#!/usr/bin/env bash declare -A SRC SRC[benchmark]=benchmark.go SRC[txgen]=cmd/client/txgen/main.go SRC[beacon]=cmd/beaconchain/main.go SRC[wallet]=cmd/client/wallet/main.go BINDIR=bin BUCKET=unique-bucket-bin PUBBUCKET=pub.harmony.one GOOS=linux GOARCH=amd64 FOLDER=/${WHOAMI:-$USER} RACE= if [ "$(uname -s)" == "Darwin" ]; then MD5='md5 -r' else MD5=md5sum 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 [ -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") DEST=wallet/wallet ;; "Darwin") DEST=wallet.osx/wallet ;; *) echo "Unsupported OS: $OS" return ;; esac $AWSCLI s3 cp $BINDIR/wallet s3://$PUBBUCKET/$DEST $AWSCLI s3api put-object-acl --bucket $PUBBUCKET --key $DEST --acl public-read } ################################ MAIN FUNCTION ############################## while getopts "hp:a:o:b:f:r" 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 ;; esac done mkdir -p $BINDIR shift $(($OPTIND-1)) ACTION=${1:-build} case "$ACTION" in "build") build_only ;; "upload") upload ;; "pubwallet") upload_wallet ;; *) usage ;; esac