mirror of
https://github.com/triffid/pia-wg.git
synced 2026-03-31 06:24:18 -04:00
57 lines
857 B
Plaintext
Executable File
57 lines
857 B
Plaintext
Executable File
#!/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 -r
|
|
}
|
|
|
|
restart() {
|
|
stop
|
|
start
|
|
}
|
|
|
|
stop() {
|
|
source "$CONFIG"
|
|
ip link del "${PIA_INTERFACE:-pia}"
|
|
}
|