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