Skip to content

Instantly share code, notes, and snippets.

@zoran
Last active May 27, 2020 19:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zoran/d1cd864801e68c89569f7e5e32eeae9f to your computer and use it in GitHub Desktop.
Save zoran/d1cd864801e68c89569f7e5e32eeae9f to your computer and use it in GitHub Desktop.
iota.partners-iri-env-auto-updater.sh
#!/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