Skip to content

Instantly share code, notes, and snippets.

@zoran
Last active January 11, 2019 21:39
Show Gist options
  • Save zoran/48482038deda9ce5898c00f78d42f801 to your computer and use it in GitHub Desktop.
Save zoran/48482038deda9ce5898c00f78d42f801 to your computer and use it in GitHub Desktop.
IOTA IRI Auto Update
#!/usr/bin/env bash
set -euo pipefail
readonly SYSTEMD_CONFIG="/lib/systemd/system/iota.service"
readonly SCRIPT_NAME=$(basename $0)
function get_latest_github_release {
curl -s https://api.github.com/repos/iotaledger/iri/releases/latest | jq "[.assets][0][0].name" --raw-output
}
function get_download_url {
curl -s https://api.github.com/repos/iotaledger/iri/releases/latest | jq "[.assets][0][0].browser_download_url"
}
function get_installed_version {
raw=`grep -v "^#" $SYSTEMD_CONFIG | 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 iri-$latest.jar" &&
sh -c "sudo -u iota wget -qO /home/iota/node/$latest $(get_download_url)" &&
sed -i -e "s/$installed/$latest/" $SYSTEMD_CONFIG &&
systemctl daemon-reload &&
systemctl restart iota
}
function main {
local latest="$(get_latest_github_release)"
local installed="$(get_installed_version)"
if [ "$latest" != "$installed" ] && [ $(v_is_digit ${latest}) ] && [ $(v_is_digit ${installed}) ]; then
update_iri
fi
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment