From bed5384ea49b8ca73bd8015c7848acb3f26a8b27 Mon Sep 17 00:00:00 2001 From: Daniel Hansson Date: Tue, 3 Oct 2023 23:18:30 +0200 Subject: [PATCH 01/14] Add uninstaller This is based on the install script, line by line. Will maybe make a nicer menu of everything if I have time and motivation. This PR can be merged as is though. --- uninstall.sh | 199 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 199 insertions(+) create mode 100644 uninstall.sh diff --git a/uninstall.sh b/uninstall.sh new file mode 100644 index 0000000..f7e490f --- /dev/null +++ b/uninstall.sh @@ -0,0 +1,199 @@ +#!/bin/bash + +# shellcheck disable=2034,2059,2164 +true +# see https://github.com/koalaman/shellcheck/wiki/Directive + +################################################################################################################## + +if [[ "$EUID" -ne 0 ]] +then + echo "Sorry, you are not root. You now have two options:" + echo + echo "1. Use SUDO directly:" + echo " a) :~$ sudo bash install.sh" + echo + echo "2. Become ROOT and then type your command:" + echo " a) :~$ sudo -i" + echo " b) :~# bash install.sh" + echo + echo "More information can be found here: https://unix.stackexchange.com/a/3064" + exit 1 +fi + +# Identify OS +if [ -f /etc/os-release ] +then + # freedesktop.org and systemd + # shellcheck source=/dev/null + source /etc/os-release + OS=$NAME + VER=$VERSION_ID + UPSTREAM_ID=${ID_LIKE,,} + + # Fallback to ID_LIKE if ID was not 'ubuntu' or 'debian' + if [ "${UPSTREAM_ID}" != "debian" ] && [ "${UPSTREAM_ID}" != "ubuntu" ] + then + UPSTREAM_ID="$(echo "${ID_LIKE,,}" | sed s/\"//g | cut -d' ' -f1)" + fi + +elif type lsb_release >/dev/null 2>&1 +then + # linuxbase.org + OS=$(lsb_release -si) + VER=$(lsb_release -sr) +elif [ -f /etc/lsb-release ] +then + # For some versions of Debian/Ubuntu without lsb_release command + # shellcheck source=/dev/null + source /etc/os-release + OS=$DISTRIB_ID + VER=$DISTRIB_RELEASE +elif [ -f /etc/debian_version ] +then + # Older Debian, Ubuntu, etc. + OS=Debian + VER=$(cat /etc/debian_version) +elif [ -f /etc/SuSE-release ] +then + # Older SuSE, etc. + OS=SuSE + VER=$(cat /etc/SuSE-release) +elif [ -f /etc/redhat-release ] +then + # Older Red Hat, CentOS, etc. + OS=RedHat + VER=$(cat /etc/redhat-release) +else + # Fall back to uname, e.g. "Linux ", also works for BSD, etc. + OS=$(uname -s) + VER=$(uname -r) +fi + +# Setup prereqs for server +# Common named prereqs +PREREQ=(wget unzip tar whiptail) +PREREQDEB=(dnsutils) +PREREQRPM=(bind-utils) +PREREQARCH=(bind) + +echo "Removing packages..." +if [ "${ID}" = "debian" ] || [ "$OS" = "Ubuntu" ] || [ "$OS" = "Debian" ] || [ "${UPSTREAM_ID}" = "ubuntu" ] || [ "${UPSTREAM_ID}" = "debian" ] +then + apt-get purge -y "${PREREQ[@]}" "${PREREQDEB[@]}" +elif [ "$OS" = "CentOS" ] || [ "$OS" = "RedHat" ] || [ "${UPSTREAM_ID}" = "rhel" ] || [ "${OS}" = "Almalinux" ] || [ "${UPSTREAM_ID}" = "Rocky*" ] +then +# openSUSE 15.4 fails to run the relay service and hangs waiting for it +# Needs more work before it can be enabled +# || [ "${UPSTREAM_ID}" = "suse" ] + yum purge -y "${PREREQ[@]}" "${PREREQRPM[@]}" # git +elif [ "${ID}" = "arch" ] || [ "${UPSTREAM_ID}" = "arch" ] +then + pacman -R "${PREREQ[@]}" "${PREREQARCH[@]}" +fi + +# Download the lib file +if ! curl -fSL https://raw.githubusercontent.com/rustdesk/rustdesk-server-pro/main/lib.sh -o lib.sh +then + echo "Failed to download the lib.sh file. Please try again" + exit 1 +fi + +# shellcheck disable=2034,2059,2164 +true +# shellcheck source=lib.sh +source lib.sh + +# Output debugging info if $DEBUG set +if [ "$DEBUG" = "true" ] +then + print_text_in_color "$ICyan" "OS: $OS" + print_text_in_color "$ICyan" "VER: $VER" + print_text_in_color "$ICyan" "UPSTREAM_ID: $UPSTREAM_ID" + exit 0 +fi + +msg_box "WARNING WARNING WARNING + +This script will remove EVERYTHING that was installed by the Rustdesk Linux installer. +You can choose to opt out after you hit OK." + +if ! yesno_box_no "Are you REALLY sure you want to continue with the uninstallation?" +then + exit 0 +fi + +# Deleting UFW rules +ufw delete allow 21115:21119/tcp +# ufw delete 22/tcp # If connected to a remote VPS, this deletion will make the connection go down +ufw delete allow 21116/udp +if [ -f "/etc/nginx/sites-available/rustdesk.conf" ] +then + ufw delete allow 80/tcp + ufw delete allow 443/tcp +else + ufw delete allow 21114/tcp +fi +ufw disable +ufw reload + +# Rustdesk installation dir +print_text_in_color "$IGreen" "Removing RustDesk Server..." +rm -rf "$RUSTDESK_INSTALL_DIR" +rm -rf /usr/bin/hbbr +rm -rf /usr/bin/hbbr + +# Rustdesk LOG dir +rm -rf "$RUSTDESK_LOG_DIR" + +# systemctl services +# HBBS +systemctl disable rustdesk-hbbs.service +systemctl stop rustdesk-hbbs.service +rm -f "/etc/systemd/system/rustdesk-hbbs.service" +# HBBR +systemctl disable rustdesk-hbbr.service +systemctl stop rustdesk-hbbr.service +rm -f "/etc/systemd/system/rustdesk-hbbr.service" +# daemon-reload +systemctl daemon-reload + +# Certbot & NGINX +if [ "${ID}" = "debian" ] || [ "$OS" = "Ubuntu" ] || [ "$OS" = "Debian" ] || [ "${UPSTREAM_ID}" = "ubuntu" ] || [ "${UPSTREAM_ID}" = "debian" ] +then + if snap list | grep -q certbot > /dev/null + then + apt-get purge snapd -y + snap remove certbot + else + apt-get purge nginx -y + apt-get purge python3-certbot-nginx -y + fi +elif [ "$OS" = "CentOS" ] || [ "$OS" = "RedHat" ] || [ "${UPSTREAM_ID}" = "rhel" ] || [ "${OS}" = "Almalinux" ] || [ "${UPSTREAM_ID}" = "Rocky*" ] +then +# openSUSE 15.4 fails to run the relay service and hangs waiting for it +# Needs more work before it can be enabled +# || [ "${UPSTREAM_ID}" = "suse" ] + yum -y purge nginx + yum -y purge python3-certbot-nginx +elif [ "${ID}" = "arch" ] || [ "${UPSTREAM_ID}" = "arch" ] +then + pacman -S purge nginx + pacman -S purge python3-certbot-nginx +fi +rm -f "/etc/nginx/sites-available/rustdesk.conf" +rm -f "/etc/nginx/sites-enabled/rustdesk.conf" +service nginx restart + +# Let's Encrypt +rm -rf /etc/letsencrypt + +# The rest +apt-get purge curl ufw -y +apt autoremove -y + +msg_box "Uninstallation complete! + +Please hit OK to remove the last file." + +rm -f lib.sh From dcd7f828c0ba827de3392a430088e41b732bb6ec Mon Sep 17 00:00:00 2001 From: Daniel Hansson Date: Wed, 4 Oct 2023 14:10:43 +0200 Subject: [PATCH 02/14] add more functions --- lib.sh | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 92 insertions(+), 1 deletion(-) diff --git a/lib.sh b/lib.sh index b416c3a..b157cf5 100644 --- a/lib.sh +++ b/lib.sh @@ -8,7 +8,8 @@ true RUSTDESK_INSTALL_DIR=/var/lib/rustdesk-server RUSTDESK_LOG_DIR=/var/log/rustdesk-server - +ARCH=$(uname -m) +TITLE="RustDesk Linux installer" WANIP4=$(curl -s -k -m 5 -4 https://api64.ipify.org) ############ Functions @@ -66,6 +67,96 @@ input_box_flow() { echo "$RESULT" } +identify_os() { +if [ -f /etc/os-release ] +then + # freedesktop.org and systemd + # shellcheck source=/dev/null + source /etc/os-release + OS=$NAME + VER=$VERSION_ID + UPSTREAM_ID=${ID_LIKE,,} + + # Fallback to ID_LIKE if ID was not 'ubuntu' or 'debian' + if [ "${UPSTREAM_ID}" != "debian" ] && [ "${UPSTREAM_ID}" != "ubuntu" ] + then + UPSTREAM_ID="$(echo "${ID_LIKE,,}" | sed s/\"//g | cut -d' ' -f1)" + fi +elif type lsb_release >/dev/null 2>&1 +then + # linuxbase.org + OS=$(lsb_release -si) + VER=$(lsb_release -sr) +elif [ -f /etc/lsb-release ] +then + # For some versions of Debian/Ubuntu without lsb_release command + # shellcheck source=/dev/null + source /etc/os-release + OS=$DISTRIB_ID + VER=$DISTRIB_RELEASE +elif [ -f /etc/debian_version ] +then + # Older Debian, Ubuntu, etc. + OS=Debian + VER=$(cat /etc/debian_version) +elif [ -f /etc/SuSE-release ] +then + # Older SuSE, etc. + OS=SuSE + VER=$(cat /etc/SuSE-release) +elif [ -f /etc/redhat-release ] +then + # Older Red Hat, CentOS, etc. + OS=RedHat + VER=$(cat /etc/redhat-release) +else + # Fall back to uname, e.g. "Linux ", also works for BSD, etc. + OS=$(uname -s) + VER=$(uname -r) +fi +} + +purge_linux_package() { + # Identify which OS it is + if [ -z "${ID}" ] || [ -z "$OS" ] || [ -z "${UPSTREAM_ID}" ] + then + identify_os + fi + # Purge based on OS + if [ "${ID}" = "debian" ] || [ "$OS" = "Ubuntu" ] || [ "$OS" = "Debian" ] || [ "${UPSTREAM_ID}" = "ubuntu" ] || [ "${UPSTREAM_ID}" = "debian" ] + then + apt-get purge "${1}" -y + apt-get autoremove -y + elif [ "$OS" = "CentOS" ] || [ "$OS" = "RedHat" ] || [ "${UPSTREAM_ID}" = "rhel" ] || [ "${OS}" = "Almalinux" ] || [ "${UPSTREAM_ID}" = "Rocky*" ] + then + yum purge "${1}" -y + elif [ "${ID}" = "arch" ] || [ "${UPSTREAM_ID}" = "arch" ] + then + pacman -S purge "${1}" + fi +} + +install_linux_package() { + # Identify which OS it is + if [ -z "${ID}" ] || [ -z "$OS" ] || [ -z "${UPSTREAM_ID}" ] + then + identify_os + fi + + # Install based on OS + if [ "${ID}" = "debian" ] || [ "$OS" = "Ubuntu" ] || [ "$OS" = "Debian" ] || [ "${UPSTREAM_ID}" = "ubuntu" ] || [ "${UPSTREAM_ID}" = "debian" ] + then + apt-get install "${1}" -y + elif [ "$OS" = "CentOS" ] || [ "$OS" = "RedHat" ] || [ "${UPSTREAM_ID}" = "rhel" ] || [ "${OS}" = "Almalinux" ] || [ "${UPSTREAM_ID}" = "Rocky*" ] + then + yum install "${1}" -y + elif [ "${ID}" = "arch" ] || [ "${UPSTREAM_ID}" = "arch" ] + then + pacman -S install "${1}" + fi +} + + ## bash colors # Reset From 57862cb63fa0d3a84466c0fc9c0b321a468f768a Mon Sep 17 00:00:00 2001 From: Daniel Hansson Date: Wed, 4 Oct 2023 14:11:41 +0200 Subject: [PATCH 03/14] rethink the uninstaller --- uninstall.sh | 299 +++++++++++++++++++++++++++++---------------------- 1 file changed, 170 insertions(+), 129 deletions(-) diff --git a/uninstall.sh b/uninstall.sh index f7e490f..c09d1ef 100644 --- a/uninstall.sh +++ b/uninstall.sh @@ -21,77 +21,6 @@ then exit 1 fi -# Identify OS -if [ -f /etc/os-release ] -then - # freedesktop.org and systemd - # shellcheck source=/dev/null - source /etc/os-release - OS=$NAME - VER=$VERSION_ID - UPSTREAM_ID=${ID_LIKE,,} - - # Fallback to ID_LIKE if ID was not 'ubuntu' or 'debian' - if [ "${UPSTREAM_ID}" != "debian" ] && [ "${UPSTREAM_ID}" != "ubuntu" ] - then - UPSTREAM_ID="$(echo "${ID_LIKE,,}" | sed s/\"//g | cut -d' ' -f1)" - fi - -elif type lsb_release >/dev/null 2>&1 -then - # linuxbase.org - OS=$(lsb_release -si) - VER=$(lsb_release -sr) -elif [ -f /etc/lsb-release ] -then - # For some versions of Debian/Ubuntu without lsb_release command - # shellcheck source=/dev/null - source /etc/os-release - OS=$DISTRIB_ID - VER=$DISTRIB_RELEASE -elif [ -f /etc/debian_version ] -then - # Older Debian, Ubuntu, etc. - OS=Debian - VER=$(cat /etc/debian_version) -elif [ -f /etc/SuSE-release ] -then - # Older SuSE, etc. - OS=SuSE - VER=$(cat /etc/SuSE-release) -elif [ -f /etc/redhat-release ] -then - # Older Red Hat, CentOS, etc. - OS=RedHat - VER=$(cat /etc/redhat-release) -else - # Fall back to uname, e.g. "Linux ", also works for BSD, etc. - OS=$(uname -s) - VER=$(uname -r) -fi - -# Setup prereqs for server -# Common named prereqs -PREREQ=(wget unzip tar whiptail) -PREREQDEB=(dnsutils) -PREREQRPM=(bind-utils) -PREREQARCH=(bind) - -echo "Removing packages..." -if [ "${ID}" = "debian" ] || [ "$OS" = "Ubuntu" ] || [ "$OS" = "Debian" ] || [ "${UPSTREAM_ID}" = "ubuntu" ] || [ "${UPSTREAM_ID}" = "debian" ] -then - apt-get purge -y "${PREREQ[@]}" "${PREREQDEB[@]}" -elif [ "$OS" = "CentOS" ] || [ "$OS" = "RedHat" ] || [ "${UPSTREAM_ID}" = "rhel" ] || [ "${OS}" = "Almalinux" ] || [ "${UPSTREAM_ID}" = "Rocky*" ] -then -# openSUSE 15.4 fails to run the relay service and hangs waiting for it -# Needs more work before it can be enabled -# || [ "${UPSTREAM_ID}" = "suse" ] - yum purge -y "${PREREQ[@]}" "${PREREQRPM[@]}" # git -elif [ "${ID}" = "arch" ] || [ "${UPSTREAM_ID}" = "arch" ] -then - pacman -R "${PREREQ[@]}" "${PREREQARCH[@]}" -fi - # Download the lib file if ! curl -fSL https://raw.githubusercontent.com/rustdesk/rustdesk-server-pro/main/lib.sh -o lib.sh then @@ -107,15 +36,79 @@ source lib.sh # Output debugging info if $DEBUG set if [ "$DEBUG" = "true" ] then + identify_os print_text_in_color "$ICyan" "OS: $OS" print_text_in_color "$ICyan" "VER: $VER" print_text_in_color "$ICyan" "UPSTREAM_ID: $UPSTREAM_ID" exit 0 fi +# Uninstall Rustdesk Menu +choice=$(whiptail --title "$TITLE" --checklist \ +"What do you want to uninstall? +$CHECKLIST_GUIDE\n\n$RUN_LATER_GUIDE" "$WT_HEIGHT" "$WT_WIDTH" 4 \ +"curl" "(Removes curl package)" OFF \ +"nginx" "(Removes nginx package + all configurations)" ON \ +"wget" "(Removes wget package)" ON \ +"unzip" "(Removes unzip package)" ON \ +"tar" "(Removes tar package)" ON \ +"whiptail" "(Removes whiptail package)" ON \ +"dnsutils" "(Removes dnsutils package)" ON \ +"bind-utils" "(Removes bind-utils package)" ON \ +"bind" "(Removes bind package)" ON \ +"UFW" "(Removes UFW package plus rules)" ON \ +"Rustdesk LOGs" "(Removes RustDesk log dir)" ON \ +"Rustdesk Server" "(Removes Rustdesk server + services)" ON \ +"Certbot" "(Removes Certbot package plus Let's Encrypt)" ON 3>&1 1>&2 2>&3) + +case "$choice" in + *"curl"*) + curl=yes + ;;& + *"nginx"*) + nginx=yes + ;;& + *"wget"*) + wget=yes + ;;& + *"unzip"*) + unzip=yes + ;;& + *"tar"*) + tar=yes + ;;& + *"whiptail"*) + whiptail=yes + ;;& + *"dnsutils"*) + dnsutils=yes + ;;& + *"bind-utils"*) + bind-utils=yes + ;;& + *"bind"*) + bind=yes + ;;& + *"UFW"*) + UFW=yes + ;;& + *"Rustdesk LOGs"*) + Rustdesk_LOGs=yes + ;;& + *"Rustdesk Server"*) + Rustdesk_Server=yes + ;;& + *"Certbot"*) + Certbot=yes + ;;& + *) + ;; +esac +exit + msg_box "WARNING WARNING WARNING -This script will remove EVERYTHING that was installed by the Rustdesk Linux installer. +This script will remove EVERYTHING that was you chose in the previous selection. You can choose to opt out after you hit OK." if ! yesno_box_no "Are you REALLY sure you want to continue with the uninstallation?" @@ -123,74 +116,122 @@ then exit 0 fi -# Deleting UFW rules -ufw delete allow 21115:21119/tcp -# ufw delete 22/tcp # If connected to a remote VPS, this deletion will make the connection go down -ufw delete allow 21116/udp -if [ -f "/etc/nginx/sites-available/rustdesk.conf" ] -then - ufw delete allow 80/tcp - ufw delete allow 443/tcp -else - ufw delete allow 21114/tcp -fi -ufw disable -ufw reload - -# Rustdesk installation dir -print_text_in_color "$IGreen" "Removing RustDesk Server..." -rm -rf "$RUSTDESK_INSTALL_DIR" -rm -rf /usr/bin/hbbr -rm -rf /usr/bin/hbbr - -# Rustdesk LOG dir -rm -rf "$RUSTDESK_LOG_DIR" - -# systemctl services -# HBBS -systemctl disable rustdesk-hbbs.service -systemctl stop rustdesk-hbbs.service -rm -f "/etc/systemd/system/rustdesk-hbbs.service" -# HBBR -systemctl disable rustdesk-hbbr.service -systemctl stop rustdesk-hbbr.service -rm -f "/etc/systemd/system/rustdesk-hbbr.service" -# daemon-reload -systemctl daemon-reload - -# Certbot & NGINX -if [ "${ID}" = "debian" ] || [ "$OS" = "Ubuntu" ] || [ "$OS" = "Debian" ] || [ "${UPSTREAM_ID}" = "ubuntu" ] || [ "${UPSTREAM_ID}" = "debian" ] +if [ -n "$UFW" ] +then + # Deleting UFW rules + ufw delete allow 21115:21119/tcp + # ufw delete 22/tcp # If connected to a remote VPS, this deletion will make the connection go down + ufw delete allow 21116/udp + if [ -f "/etc/nginx/sites-available/rustdesk.conf" ] + then + ufw delete allow 80/tcp + ufw delete allow 443/tcp + else + ufw delete allow 21114/tcp + fi + ufw disable + ufw reload +fi + +# Rustdesk Server +if [ -n "$Rustdesk_Server" ] +then + # Rustdesk installation dir + print_text_in_color "$IGreen" "Removing RustDesk Server..." + rm -rf "$RUSTDESK_INSTALL_DIR" + rm -rf /usr/bin/hbbr + rm -rf /usr/bin/hbbr + + # systemctl services + # HBBS + systemctl disable rustdesk-hbbs.service + systemctl stop rustdesk-hbbs.service + rm -f "/etc/systemd/system/rustdesk-hbbs.service" + # HBBR + systemctl disable rustdesk-hbbr.service + systemctl stop rustdesk-hbbr.service + rm -f "/etc/systemd/system/rustdesk-hbbr.service" + # daemon-reload + systemctl daemon-reload +fi + +# Rustdesk LOG +if [ -n "$Rustdesk_LOGs" ] +then + # Rustdesk LOG dir + rm -rf "$RUSTDESK_LOG_DIR" +fi + +# Certbot +if [ -n "$Certbot" ] then if snap list | grep -q certbot > /dev/null then - apt-get purge snapd -y + purge_linux_package snap snap remove certbot else - apt-get purge nginx -y - apt-get purge python3-certbot-nginx -y + purge_linux_packagepython3-certbot-nginx -y fi -elif [ "$OS" = "CentOS" ] || [ "$OS" = "RedHat" ] || [ "${UPSTREAM_ID}" = "rhel" ] || [ "${OS}" = "Almalinux" ] || [ "${UPSTREAM_ID}" = "Rocky*" ] + # Also remove the actual certs + rm -rf /etc/letsencrypt +fi + +# Nginx +if [ -n "$nginxconf" ] + rm -f "/etc/nginx/sites-available/rustdesk.conf" + rm -f "/etc/nginx/sites-enabled/rustdesk.conf" + service nginx restart +elif [ -n "$nginxall" ] +then + purge_linux_package nginx + rm -rf "/etc/nginx" +fi + +# The rest +if [ -n "$curl" ] +then + purge_linux_package curl +fi + +if [ -n "$wget" ] then -# openSUSE 15.4 fails to run the relay service and hangs waiting for it -# Needs more work before it can be enabled -# || [ "${UPSTREAM_ID}" = "suse" ] - yum -y purge nginx - yum -y purge python3-certbot-nginx -elif [ "${ID}" = "arch" ] || [ "${UPSTREAM_ID}" = "arch" ] + purge_linux_package wget +fi + +if [ -n "$unzip" ] then - pacman -S purge nginx - pacman -S purge python3-certbot-nginx + purge_linux_package unzip fi -rm -f "/etc/nginx/sites-available/rustdesk.conf" -rm -f "/etc/nginx/sites-enabled/rustdesk.conf" -service nginx restart -# Let's Encrypt -rm -rf /etc/letsencrypt +if [ -n "$tar" ] +then + purge_linux_package tar +fi -# The rest -apt-get purge curl ufw -y -apt autoremove -y +if [ -n "$whiptail" ] +then + purge_linux_package whiptail +fi + +if [ -n "$dnsutils" ] +then + purge_linux_package dnsutils +fi + +if [ -n "$bind-utils" ] +then + purge_linux_package bind-utils +fi + +if [ -n "$bind" ] +then + purge_linux_package bind +fi + +if [ -n "$UFW" ] +then + purge_linux_package ufw +fi msg_box "Uninstallation complete! From f03fc83c4f2dc5bf91ff6bfcd675c92afba024a8 Mon Sep 17 00:00:00 2001 From: Daniel Hansson Date: Wed, 4 Oct 2023 14:15:23 +0200 Subject: [PATCH 04/14] more vars --- lib.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib.sh b/lib.sh index b157cf5..4c1a0bf 100644 --- a/lib.sh +++ b/lib.sh @@ -6,11 +6,19 @@ true ############ Variables +# PATH & DIR RUSTDESK_INSTALL_DIR=/var/lib/rustdesk-server RUSTDESK_LOG_DIR=/var/log/rustdesk-server +# OS ARCH=$(uname -m) -TITLE="RustDesk Linux installer" +# Network WANIP4=$(curl -s -k -m 5 -4 https://api64.ipify.org) +# Whiptail menus +TITLE="RustDesk Setup - $(date +%Y)" +[ -n "$SCRIPT_NAME" ] && TITLE+=" - $SCRIPT_NAME" +CHECKLIST_GUIDE="Navigate with the [ARROW] keys and (de)select with the [SPACE] key. \ +Confirm by pressing [ENTER]. Cancel by pressing [ESC]." +MENU_GUIDE="Navigate with the [ARROW] keys and confirm by pressing [ENTER]. Cancel by pressing [ESC]." ############ Functions From 386e548d5c340e400b80fabfb711c9288bcdf26c Mon Sep 17 00:00:00 2001 From: Daniel Hansson Date: Wed, 4 Oct 2023 14:20:59 +0200 Subject: [PATCH 05/14] SC --- uninstall.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/uninstall.sh b/uninstall.sh index c09d1ef..81a9aad 100644 --- a/uninstall.sh +++ b/uninstall.sh @@ -48,7 +48,8 @@ choice=$(whiptail --title "$TITLE" --checklist \ "What do you want to uninstall? $CHECKLIST_GUIDE\n\n$RUN_LATER_GUIDE" "$WT_HEIGHT" "$WT_WIDTH" 4 \ "curl" "(Removes curl package)" OFF \ -"nginx" "(Removes nginx package + all configurations)" ON \ +"nginxconf" "(Removes Rustdesk Nginx config)" ON \ +"nginxall" "(Removes Nginx package + all configurations)" ON \ "wget" "(Removes wget package)" ON \ "unzip" "(Removes unzip package)" ON \ "tar" "(Removes tar package)" ON \ @@ -178,6 +179,7 @@ fi # Nginx if [ -n "$nginxconf" ] +then rm -f "/etc/nginx/sites-available/rustdesk.conf" rm -f "/etc/nginx/sites-enabled/rustdesk.conf" service nginx restart From d992357a917c07ac0260eb8dfd80d6ad82083b0a Mon Sep 17 00:00:00 2001 From: Daniel Hansson Date: Wed, 4 Oct 2023 14:21:50 +0200 Subject: [PATCH 06/14] add missing var --- uninstall.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/uninstall.sh b/uninstall.sh index 81a9aad..4527265 100644 --- a/uninstall.sh +++ b/uninstall.sh @@ -66,8 +66,11 @@ case "$choice" in *"curl"*) curl=yes ;;& - *"nginx"*) - nginx=yes + *"nginxconf"*) + nginxconf=yes + ;;& + *"nginxall"*) + nginxall=yes ;;& *"wget"*) wget=yes From 5929f8260e3325f85bc6b5d9eea15bfbfd43389e Mon Sep 17 00:00:00 2001 From: Daniel Hansson Date: Wed, 4 Oct 2023 14:49:18 +0200 Subject: [PATCH 07/14] rename vars --- uninstall.sh | 83 ++++++++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 42 deletions(-) diff --git a/uninstall.sh b/uninstall.sh index 4527265..00e160e 100644 --- a/uninstall.sh +++ b/uninstall.sh @@ -47,68 +47,67 @@ fi choice=$(whiptail --title "$TITLE" --checklist \ "What do you want to uninstall? $CHECKLIST_GUIDE\n\n$RUN_LATER_GUIDE" "$WT_HEIGHT" "$WT_WIDTH" 4 \ -"curl" "(Removes curl package)" OFF \ -"nginxconf" "(Removes Rustdesk Nginx config)" ON \ -"nginxall" "(Removes Nginx package + all configurations)" ON \ -"wget" "(Removes wget package)" ON \ -"unzip" "(Removes unzip package)" ON \ -"tar" "(Removes tar package)" ON \ -"whiptail" "(Removes whiptail package)" ON \ -"dnsutils" "(Removes dnsutils package)" ON \ -"bind-utils" "(Removes bind-utils package)" ON \ -"bind" "(Removes bind package)" ON \ -"UFW" "(Removes UFW package plus rules)" ON \ +"curl" "(Removes curl:// linux package)" OFF \ +"nginxconf" "(Removes Rustdesk Nginx config)" OFF \ +"nginxall" "(Removes *everything* releated to Nginx)" ON \ +"wget" "(Removes wget linux package)" ON \ +"unzip" "(Removes unzip linux package)" ON \ +"tar" "(Removes tar linux package)" ON \ +"whiptail" "(Removes whiptail linux package)" ON \ +"dnsutils" "(Removes dnsutils linux package)" ON \ +"bind-utils" "(Removes bind-utils linux package)" ON \ +"bind" "(Removes bind linux package)" ON \ +"UFW" "(Removes UFW linux package plus rules)" ON \ "Rustdesk LOGs" "(Removes RustDesk log dir)" ON \ "Rustdesk Server" "(Removes Rustdesk server + services)" ON \ "Certbot" "(Removes Certbot package plus Let's Encrypt)" ON 3>&1 1>&2 2>&3) case "$choice" in *"curl"*) - curl=yes + REMOVECURL="yes" ;;& *"nginxconf"*) - nginxconf=yes + REMOVE_NGINX_CONF="yes" ;;& *"nginxall"*) - nginxall=yes + REMOVE_NGINX_ALL="yes" ;;& *"wget"*) - wget=yes + REMOVE_WGET="yes" ;;& *"unzip"*) - unzip=yes + REMOVE_UNZIP="yes" ;;& *"tar"*) - tar=yes + REMOVE_TAR="yes" ;;& *"whiptail"*) - whiptail=yes + REMOVE_WHIPTAIL="yes" ;;& *"dnsutils"*) - dnsutils=yes + REMOVE_DNSUTILS="yes" ;;& *"bind-utils"*) - bind-utils=yes + REMOVE_BIND_UTILS="yes" ;;& *"bind"*) - bind=yes + REMOVE_BIND="yes" ;;& *"UFW"*) - UFW=yes + REMOVE_UFW="yes" ;;& *"Rustdesk LOGs"*) - Rustdesk_LOGs=yes + REMOVE_RUSTDESK_LOG="yes" ;;& - *"Rustdesk Server"*) - Rustdesk_Server=yes + *"Rustdesk SERVER"*) + REMOVE_RUSTDESK_SERVER="yes" ;;& *"Certbot"*) - Certbot=yes + REMOVE_CERTBOT="yes" ;;& *) ;; esac -exit msg_box "WARNING WARNING WARNING @@ -138,7 +137,7 @@ then fi # Rustdesk Server -if [ -n "$Rustdesk_Server" ] +if [ -n "$REMOVE_RUSTDESK_SERVER" ] then # Rustdesk installation dir print_text_in_color "$IGreen" "Removing RustDesk Server..." @@ -160,80 +159,80 @@ then fi # Rustdesk LOG -if [ -n "$Rustdesk_LOGs" ] +if [ -n "$REMOVE_RUSTDESK_LOG" ] then # Rustdesk LOG dir rm -rf "$RUSTDESK_LOG_DIR" fi # Certbot -if [ -n "$Certbot" ] +if [ -n "$REMOVE_CERTBOT" ] then if snap list | grep -q certbot > /dev/null then purge_linux_package snap snap remove certbot else - purge_linux_packagepython3-certbot-nginx -y + purge_linux_package python3-certbot-nginx -y fi # Also remove the actual certs rm -rf /etc/letsencrypt fi # Nginx -if [ -n "$nginxconf" ] +if [ -n "$REMOVE_NGINX_CONF" ] then rm -f "/etc/nginx/sites-available/rustdesk.conf" rm -f "/etc/nginx/sites-enabled/rustdesk.conf" service nginx restart -elif [ -n "$nginxall" ] +elif [ -n "$REMOVE_NGINX_ALL" ] then purge_linux_package nginx rm -rf "/etc/nginx" fi # The rest -if [ -n "$curl" ] +if [ -n "$REMOVE_CURL" ] then purge_linux_package curl fi -if [ -n "$wget" ] +if [ -n "$REMOVE_WGET" ] then purge_linux_package wget fi -if [ -n "$unzip" ] +if [ -n "$REMOVE_UNZIP" ] then purge_linux_package unzip fi -if [ -n "$tar" ] +if [ -n "$REMOVE_TAR" ] then purge_linux_package tar fi -if [ -n "$whiptail" ] +if [ -n "$REMOVE_WHIPTAIL" ] then purge_linux_package whiptail fi -if [ -n "$dnsutils" ] +if [ -n "$REMOVE_DNSUTILS" ] then purge_linux_package dnsutils fi -if [ -n "$bind-utils" ] +if [ -n "$REMOVE_BIND_UTILS" ] then purge_linux_package bind-utils fi -if [ -n "$bind" ] +if [ -n "$REMOVE_BIND" ] then purge_linux_package bind fi -if [ -n "$UFW" ] +if [ -n "$REMOVE_UFW" ] then purge_linux_package ufw fi From 0f95c5d8b48b8fa87f1231f6f95d2115d0eb7564 Mon Sep 17 00:00:00 2001 From: Daniel Hansson Date: Wed, 4 Oct 2023 14:59:39 +0200 Subject: [PATCH 08/14] final touches --- uninstall.sh | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/uninstall.sh b/uninstall.sh index 00e160e..0627b18 100644 --- a/uninstall.sh +++ b/uninstall.sh @@ -22,11 +22,11 @@ then fi # Download the lib file -if ! curl -fSL https://raw.githubusercontent.com/rustdesk/rustdesk-server-pro/main/lib.sh -o lib.sh -then - echo "Failed to download the lib.sh file. Please try again" - exit 1 -fi +#if ! curl -fSL https://raw.githubusercontent.com/rustdesk/rustdesk-server-pro/main/lib.sh -o lib.sh +#then +# echo "Failed to download the lib.sh file. Please try again" +# exit 1 +#fi # shellcheck disable=2034,2059,2164 true @@ -43,6 +43,15 @@ then exit 0 fi + +# Switch for Certbot +if [ -d /etc/letsencrypt ] +then + CERTBOT_SWITCH=ON +else + CERTBOT_SWITCH=OFF +fi + # Uninstall Rustdesk Menu choice=$(whiptail --title "$TITLE" --checklist \ "What do you want to uninstall? @@ -52,7 +61,6 @@ $CHECKLIST_GUIDE\n\n$RUN_LATER_GUIDE" "$WT_HEIGHT" "$WT_WIDTH" 4 \ "nginxall" "(Removes *everything* releated to Nginx)" ON \ "wget" "(Removes wget linux package)" ON \ "unzip" "(Removes unzip linux package)" ON \ -"tar" "(Removes tar linux package)" ON \ "whiptail" "(Removes whiptail linux package)" ON \ "dnsutils" "(Removes dnsutils linux package)" ON \ "bind-utils" "(Removes bind-utils linux package)" ON \ @@ -60,11 +68,11 @@ $CHECKLIST_GUIDE\n\n$RUN_LATER_GUIDE" "$WT_HEIGHT" "$WT_WIDTH" 4 \ "UFW" "(Removes UFW linux package plus rules)" ON \ "Rustdesk LOGs" "(Removes RustDesk log dir)" ON \ "Rustdesk Server" "(Removes Rustdesk server + services)" ON \ -"Certbot" "(Removes Certbot package plus Let's Encrypt)" ON 3>&1 1>&2 2>&3) +"Certbot" "(Removes Certbot package plus Let's Encrypt)" "$CERTBOT_SWITCH" 3>&1 1>&2 2>&3) case "$choice" in *"curl"*) - REMOVECURL="yes" + REMOVE_CURL="yes" ;;& *"nginxconf"*) REMOVE_NGINX_CONF="yes" @@ -78,9 +86,6 @@ case "$choice" in *"unzip"*) REMOVE_UNZIP="yes" ;;& - *"tar"*) - REMOVE_TAR="yes" - ;;& *"whiptail"*) REMOVE_WHIPTAIL="yes" ;;& @@ -207,16 +212,6 @@ then purge_linux_package unzip fi -if [ -n "$REMOVE_TAR" ] -then - purge_linux_package tar -fi - -if [ -n "$REMOVE_WHIPTAIL" ] -then - purge_linux_package whiptail -fi - if [ -n "$REMOVE_DNSUTILS" ] then purge_linux_package dnsutils @@ -241,4 +236,8 @@ msg_box "Uninstallation complete! Please hit OK to remove the last file." +if [ -n "$REMOVE_WHIPTAIL" ] +then + purge_linux_package whiptail +fi rm -f lib.sh From 19623b0011e7b2e190cc0063627ea4b366577f1c Mon Sep 17 00:00:00 2001 From: Daniel Hansson Date: Wed, 4 Oct 2023 15:07:41 +0200 Subject: [PATCH 09/14] forgot to remove testing stuff --- uninstall.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/uninstall.sh b/uninstall.sh index 0627b18..2668f1e 100644 --- a/uninstall.sh +++ b/uninstall.sh @@ -22,11 +22,11 @@ then fi # Download the lib file -#if ! curl -fSL https://raw.githubusercontent.com/rustdesk/rustdesk-server-pro/main/lib.sh -o lib.sh -#then -# echo "Failed to download the lib.sh file. Please try again" -# exit 1 -#fi +if ! curl -fSL https://raw.githubusercontent.com/rustdesk/rustdesk-server-pro/main/lib.sh -o lib.sh +then + echo "Failed to download the lib.sh file. Please try again" + exit 1 +fi # shellcheck disable=2034,2059,2164 true From 14b7019d21174d35c9a66cd9dbf3d365efd76a36 Mon Sep 17 00:00:00 2001 From: Daniel Hansson Date: Wed, 4 Oct 2023 15:36:00 +0200 Subject: [PATCH 10/14] add script name --- uninstall.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/uninstall.sh b/uninstall.sh index 2668f1e..e3360eb 100644 --- a/uninstall.sh +++ b/uninstall.sh @@ -1,9 +1,5 @@ #!/bin/bash -# shellcheck disable=2034,2059,2164 -true -# see https://github.com/koalaman/shellcheck/wiki/Directive - ################################################################################################################## if [[ "$EUID" -ne 0 ]] @@ -30,6 +26,7 @@ fi # shellcheck disable=2034,2059,2164 true +SCRIPT_NAME="Uninstall Script" # shellcheck source=lib.sh source lib.sh From 6ed4d3816018e4f01ba8da99a95e6a3c90959cf9 Mon Sep 17 00:00:00 2001 From: Daniel Hansson Date: Wed, 4 Oct 2023 15:36:29 +0200 Subject: [PATCH 11/14] more generic title --- lib.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib.sh b/lib.sh index 4c1a0bf..142dc8b 100644 --- a/lib.sh +++ b/lib.sh @@ -14,7 +14,7 @@ ARCH=$(uname -m) # Network WANIP4=$(curl -s -k -m 5 -4 https://api64.ipify.org) # Whiptail menus -TITLE="RustDesk Setup - $(date +%Y)" +TITLE="RustDesk - $(date +%Y)" [ -n "$SCRIPT_NAME" ] && TITLE+=" - $SCRIPT_NAME" CHECKLIST_GUIDE="Navigate with the [ARROW] keys and (de)select with the [SPACE] key. \ Confirm by pressing [ENTER]. Cancel by pressing [ESC]." From 6da8204aab7650ec996e594a9074eff3b46c9acb Mon Sep 17 00:00:00 2001 From: Daniel Hansson Date: Wed, 4 Oct 2023 18:27:13 +0200 Subject: [PATCH 12/14] correct syntax for removing with pacman and yum --- lib.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib.sh b/lib.sh index 142dc8b..3bd5adf 100644 --- a/lib.sh +++ b/lib.sh @@ -137,10 +137,10 @@ purge_linux_package() { apt-get autoremove -y elif [ "$OS" = "CentOS" ] || [ "$OS" = "RedHat" ] || [ "${UPSTREAM_ID}" = "rhel" ] || [ "${OS}" = "Almalinux" ] || [ "${UPSTREAM_ID}" = "Rocky*" ] then - yum purge "${1}" -y + yum remove "${1}" -y elif [ "${ID}" = "arch" ] || [ "${UPSTREAM_ID}" = "arch" ] then - pacman -S purge "${1}" + pacman -Rs "${1}" fi } From af077524cc2969e380b254e801c5bf39f7d9347b Mon Sep 17 00:00:00 2001 From: Daniel Hansson Date: Wed, 4 Oct 2023 19:34:50 +0200 Subject: [PATCH 13/14] add support for more OSes --- lib.sh | 75 ++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 47 insertions(+), 28 deletions(-) diff --git a/lib.sh b/lib.sh index 3bd5adf..93c5a53 100644 --- a/lib.sh +++ b/lib.sh @@ -124,48 +124,67 @@ else fi } -purge_linux_package() { - # Identify which OS it is - if [ -z "${ID}" ] || [ -z "$OS" ] || [ -z "${UPSTREAM_ID}" ] +install_linux_package() { + # Install based on OS + # osInfo[/etc/redhat-release]=yum + # osInfo[/etc/arch-release]=pacman + # osInfo[/etc/gentoo-release]=emerge + # osInfo[/etc/SuSE-release]=zypp + # osInfo[/etc/debian_version]=apt-get + # osInfo[/etc/alpine-release]=apk + if [ -x "$(command -v apt-get)" ] then - identify_os - fi - # Purge based on OS - if [ "${ID}" = "debian" ] || [ "$OS" = "Ubuntu" ] || [ "$OS" = "Debian" ] || [ "${UPSTREAM_ID}" = "ubuntu" ] || [ "${UPSTREAM_ID}" = "debian" ] + sudo apt-get install "${1}" + elif [ -x "$(command -v apk)" ] + then + sudo apk add --no-cache "${1}" + elif [ -x "$(command -v dnf)" ] then - apt-get purge "${1}" -y - apt-get autoremove -y - elif [ "$OS" = "CentOS" ] || [ "$OS" = "RedHat" ] || [ "${UPSTREAM_ID}" = "rhel" ] || [ "${OS}" = "Almalinux" ] || [ "${UPSTREAM_ID}" = "Rocky*" ] + sudo dnf install "${1}" + elif [ -x "$(command -v zypper)" ] then - yum remove "${1}" -y - elif [ "${ID}" = "arch" ] || [ "${UPSTREAM_ID}" = "arch" ] + sudo zypper install "${1}" + elif [ -x "$(command -v pacman)" ] then - pacman -Rs "${1}" + sudo pacman -S install "${1}" + elif [ -x "$(command -v yum)" ] + then + sudo yum install "${1}" + elif [ -x "$(command -v emerge)" ] + then + sudo emerge -av "${1}" + else + echo "FAILED TO INSTALL ${1}! Package manager not found: Your OS is currently unsupported." fi } -install_linux_package() { - # Identify which OS it is - if [ -z "${ID}" ] || [ -z "$OS" ] || [ -z "${UPSTREAM_ID}" ] +purge_linux_package() { + if [ -x "$(command -v apt-get)" ] then - identify_os - fi - - # Install based on OS - if [ "${ID}" = "debian" ] || [ "$OS" = "Ubuntu" ] || [ "$OS" = "Debian" ] || [ "${UPSTREAM_ID}" = "ubuntu" ] || [ "${UPSTREAM_ID}" = "debian" ] + sudo apt-get purge --autoremove -y "${1}" + elif [ -x "$(command -v apk)" ] + then + sudo apk del "${1}" + elif [ -x "$(command -v dnf)" ] + then + sudo dnf purge "${1}" + elif [ -x "$(command -v zypper)" ] then - apt-get install "${1}" -y - elif [ "$OS" = "CentOS" ] || [ "$OS" = "RedHat" ] || [ "${UPSTREAM_ID}" = "rhel" ] || [ "${OS}" = "Almalinux" ] || [ "${UPSTREAM_ID}" = "Rocky*" ] + sudo zypper remove "${1}" + elif [ -x "$(command -v pacman)" ] then - yum install "${1}" -y - elif [ "${ID}" = "arch" ] || [ "${UPSTREAM_ID}" = "arch" ] + sudo pacman -Rs "${1}" + elif [ -x "$(command -v yum)" ] then - pacman -S install "${1}" + sudo yum remove "${1}" + elif [ -x "$(command -v emerge)" ] + then + sudo emerge -Cv "${1}" + else + echo "FAILED TO REMOVE ${1}! Package manager not found: Your OS is currently unsupported." fi } - - ## bash colors # Reset Color_Off='\e[0m' # Text Reset From 8d07bc0c119237852f767f649e17c6eccd978880 Mon Sep 17 00:00:00 2001 From: Daniel Hansson Date: Wed, 4 Oct 2023 20:13:13 +0200 Subject: [PATCH 14/14] add -y flag not sure about the other package managers. --- lib.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib.sh b/lib.sh index 93c5a53..68755ac 100644 --- a/lib.sh +++ b/lib.sh @@ -134,7 +134,7 @@ install_linux_package() { # osInfo[/etc/alpine-release]=apk if [ -x "$(command -v apt-get)" ] then - sudo apt-get install "${1}" + sudo apt-get install "${1}" -y elif [ -x "$(command -v apk)" ] then sudo apk add --no-cache "${1}"