Skip to content

Instantly share code, notes, and snippets.

@demonbane
Last active May 11, 2018
Embed
What would you like to do?

This is a simple proof of concept for doing Ombi updates live. The requirements to use this are:

  • You must have Ombi already installed and it must be running (obviously, since Ombi kicks off the update)
  • You must be using systemd to manage Ombi
  • The user that Ombi runs as must have permissions to run systemctl restart
    • Use visudo to edit your sudoers and add a line like:
      ombiuser ALL=NOPASSWD: /bin/systemctl restart ombi.service
      
      Where ombiuser is the user Ombi runs as. You should also sanity check your system to make sure that systemctl is at /bin/systemctl and that your Ombi unti file is called ombi.service.
  • Your system must be relatively up-to-date. (Currently, that means bash version >4 and a ps command that has been updated with systemd support)
  • Running external scripts just started working recently and it's still not clear if it was due to a change in Ombi or a change in Mono. This has been tested on a system running mono 5.12.0.226. YMMV with a different version.
#!/usr/bin/env bash
logfile="$(mktemp --suffix=".log" --tmpdir ombi-update.XXX)"
exec >> "$logfile"
exec 2>&1
printf -- '---- %b ----\n%b\n' "$(date)" "$0 $*"
re='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'
if [[ "$1" =~ $re ]]; then
ombiurl="$1"
shift
else
printf 'Invalid URL, aborting: "%s"\n' "$1" >&2
exit 1
fi
newversion="$(cut -f8 -d/ <<< "$ombiurl")"
if [[ "$newversion" =~ ^v[0-9.]+$ ]]; then
targetfile="$(dirname "$(mktemp --dry-run --tmpdir)")/Ombi.$newversion.tar.gz"
touch "$targetfile"
else
targetfile="$(mktemp --suffix=".tar.gz" --tmpdir Ombi.XXX)"
fi
tempopts=$(getopt -o 'P:n:h' --long 'applicationPath:,applicationpath:,processName:,processname:,help' -n 'ombi-update' -- "$@") || { printf 'Option parsing failed, aborting\n' >&2 && exit 1; }
eval set -- "$tempopts"
unset tempopts
while true; do
case "$1" in
'-h'|'--help')
printf -- 'Usage: %s URL --applicationPath PATH [--processname NAME]\n' "$(basename "$0")"
exit 0
;;
'-P'|'--applicationPath'|'--applicationpath')
ombipath="$2"
shift 2
continue
;;
'-n'|'--processname'|'--processName')
ombiprocess="$2"
shift 2
continue
;;
'--')
shift
break
;;
*)
printf 'Internal error!' >&2
exit 1
;;
esac
done
# Any additional arguments are silently discarded at this point
if [ -z "$ombipath" ]; then
printf '--applicationPath is required, but not specified. Aborting.\n' >&2
exit 1
elif [ ! -d "$ombipath" ]; then
printf '"%s" does not appear to be a valid path, aborting.\n' "$ombipath" >&2
exit 1
fi
ombiservice="$(ps -o unit= -C "$ombiprocess")"
ombiservice="${ombiservice:-ombi.service}"
if systemctl is-enabled --quiet "$ombiservice" 2> /dev/null; then
printf 'Downloading update to "%b"... ' "$targetfile"
curl -fsSLo "$targetfile" --silent "$ombiurl" || { printf 'failed, aborting.\n' >&2 && exit 1; }
printf 'done!\n'
cd "$ombipath"
printf 'Extracting update... '
tar xvvzf "$targetfile" || { printf 'failed, aborting.\n' >&2 && exit 1; }
printf 'done!\nRestarting...\n'
sudo systemctl restart "$ombiservice"
else
printf 'Unable to find service with name "%s", aborting.\n' "$ombiservice" >&2
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment