memories/go-vod/run.sh

74 lines
1.9 KiB
Bash
Raw Permalink Normal View History

2023-10-20 21:14:28 +00:00
#!/bin/bash
# This script fetches the current version of go-vod from Nextcloud
# to the working directory and runs it. If go-vod exits with a restart
# code, the script will restart it.
# This script is intended to be run by systemd if running on bare metal.
2023-10-21 03:47:09 +00:00
# Environment variables
HOST=$NEXTCLOUD_HOST
ALLOW_INSECURE=$NEXTCLOUD_ALLOW_INSECURE
2023-10-20 21:14:28 +00:00
# check if host is set
if [[ -z $HOST ]]; then
echo "fatal: NEXTCLOUD_HOST is not set"
exit 1
fi
2023-10-21 03:47:09 +00:00
# check if scheme is set
2023-10-20 21:14:28 +00:00
if [[ ! $HOST == http://* ]] && [[ ! $HOST == https://* ]]; then
2023-10-21 03:47:09 +00:00
echo "fatal: NEXTCLOUD_HOST must start with http:// or https://"
exit 1
fi
# check if scheme is http and allow_insecure is not set
if [[ $HOST == http://* ]] && [[ -z $ALLOW_INSECURE ]]; then
echo "fatal: NEXTCLOUD_HOST is set to http:// but NEXTCLOUD_ALLOW_INSECURE is not set"
exit 1
2023-10-20 21:14:28 +00:00
fi
# Check if the current working directory is writable
if [ ! -w "." ]; then
echo "Current working directory is not writable."
echo "Are you in Docker and non-root (not supported)?"
exit 1
fi
2023-10-20 21:14:28 +00:00
# build URL to fetch binary from Nextcloud
ARCH=$(uname -m)
URL="$HOST/index.php/apps/memories/static/go-vod?arch=$ARCH"
2023-10-21 03:47:09 +00:00
# set the -k option in curl if allow_insecure is set
EXTRA_CURL_ARGS=""
if [[ $ALLOW_INSECURE == true ]]; then
EXTRA_CURL_ARGS="$EXTRA_CURL_ARGS -k"
fi
2023-10-20 21:14:28 +00:00
# fetch binary, sleeping 10 seconds between retries
function fetch_binary {
while true; do
rm -f go-vod
2023-10-21 03:47:09 +00:00
curl $EXTRA_CURL_ARGS -L -f -m 10 -s -o go-vod $URL
2023-10-20 21:14:28 +00:00
if [[ $? == 0 ]]; then
chmod +x go-vod
echo "Fetched $URL successfully!"
break
fi
2023-10-20 21:54:01 +00:00
echo "Failed to fetch $URL"
2023-10-20 21:14:28 +00:00
echo "Are you sure the host is reachable and running Memories v6+?"
2023-10-20 21:54:01 +00:00
echo "Retrying in 10 seconds..."
2023-10-20 21:14:28 +00:00
sleep 10
done
}
# infinite loop
while true; do
fetch_binary
./go-vod -version-monitor
if [[ $? != 12 ]]; then
break
fi
sleep 3 # throttle
done