Last active
November 25, 2021 15:57
-
-
Save notexeditor/b6e2de80426a6db84a960dfceae3fc7a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| ############################################################################### | |
| source /etc/profile.d/go.sh | |
| ############################################################################### | |
| function command_fqn { | |
| local cmd ; | |
| cmd=$([[ "$1" =~ ([^/]+)/([^/]+)\.sh$ ]] && printf '%s' "${BASH_REMATCH[1]}") ; | |
| local sub ; | |
| sub=$([[ "$1" =~ ([^/]+)\.sh$ ]] && printf '%s' "${BASH_REMATCH[1]}") ; | |
| if [[ -n "$cmd" ]] && [[ "$cmd" != '.' ]] ; then | |
| printf "%s %s" "$cmd" "$sub" ; | |
| else | |
| printf '%s' "$1" ; | |
| fi ; | |
| } | |
| function cli_help { | |
| local usage ; | |
| usage="${BB}Usage:${NB} $(command_fqn "${0}")" ; | |
| usage+=" [-O|--skip-operating-system|\${SKIP_OPERATING_SYSTEM}]" ; | |
| usage+=" [-A|--skip-avalanche|\${SKIP_AVALANCHE}]" ; | |
| usage+=" [-R|--skip-reboot|\${SKIP_REBOOT}]" ; | |
| usage+=" [-t|--tag-name|\${TAG_NAME}]" ; | |
| usage+=" [-h|--help]" ; | |
| printf '%s\n' "$usage" ; | |
| } | |
| function cli_options { | |
| local -a options ; | |
| options+=( "-O" "--skip-operating-system" ) ; | |
| options+=( "-A" "--skip-avalanche" ) ; | |
| options+=( "-R" "--skip-reboot" ) ; | |
| options+=( "-t" "--tag-name" ) ; | |
| options+=( "-h" "--help" ) ; | |
| printf '%s ' "${options[@]}" ; | |
| } | |
| function cli { | |
| while getopts ":hOARt-:" OPT "$@" | |
| do | |
| if [ "$OPT" = "-" ] ; then | |
| OPT="${OPTARG%%=*}" ; | |
| OPTARG="${OPTARG#$OPT}" ; | |
| OPTARG="${OPTARG#=}" ; | |
| fi | |
| case "${OPT}" in | |
| list-options) | |
| cli_options && exit 0 ;; | |
| O|skip-operating-system) | |
| export SKIP_OPERATING_SYSTEM=1 ;; | |
| A|skip-avalanche) | |
| export SKIP_AVALANCHE=1 ;; | |
| R|skip-reboot) | |
| export SKIP_REBOOT=1 ;; | |
| t|tag-name) | |
| TAG_NAME="${OPTARG}" ;; | |
| h|help) | |
| cli_help && exit 0 ;; | |
| :|*) | |
| cli_help && exit 1 ;; | |
| esac | |
| done | |
| shift $((OPTIND-1)) ; | |
| } | |
| function network_svc { | |
| if [ -n "$NETWORK_SVC" ]; then | |
| echo "$NETWORK_SVC" ; | |
| else | |
| local is_mainnet=$(systemctl is-active --user \ | |
| avalanche-go@mainnet.service) ; | |
| if [ "$is_mainnet" = "active" ] ; then | |
| NETWORK_SVC="mainnet.service" ; | |
| echo "$NETWORK_SVC" ; | |
| return ; | |
| fi | |
| local is_testnet=$(systemctl is-active --user \ | |
| avalanche-go@testnet.service) ; | |
| if [ "$is_testnet" = "active" ] ; then | |
| NETWORK_SVC="testnet.service" ; | |
| echo "$NETWORK_SVC" ; | |
| return ; | |
| fi | |
| fi | |
| } | |
| function up_operating_system { | |
| if [ -z "$SKIP_OPERATING_SYSTEM" ] ; then | |
| sudo apt-get update -y && sudo apt-get upgrade -y ; | |
| fi | |
| } | |
| function up_avalanche { | |
| if [ -z "$SKIP_AVALANCHE" ] ; then | |
| if [ -n "$(network_svc)" ] ; then | |
| systemctl stop --user "avalanche-go@$(network_svc)" ; | |
| fi | |
| cd "$GOPATH/src/github.com/ava-labs/avalanchego" ; | |
| git checkout master ; git checkout -- . ; git pull ; git pull --tags ; | |
| go get -v -d github.com/ava-labs/avalanchego/... ; | |
| git config advice.detachedHead false ; | |
| if [ -z "$TAG_NAME" ] ; then | |
| git checkout "$(git describe --tags --abbrev=0)" ; | |
| else | |
| git checkout "$TAG_NAME" ; | |
| fi | |
| ./scripts/build.sh ; | |
| fi | |
| } | |
| function up_reboot { | |
| if [ -n "$SKIP_REBOOT" ] ; then | |
| if [ -n "$(network_svc)" ] ; then | |
| systemctl start --user "avalanche-go@$(network_svc)" ; | |
| fi | |
| else | |
| sudo reboot ; | |
| fi | |
| } | |
| function up_main { | |
| up_operating_system && \ | |
| up_avalanche && \ | |
| up_reboot ; | |
| } | |
| ############################################################################### | |
| cli "$@" && up_main ; | |
| ############################################################################### | |
| ############################################################################### |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export GOPATH=$HOME/.go | |
| export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An
avalancheupgrade script to fetch and compile the GO client from the git repository. Further, it has a dependency on aavalanche-gosystemd service unit.