Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 80 lines (68 sloc) 1.61 KB
#!/bin/bash
# fail fast
set -o errexit
set -o pipefail
id=$1
echo() {
/bin/echo "$1" "$2"
}
error() {
/bin/echo $* >&2; exit 1
}
# get root dir
root_dir=$(pwd)
# create a temporary compile directory
compile_dir=$(mktemp -t compile_XXXXX)
rm -rf $compile_dir
mkdir -p $compile_dir
source_anchor=${1#*#}
source_url=${1%%#*}
if [ "$source_anchor" == "$source_url" ]; then
source_anchor=""
fi
echo "done" >&2
echo -n "Preparing app for compilation... " >&2
# fetching app
case $source_url in
*.json)
manifest=$(mktemp -t manifest_XXXXX)
curl -f -Ls $source_url -o $manifest
$root_dir/bin/download_manifest $manifest $compile_dir >/dev/null
;;
*.git)
git clone "$source_url" "$compile_dir" --recursive >/dev/null 2>/dev/null
if [ "$source_anchor" != "" ]; then
cd $compile_dir >/dev/null 2>&1
git remote update >/dev/null 2>&1
git checkout "$source_anchor" >/dev/null 2>&1 || \
error "failed, no such ref: $source_anchor"
cd - >/dev/null 2>&1
fi
rm -rf $compile_dir/.git
;;
*)
source=$(mktemp -t source_XXXXX)
curl -f -Ls $source_url -o $source
cd $compile_dir >/dev/null 2>&1
case $(file -b $source) in
Squashfs*)
unsquashfs -f -d $compile_dir $source >/dev/null 2>&1
;;
gzip\ compressed\ data*)
tar xzf $source
;;
bzip2\ compressed\ data*)
tar xjf $source
;;
Zip\ archive\ data*)
jar xf $source
;;
*)
error "failed, unknown source type: $source_url"
;;
esac
cd - >/dev/null 2>&1
;;
esac
echo "done" >&2
echo $compile_dir