changes again
This commit is contained in:
parent
94d2955ab0
commit
f4b88690f7
12 changed files with 94 additions and 70 deletions
|
|
@ -1,26 +1,28 @@
|
|||
#!/bin/bash
|
||||
# shellcheck disable=SC2034
|
||||
|
||||
die() {
|
||||
echo "exitting..."
|
||||
rm -f $PIPE
|
||||
exit 0
|
||||
}
|
||||
|
||||
trap 'die' SIGTERM SIGQUIT SIGINT
|
||||
|
||||
PIPE="/var/run/vpnd.sock"
|
||||
oc_pid=
|
||||
|
||||
[ -p $PIPE ] && exit 1
|
||||
[ "$(id -u)" != "0" ] && exit 1
|
||||
|
||||
trap 'die' SIGTERM SIGQUIT SIGINT
|
||||
|
||||
declare -a CONFIGS
|
||||
for config in /etc/wireguard/*; do
|
||||
for config in /etc/openconnect/config_*; do
|
||||
config="$(basename "$config")"
|
||||
CONFIGS+=("${config%.conf}")
|
||||
CONFIGS+=("${config#config_}")
|
||||
done
|
||||
|
||||
COMMANDS=("up" "down")
|
||||
|
||||
die() {
|
||||
rm $PIPE
|
||||
exit 0
|
||||
}
|
||||
|
||||
in_arr() {
|
||||
declare -n arr="$2"
|
||||
|
||||
|
|
@ -30,6 +32,19 @@ in_arr() {
|
|||
return 1
|
||||
}
|
||||
|
||||
down() {
|
||||
[ -z "$oc_pid" ] && return
|
||||
kill -s TERM $oc_pid
|
||||
wait $oc_pid
|
||||
oc_pid=
|
||||
}
|
||||
|
||||
up() {
|
||||
[ -n "$oc_pid" ] && down
|
||||
openconnect --config "/etc/openconnect/config_$1" &
|
||||
oc_pid="$!"
|
||||
}
|
||||
|
||||
main() {
|
||||
mkfifo $PIPE -m666
|
||||
|
||||
|
|
@ -41,7 +56,10 @@ main() {
|
|||
elif ! in_arr "$cmd" "COMMANDS"; then
|
||||
echo "ERROR: Invalid command $cmd" > $PIPE
|
||||
else
|
||||
wg-quick "$cmd" "$ifname" > $PIPE 2>&1
|
||||
case "$cmd" in
|
||||
"up") up "$ifname" > $PIPE ;;
|
||||
"down") down > $PIPE ;;
|
||||
esac
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue