#!/sbin/openrc-run command="/root/bin/pia-wg.sh" CONFIGDIR="${CONFIGDIR:-/var/cache/pia-wg}" CONFIG="${CONFIG:-/etc/pia-wg/pia-wg.conf}" extra_started_commands="reload" depend() { need net sysfs after modules ip-rules use logger } start_pre() { if ! [ -e "$CONFIG" ] then echo "Please generate a config with pia-wg.sh and copy it to $CONFIG" return 1 fi if ! [ -w "$CONFIGDIR" ] || ! [ -d "$CONFIGDIR" ] then echo "$CONFIGDIR is not a writable directory" return 1 fi return 0 } start() { ( export CONFIGDIR="$CONFIGDIR" export CONFIG="$CONFIG" while "$command" "$@" 2>&1 | tee /var/log/pia-wg.log && [ ${PIPESTATUS[0]} -ne 0 ] do ewarn "Failed, retrying" sleep 1 done einfo "OK" ); return 0 } reload() { start -n } restart() { stop start } stop() { source "$CONFIG" ip link del "${PIA_INTERFACE:-pia}" }