aboutsummaryrefslogtreecommitdiff
path: root/files/usr/local/libexec/invidious-sighelper-update.invidious_server
diff options
context:
space:
mode:
Diffstat (limited to 'files/usr/local/libexec/invidious-sighelper-update.invidious_server')
-rw-r--r--files/usr/local/libexec/invidious-sighelper-update.invidious_server48
1 files changed, 48 insertions, 0 deletions
diff --git a/files/usr/local/libexec/invidious-sighelper-update.invidious_server b/files/usr/local/libexec/invidious-sighelper-update.invidious_server
new file mode 100644
index 0000000..0aacbb1
--- /dev/null
+++ b/files/usr/local/libexec/invidious-sighelper-update.invidious_server
@@ -0,0 +1,48 @@
+#!/bin/sh
+
+set -eu -o pipefail
+
+prog=$(basename "$(readlink -f "$0")")
+usage="${prog} [-q] INVIDIOUS_USER SIGHELPER_SRCDIR"
+
+die() {
+ printf '%s: %s\n' "$prog" "$*" 1>&2
+ exit 1
+}
+
+usage(){
+ printf 'usage: %s\n' "$usage" 1>&2
+ exit 2
+}
+
+as_invidious(){
+ su -m "$invidious_user" -c "HOME=$(dirname "$sighelper_dir") ${@}"
+}
+
+while getopts hq opt; do
+ case $opt in
+ h) usage ;;
+ q) exec 1>/dev/null ;;
+ esac
+done
+shift $((OPTIND - 1))
+
+[ $# -eq 2 ] || usage
+
+invidious_user=$1
+sighelper_dir=$2
+
+cd "$sighelper_dir"
+
+as_invidious 'git fetch'
+local_rev=$(as_invidious 'git rev-parse HEAD')
+upstream_rev=$(as_invidious 'git rev-parse "@{u}"')
+
+if [ "$local_rev" != "$upstream_rev" ]; then
+ echo "updating inv_sig_helper to rev ${upstream_rev}"
+ as_invidious 'git pull --ff-only && cargo build --release'
+else
+ echo "inv_sig_helper already up to date at rev ${local_rev}"
+fi
+
+service inv_sig_helper status 2>/dev/null && service inv_sig_helper restart