You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
144 lines
3.2 KiB
144 lines
3.2 KiB
6 years ago
|
#!/usr/bin/env bash
|
||
6 years ago
|
declare -A SRC
|
||
6 years ago
|
SRC[harmony]=cmd/harmony.go
|
||
6 years ago
|
SRC[txgen]=cmd/client/txgen/main.go
|
||
6 years ago
|
SRC[beacon]=cmd/beaconchain/main.go
|
||
6 years ago
|
SRC[wallet]=cmd/client/wallet/main.go
|
||
6 years ago
|
|
||
|
BINDIR=bin
|
||
|
BUCKET=unique-bucket-bin
|
||
6 years ago
|
PUBBUCKET=pub.harmony.one
|
||
6 years ago
|
GOOS=linux
|
||
|
GOARCH=amd64
|
||
6 years ago
|
FOLDER=/${WHOAMI:-$USER}
|
||
6 years ago
|
RACE=
|
||
6 years ago
|
|
||
|
if [ "$(uname -s)" == "Darwin" ]; then
|
||
|
MD5='md5 -r'
|
||
6 years ago
|
GOOS=darwin
|
||
6 years ago
|
else
|
||
|
MD5=md5sum
|
||
|
fi
|
||
|
|
||
|
function usage
|
||
|
{
|
||
|
ME=$(basename $0)
|
||
|
cat<<EOF
|
||
|
|
||
|
Usage: $ME [OPTIONS] ACTION
|
||
|
|
||
|
OPTIONS:
|
||
|
-h print this help message
|
||
|
-p profile aws profile name
|
||
|
-a arch set build arch (default: $GOARCH)
|
||
|
-o os set build OS (default: $GOOS, windows is supported)
|
||
|
-b bucket set the upload bucket name (default: $BUCKET)
|
||
|
-f folder set the upload folder name in the bucket (default: $FOLDER)
|
||
6 years ago
|
-r enable -race build option (default: $RACE)
|
||
6 years ago
|
|
||
|
ACTION:
|
||
|
build build binaries only (default action)
|
||
|
upload upload binaries to s3
|
||
6 years ago
|
pubwallet upload wallet to public bucket (bucket: $PUBBUCKET)
|
||
6 years ago
|
|
||
|
EXAMPLES:
|
||
|
|
||
|
# build linux binaries only by default
|
||
|
$ME
|
||
|
|
||
|
# build windows binaries
|
||
|
$ME -o windows
|
||
|
|
||
|
# upload binaries to my s3 bucket, 0908 folder
|
||
|
$ME -b mybucket -f 0908 upload
|
||
|
|
||
|
EOF
|
||
|
exit 1
|
||
|
}
|
||
|
|
||
|
function build_only
|
||
|
{
|
||
|
VERSION=$(git rev-list --all --count)
|
||
|
COMMIT=$(git describe --always --long --dirty)
|
||
|
BUILTAT=$(date +%FT%T%z)
|
||
|
BUILTBY=${USER}@
|
||
|
|
||
|
for bin in "${!SRC[@]}"; do
|
||
6 years ago
|
echo "building ${SRC[$bin]}"
|
||
6 years ago
|
env GOOS=$GOOS GOARCH=$GOARCH go build -ldflags="-X main.version=v${VERSION} -X main.commit=${COMMIT} -X main.builtAt=${BUILTAT} -X main.builtBy=${BUILTBY}" -o $BINDIR/$bin $RACE ${SRC[$bin]}
|
||
6 years ago
|
if [ "$(uname -s)" == "Linux" ]; then
|
||
|
$BINDIR/$bin -version
|
||
|
fi
|
||
6 years ago
|
if [ "$(uname -s)" == "Darwin" -a "$GOOS" == "darwin" ]; then
|
||
|
$BINDIR/$bin -version
|
||
|
fi
|
||
6 years ago
|
done
|
||
|
|
||
|
$MD5 $BINDIR/* > $BINDIR/md5sum.txt 2> /dev/null
|
||
|
}
|
||
|
|
||
|
function upload
|
||
|
{
|
||
|
AWSCLI=aws
|
||
|
|
||
|
if [ -n "$PROFILE" ]; then
|
||
|
AWSCLI+=" --profile $PROFILE"
|
||
|
fi
|
||
|
|
||
|
for bin in "${!SRC[@]}"; do
|
||
|
[ -e $BINDIR/$bin ] && $AWSCLI s3 cp $BINDIR/$bin s3://${BUCKET}$FOLDER/$bin --acl public-read
|
||
|
done
|
||
|
[ -e $BINDIR/md5sum.txt ] && $AWSCLI s3 cp $BINDIR/md5sum.txt s3://${BUCKET}$FOLDER/md5sum.txt --acl public-read
|
||
|
}
|
||
|
|
||
6 years ago
|
function upload_wallet
|
||
|
{
|
||
|
AWSCLI=aws
|
||
|
|
||
|
if [ -n "$PROFILE" ]; then
|
||
|
AWSCLI+=" --profile $PROFILE"
|
||
|
fi
|
||
|
|
||
|
|
||
|
OS=$(uname -s)
|
||
|
|
||
|
case "$OS" in
|
||
|
"Linux")
|
||
|
DEST=wallet/wallet ;;
|
||
|
"Darwin")
|
||
|
DEST=wallet.osx/wallet ;;
|
||
|
*)
|
||
|
echo "Unsupported OS: $OS"
|
||
|
return ;;
|
||
|
esac
|
||
|
|
||
|
$AWSCLI s3 cp $BINDIR/wallet s3://$PUBBUCKET/$DEST
|
||
6 years ago
|
$AWSCLI s3api put-object-acl --bucket $PUBBUCKET --key $DEST --acl public-read
|
||
6 years ago
|
}
|
||
|
|
||
6 years ago
|
################################ MAIN FUNCTION ##############################
|
||
6 years ago
|
while getopts "hp:a:o:b:f:r" option; do
|
||
6 years ago
|
case $option in
|
||
|
h) usage ;;
|
||
|
p) PROFILE=$OPTARG ;;
|
||
|
a) GOARCH=$OPTARG ;;
|
||
|
o) GOOS=$OPTARG ;;
|
||
|
b) BUCKET=$OPTARG/ ;;
|
||
|
f) FOLDER=$OPTARG ;;
|
||
6 years ago
|
r) RACE=-race ;;
|
||
6 years ago
|
esac
|
||
|
done
|
||
|
|
||
|
mkdir -p $BINDIR
|
||
|
|
||
|
shift $(($OPTIND-1))
|
||
|
|
||
|
ACTION=${1:-build}
|
||
6 years ago
|
|
||
6 years ago
|
case "$ACTION" in
|
||
|
"build") build_only ;;
|
||
|
"upload") upload ;;
|
||
6 years ago
|
"pubwallet") upload_wallet ;;
|
||
6 years ago
|
*) usage ;;
|
||
|
esac
|