Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 83 lines (64 sloc) 1.74 KB
#!/bin/bash
# fail fast
set -o errexit
set -o pipefail
compile_dir=$1
# override built-in shell echo
echo() {
/bin/echo "$1" "$2"
}
error() {
/bin/echo $*; exit 1
}
if [ "$compile_dir" == "" ]; then
error "Aborting compilation"
fi
if [ ! -d $compile_dir ]; then
error "Aborting compilation"
fi
# make slug
if [ "$SLUG_PUT_URL" != "" ]; then
echo -n "Creating slug... "
slug=$(mktemp -t slug_XXXXX)
case $SLUG_TYPE in
tgz)
cd $compile_dir
tar czf $slug .
cd - >/dev/null
;;
deb)
debroot=$(mktemp -t debroot_XXXXX)
rm -rf $debroot
mkdir -p -m 0755 $debroot
mv $compile_dir $debroot/app
mkdir -p -m 0755 $debroot/DEBIAN
base=$(basename $SLUG_URL)
name=${base%%.*}
version=$(date +%s)
if [ -f $debroot/app/.control ]; then
cp $debroot/app/.control $debroot/DEBIAN/control
fi
default_control() {
file=$1; key=$2; value=$3
grep "^$key:" $file >/dev/null 2>&1 || echo "$key: $value" >> $file
}
default_control $debroot/DEBIAN/control "Package" $name
default_control $debroot/DEBIAN/control "Version" $version
default_control $debroot/DEBIAN/control "Architecture" "amd64"
default_control $debroot/DEBIAN/control "Maintainer" "Anvil Compiler <david@heroku.com>"
default_control $debroot/DEBIAN/control "Description" "Anvil:$ANVIL_HOST, Buildpack:$BUILDPACK_URL"
fakeroot dpkg-deb --build $debroot . >/dev/null 2>&1
mv ${name}_${version}_amd64.deb $slug
;;
*)
error "Unknown SLUG_TYPE"
;;
esac
echo "done"
echo -n "Uploading slug... "
curl -f -s -T $slug "$SLUG_PUT_URL"
echo "done"
echo "Success, slug is ${SLUG_URL}"
else
echo "Success"
fi