Change configuration creation by adding init command

This commit is contained in:
2022-12-02 16:47:52 +01:00
parent 61dbd439a7
commit f4d26084a2
3 changed files with 28 additions and 10 deletions

View File

@ -4,11 +4,13 @@
rm *.conf 2>/dev/null
rm *-client_*.png 2>/dev/null
echo "Create configuration files"
while [[ -z $DEVICE ]]; do
echo -n "Device (eg tun0): "
read DEVICE
done
echo " - Writing config to file $DEVICE.conf"
echo " - Writing server config to file $DEVICE.conf"
while [[ -z $SERVER_HOST ]]; do
echo -n "Endpoint hostname: "

View File

@ -6,12 +6,6 @@ if [ -z $DEVICE ]; then
DEVICE="tun0"
fi
if [ ! -f "/etc/wireguard/$DEVICE.conf" ]; then
cd /etc/wireguard
/scripts/create-config.sh
exit 0
fi
case "$1" in
'ls-configs' | 'ls')
cd /etc/wireguard
@ -41,6 +35,16 @@ case "$1" in
/scripts/show-client.sh $2
exit 0
;;
'init')
if [ ! -f "/etc/wireguard/$DEVICE.conf" ]; then
cd /etc/wireguard
/scripts/create-config.sh
exit 0
else
echo "Existing config found: Run command 'purge' first."
exit 1
fi
;;
'purge')
cd /etc/wireguard
rm *.conf *.png
@ -55,11 +59,16 @@ case "$1" in
echo "add Add new client"
echo "rm Remove client by ID"
echo "show Show client config with qrcode"
echo "init Initialize service by creating config files"
echo "purge Remove server config and all client configs"
echo "help Show this help message"
echo
;;
*)
if [ ! -f "/etc/wireguard/$DEVICE.conf" ]; then
cd /etc/wireguard
/scripts/create-config.sh
fi
echo "Starting wg-quick on $DEVICE"
touch "${WG_LOG_FILE}"
wg-quick up $DEVICE