From a1b1ac2ececa50d35a6ddd078a86dd6f28003fb3 Mon Sep 17 00:00:00 2001 From: randomshell Date: Sat, 14 Nov 2020 00:47:36 +0000 Subject: [PATCH] Add confirmation before removing WireGuard (#156) --- wireguard-install.sh | 69 ++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 31 deletions(-) diff --git a/wireguard-install.sh b/wireguard-install.sh index 77f4f3c..9e09caa 100644 --- a/wireguard-install.sh +++ b/wireguard-install.sh @@ -344,45 +344,52 @@ function revokeClient() { } function uninstallWg() { - checkOS + echo "" + read -rp "Do you really want to remove WireGuard? [y/n]: " -e -i n REMOVE + if [[ $REMOVE == 'y' ]]; then + checkOS - systemctl stop "wg-quick@${SERVER_WG_NIC}" - systemctl disable "wg-quick@${SERVER_WG_NIC}" + systemctl stop "wg-quick@${SERVER_WG_NIC}" + systemctl disable "wg-quick@${SERVER_WG_NIC}" - if [[ ${OS} == 'ubuntu' ]]; then - apt-get autoremove --purge -y wireguard qrencode - elif [[ ${OS} == 'debian' ]]; then - apt-get autoremove --purge -y wireguard qrencode - elif [[ ${OS} == 'fedora' ]]; then - dnf remove -y wireguard-tools qrencode - if [[ ${VERSION_ID} -lt 32 ]]; then - dnf remove -y wireguard-dkms - dnf copr disable -y jdoss/wireguard + if [[ ${OS} == 'ubuntu' ]]; then + apt-get autoremove --purge -y wireguard qrencode + elif [[ ${OS} == 'debian' ]]; then + apt-get autoremove --purge -y wireguard qrencode + elif [[ ${OS} == 'fedora' ]]; then + dnf remove -y wireguard-tools qrencode + if [[ ${VERSION_ID} -lt 32 ]]; then + dnf remove -y wireguard-dkms + dnf copr disable -y jdoss/wireguard + fi + dnf autoremove -y + elif [[ ${OS} == 'centos' ]]; then + yum -y remove kmod-wireguard wireguard-tools qrencode + yum -y autoremove + elif [[ ${OS} == 'arch' ]]; then + pacman -Rs --noconfirm wireguard-tools qrencode fi - dnf autoremove -y - elif [[ ${OS} == 'centos' ]]; then - yum -y remove kmod-wireguard wireguard-tools qrencode - yum -y autoremove - elif [[ ${OS} == 'arch' ]]; then - pacman -Rs --noconfirm wireguard-tools qrencode - fi - rm -rf /etc/wireguard - rm -f /etc/sysctl.d/wg.conf + rm -rf /etc/wireguard + rm -f /etc/sysctl.d/wg.conf - # Reload sysctl - sysctl --system + # Reload sysctl + sysctl --system - # Check if WireGuard is running - systemctl is-active --quiet "wg-quick@${SERVER_WG_NIC}" - WG_RUNNING=$? + # Check if WireGuard is running + systemctl is-active --quiet "wg-quick@${SERVER_WG_NIC}" + WG_RUNNING=$? - if [[ ${WG_RUNNING} -eq 0 ]]; then - echo "WireGuard failed to uninstall properly." - exit 1 + if [[ ${WG_RUNNING} -eq 0 ]]; then + echo "WireGuard failed to uninstall properly." + exit 1 + else + echo "WireGuard uninstalled successfully." + exit 0 + fi else - echo "WireGuard uninstalled successfully." - exit 0 + echo "" + echo "Removal aborted!" fi }