Last active
May 27, 2020 19:06
-
-
Save zoran/d1cd864801e68c89569f7e5e32eeae9f to your computer and use it in GitHub Desktop.
iota.partners-iri-env-auto-updater.sh
This file contains 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 | |
set -euo pipefail | |
readonly NODE_PATH="/home/iota/node" | |
readonly IOTA_ENV_FILE="$NODE_PATH/iota.env" | |
readonly SCRIPT_NAME=$(basename $0) | |
function get_latest_github_release { | |
curl -s https://api.github.com/repos/iotaledger/iri/releases/latest | jq "[.assets][0][2].name" --raw-output | |
} | |
function get_download_url { | |
curl -s https://api.github.com/repos/iotaledger/iri/releases/latest | jq "[.assets][0][2].browser_download_url" | |
} | |
function get_installed_version { | |
raw=`grep -v "^#" $IOTA_ENV_FILE | grep -v "^$" | grep -o -P '(?<=IRI-).*(?=.jar)'` | |
echo "IRI-$raw.jar" | |
} | |
log() { | |
echo "$@" | |
logger -p user.notice -t $SCRIPT_NAME "$@" | |
} | |
function v_is_digit { | |
tr -cd 0-9 <<<"$@" | |
} | |
function update_iri { | |
log "New IRI release $latest detected! Updating installed version $installed to the latest release $latest" | |
sh -c "sudo rm -f $NODE_PATH/$installed" && | |
sh -c "sudo -u iota wget -qO $NODE_PATH/$latest $(get_download_url)" && | |
sed -i -e '${/IRI_VERSION/d;}' $IOTA_ENV_FILE && | |
echo "IRI_VERSION=$latest" >> $IOTA_ENV_FILE && | |
source $IOTA_ENV_FILE && | |
systemctl restart iota | |
} | |
function main { | |
latest="$(get_latest_github_release)" | |
installed="$(get_installed_version)" | |
if [ "$latest" != "$installed" ] && [ $(v_is_digit ${latest}) ]; then | |
update_iri | |
fi | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment