Skip to content

Instantly share code, notes, and snippets.

@wereHamster
Created January 9, 2011 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wereHamster/771993 to your computer and use it in GitHub Desktop.
Save wereHamster/771993 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# This relies on addons specifying the external dependencies in their toc file.
# Blizzard conveniently ignores everything after the first space in the
# OptionalDependency field so we can use something like this:
#
# ## OptionalDependency: FooLibrary git@github.com:you/FooLibrary.git deadbeef:Lib/
#
# Where deadbeef:Lib/ is the tree-ish we want to extract and put into Libs/FooLibrary.
#
# git-archive which works even if the remote doens't support git-upload-archive.
archive () {
GITDIR="$(mktemp -d $TMPDIR/XXXXXXX)"
git clone --bare --quiet "$2" "$GITDIR"
git --git-dir "$GITDIR" archive --prefix="$1/" "$3" | tar -xf -
RET="$(git --git-dir "$GITDIR" describe --always)"
rm -rf "$GITDIR"
echo "$RET"
}
# Create a temporary directory where we'll build the package.
ROOT="$(mktemp -d $TMPDIR/XXXXXXX)"
pushd "$ROOT"
# The source of the addon goes into a subdirectory so that when the user
# extracts the package into the AddOns directory it'll just work.
NAME="$(archive "$1" "$2" "$3")"
pushd "$1"
# Extract all optional dependencies into Libs/
cat "$1.toc" | sed -n -e '/^## OptionalDeps/ { s/## OptionalDeps: //; p; }' | \
while read name source treeish; do
archive "Libs/$name" "$source" "$treeish"
done
# Go back to the directory where we started in
popd
popd
# Create the package and clean up
tar -cvC "$ROOT" . | xz > "$NAME.tar.xz"
rm -rf "$ROOT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment