From 074ecc88575f40218e499bf54179929bb2e1e964 Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Tue, 29 Nov 2022 07:24:44 +0100 Subject: [PATCH] Add script to remove client --- README.md | 10 ++++++++++ scripts/entrypoint.sh | 37 ++++++++++++++++++++++++------------- scripts/rm-client.sh | 10 ++++++++++ 3 files changed, 44 insertions(+), 13 deletions(-) create mode 100755 scripts/rm-client.sh diff --git a/README.md b/README.md index 7f75a15..fc20f86 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,16 @@ $ docker-compose run wg add-client This will create new client configuration and adds peer configuration to server config file. +### Remove client + +Stop the service and run + +``` +$ docker-compose run wg rm-client 1 +``` + +This will remove client with id '1' (or any other client for different id) configuration. + ### Remove configuration and create new one from scratch Remove existing config files or rename device in `docker-compose.yml`. Run command `docker-compose up` again. diff --git a/scripts/entrypoint.sh b/scripts/entrypoint.sh index 3cf1d77..9a0e966 100755 --- a/scripts/entrypoint.sh +++ b/scripts/entrypoint.sh @@ -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 " + 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 diff --git a/scripts/rm-client.sh b/scripts/rm-client.sh new file mode 100755 index 0000000..6232ddb --- /dev/null +++ b/scripts/rm-client.sh @@ -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" \ No newline at end of file