Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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