Add script to remove client

This commit is contained in:
2022-11-29 07:24:44 +01:00
parent fbbb26f4cb
commit 074ecc8857
3 changed files with 44 additions and 13 deletions

View File

@ -8,19 +8,30 @@ fi
if [ ! -f "/etc/wireguard/$DEVICE.conf" ]; then
cd /etc/wireguard
/create-config.sh
/scripts/create-config.sh
exit 0
fi
if [ "add-client" == "$1" ]; then
cd /etc/wireguard
/add-client.sh
exit 0
fi
echo "Starting wg-quick on $DEVICE"
touch "${WG_LOG_FILE}"
wg-quick up $DEVICE
echo "done!"
tail -f "${WG_LOG_FILE}"
case "$1" in
'add-client')
cd /etc/wireguard
/scripts/add-client.sh
exit 0
;;
'rm-client')
if [ -z $2 ]; then
echo "Usage: rm-client <client id>"
exit 1
fi
cd /etc/wireguard
/scripts/rm-client.sh $2
exit 0
;;
*)
echo "Starting wg-quick on $DEVICE"
touch "${WG_LOG_FILE}"
wg-quick up $DEVICE
echo "done!"
tail -f "${WG_LOG_FILE}"
;;
esac

10
scripts/rm-client.sh Executable file
View File

@ -0,0 +1,10 @@
#!/bin/bash
CONFIG=$(cat "$DEVICE.conf" | sed "/^\# Client $1/{N;N;N;N;d}")
echo "$CONFIG" > "$DEVICE.conf"
rm "$DEVICE-client_$1.conf" 2>/dev/null
rm "$DEVICE-client_$1.png" 2>/dev/null
echo "Client # $1 removed"