#!/usr/bin/env bash export GO111MODULE=on declare -A SRC SRC[harmony]=cmd/harmony/main.go SRC[txgen]=cmd/client/txgen/main.go SRC[bootnode]=cmd/bootnode/main.go SRC[wallet]="cmd/client/wallet/main.go cmd/client/wallet/generated_wallet.ini.go" BINDIR=bin BUCKET=unique-bucket-bin PUBBUCKET=pub.harmony.one REL=drum GOOS=linux GOARCH=amd64 FOLDER=/${WHOAMI:-$USER} RACE= VERBOSE= DEBUG=false unset -v progdir case "${0}" in */*) progdir="${0%/*}";; *) progdir=.;; esac . "${progdir}/setup_bls_build_flags.sh" declare -A LIB if [ "$(uname -s)" == "Darwin" ]; then MD5='md5 -r' GOOS=darwin LIB[libbls384_256.dylib]=${BLS_DIR}/lib/libbls384_256.dylib LIB[libmcl.dylib]=${MCL_DIR}/lib/libmcl.dylib else MD5=md5sum LIB[libbls384_256.so]=${BLS_DIR}/lib/libbls384_256.so LIB[libmcl.so]=${MCL_DIR}/lib/libmcl.so fi function usage { ME=$(basename $0) cat< $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 for lib in "${!LIB[@]}"; do if [ -e ${LIB[$lib]} ]; then $AWSCLI s3 cp ${LIB[$lib]} s3://${BUCKET}$FOLDER/$lib --acl public-read else echo "!! MISSING ${LIB[$lib]} !!" fi done [ -e $BINDIR/md5sum.txt ] && $AWSCLI s3 cp $BINDIR/md5sum.txt s3://${BUCKET}$FOLDER/md5sum.txt --acl public-read } function upload_wallet { AWSCLI=aws if [ -n "$PROFILE" ]; then AWSCLI+=" --profile $PROFILE" fi OS=$(uname -s) case "$OS" in "Linux") FOLDER=release/$REL/linux-x86_64 ;; "Darwin") FOLDER=release/$REL/darwin-x86_64 ;; *) echo "Unsupported OS: $OS" return ;; esac $AWSCLI s3 cp $BINDIR/wallet s3://$PUBBUCKET/$FOLDER/wallet --acl public-read for lib in "${!LIB[@]}"; do if [ -e ${LIB[$lib]} ]; then $AWSCLI s3 cp ${LIB[$lib]} s3://${PUBBUCKET}/$FOLDER/$lib --acl public-read else echo "!! MISSING ${LIB[$lib]} !!" fi done } ################################ MAIN FUNCTION ############################## while getopts "hp:a:o:b:f:rv" option; do case $option in h) usage ;; p) PROFILE=$OPTARG ;; a) GOARCH=$OPTARG ;; o) GOOS=$OPTARG ;; b) BUCKET=$OPTARG/ ;; f) FOLDER=$OPTARG ;; r) RACE=-race ;; v) VERBOSE='-v -x' ;; d) DEBUG=true ;; esac done mkdir -p $BINDIR shift $(($OPTIND-1)) ACTION=${1:-build} case "$ACTION" in "build") build_only ;; "upload") upload ;; "pubwallet") upload_wallet ;; "harmony"|"wallet"|"txgen"|"bootnode") build_only $ACTION ;; *) usage ;; esac