2015-06-12 13:17:11 +08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
set -o pipefail
|
|
|
|
shopt -s nullglob # if no files match glob, assume empty list instead of string literal
|
|
|
|
|
|
|
|
|
|
|
|
## PACKAGE TO BUILD
|
|
|
|
Package=github.com/mholt/caddy
|
|
|
|
|
|
|
|
|
|
|
|
## PATHS TO USE
|
|
|
|
DistDir=$GOPATH/src/$Package/dist
|
|
|
|
BuildDir=$DistDir/builds
|
|
|
|
ReleaseDir=$DistDir/release
|
|
|
|
|
|
|
|
|
|
|
|
## BEGIN
|
|
|
|
|
|
|
|
# Compile binaries
|
|
|
|
mkdir -p $BuildDir
|
|
|
|
cd $BuildDir
|
2015-07-18 07:26:33 +08:00
|
|
|
rm -f caddy*
|
2015-06-12 13:17:11 +08:00
|
|
|
gox $Package
|
|
|
|
|
|
|
|
# Zip them up with release notes and stuff
|
|
|
|
mkdir -p $ReleaseDir
|
|
|
|
cd $ReleaseDir
|
2015-07-18 07:26:33 +08:00
|
|
|
rm -f caddy*
|
2015-06-12 13:17:11 +08:00
|
|
|
for f in $BuildDir/*
|
|
|
|
do
|
|
|
|
# Name .zip file same as binary, but strip .exe from end
|
2015-07-18 07:26:33 +08:00
|
|
|
zipname=$(basename ${f%".exe"})
|
|
|
|
if [[ $f == *"linux"* ]] || [[ $f == *"bsd"* ]]; then
|
|
|
|
zipname=${zipname}.tar.gz
|
|
|
|
else
|
|
|
|
zipname=${zipname}.zip
|
|
|
|
fi
|
2015-06-12 13:17:11 +08:00
|
|
|
|
|
|
|
# Binary inside the zip file is simply the project name
|
2015-07-18 07:26:33 +08:00
|
|
|
binbase=$(basename $Package)
|
|
|
|
if [[ $f == *.exe ]]; then
|
|
|
|
binbase=$binbase.exe
|
2015-06-12 13:17:11 +08:00
|
|
|
fi
|
2015-07-18 07:26:33 +08:00
|
|
|
bin=$BuildDir/$binbase
|
2015-06-12 13:17:11 +08:00
|
|
|
mv $f $bin
|
|
|
|
|
|
|
|
# Compress distributable
|
2015-07-18 07:26:33 +08:00
|
|
|
if [[ $zipname == *.zip ]]; then
|
|
|
|
zip -j $zipname $bin $DistDir/CHANGES.txt $DistDir/LICENSES.txt $DistDir/README.txt
|
|
|
|
else
|
|
|
|
tar -cvzf $zipname -C $BuildDir $binbase -C $DistDir CHANGES.txt LICENSES.txt README.txt
|
|
|
|
fi
|
2015-06-12 13:17:11 +08:00
|
|
|
|
|
|
|
# Put binary filename back to original
|
|
|
|
mv $bin $f
|
|
|
|
done
|