From 727aa097bf7b16e69ac5a35b01f0d2398cd20e48 Mon Sep 17 00:00:00 2001 From: Matt Low Date: Fri, 1 Jan 2021 07:40:46 -0700 Subject: [PATCH] Ensure $SERVER_ADDR is free on the server. --- vpnerator.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/vpnerator.sh b/vpnerator.sh index a074bad..5407e44 100755 --- a/vpnerator.sh +++ b/vpnerator.sh @@ -59,6 +59,11 @@ cleanup() { EXIST_INTERFACE=\$(ip addr show to ${SERVER_ADDR} | head -1 | awk '{ print \$2 }' | cut -d':' -f1) if [ ! -z "\${EXIST_INTERFACE}" ] ; then + if [ -z "\$(ip link show "\${EXIST_INTERFACE}" type wireguard)" ] ; then + # bail if the existing interface isn't of type wireguard + return 2 + fi + remove_interface \${EXIST_INTERFACE} return 0 elif ip link show ${INTERFACE_NAME} type wireguard > /dev/null 2>&1 ; then @@ -81,6 +86,11 @@ deps || exit 1 # Cleanup previous tunnel cleanup +if [ "\$?" -eq 2 ] ; then + echo "$SERVER_ADDR is already being used on the server." + echo "Please choose another address." + exit 1 +fi umask 0177