From 0015f65b98dc3acf82cf83ea6a4683a197a9ecc9 Mon Sep 17 00:00:00 2001 From: Teddysun Date: Sun, 27 Oct 2019 14:22:46 +0900 Subject: [PATCH] Update wireguard.sh Added uninstall wireguard function --- wireguard.sh | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/wireguard.sh b/wireguard.sh index 017f50f..42efca6 100644 --- a/wireguard.sh +++ b/wireguard.sh @@ -283,6 +283,37 @@ install_wg_2() { fi } +# Uninstall WireGuard +uninstall_wg() { + if ! _is_installed; then + _error "WireGuard is not installed" + fi + _info "Uninstall WireGuard start" + # stop wireguard at first + _error_detect "systemctl stop wg-quick@${SERVER_WG_NIC}" + _error_detect "systemctl disable wg-quick@${SERVER_WG_NIC}" + # if wireguard has been installed from repository + if _exists "yum" && _exists "rpm"; then + if rpm -qa | grep -q wireguard; then + _error_detect "yum -y remove wireguard-dkms wireguard-tools" + fi + elif _exists "apt" && _exists "apt-get"; then + if apt list --installed | grep -q wireguard; then + _error_detect "apt-get -y remove wireguard" + fi + fi + # if wireguard has been installed from source + if _is_installed; then + _error_detect "rm -f /usr/bin/wg" + _error_detect "rm -f /usr/bin/wg-quick" + _error_detect "rm -f /usr/share/man/man8/wg.8" + _error_detect "rm -f /usr/share/man/man8/wg-quick.8" + _exists "modprobe" && _error_detect "modprobe -r wireguard" + fi + [ -d "/etc/wireguard" ] && _error_detect "rm -fr /etc/wireguard" + _info "Uninstall WireGuard completed" +} + # Create server interface create_server_if() { SERVER_PRIVATE_KEY="$(wg genkey)" @@ -615,6 +646,7 @@ Options: -a, --add Add a WireGuard client -d, --del Delete a WireGuard client -l, --list List all WireGuard client's IP + -n, --uninstall Uninstall WireGuard " } @@ -706,6 +738,9 @@ main() { -l|--list) list_clients ;; + -n|--uninstall) + uninstall_wg + ;; *) show_help ;;