From a36ac3ba1301e37b920969c2e1b5bedb4898a2b0 Mon Sep 17 00:00:00 2001 From: Daniel Hansson Date: Thu, 5 Oct 2023 15:00:02 +0200 Subject: [PATCH 1/7] [WIP] Consistency is key! This PR aims to make everything more consistent, and correct smaller errors/bugs. --- uninstall.sh | 86 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 55 insertions(+), 31 deletions(-) diff --git a/uninstall.sh b/uninstall.sh index e3360eb..5d7a30c 100644 --- a/uninstall.sh +++ b/uninstall.sh @@ -2,33 +2,59 @@ ################################################################################################################## -if [[ "$EUID" -ne 0 ]] +# Install curl and whiptail if needed +if [ ! -x "$(command -v curl)" ] || [ ! -x "$(command -v whiptail)" ] 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 - -# 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 + # We need curl to fetch the lib + # There are the package managers for different 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 + NEEDED_DEPS=(curl whiptail) + if [ -x "$(command -v apt-get)" ] + then + sudo apt-get install "${NEEDED_DEPS[@]}" -y + elif [ -x "$(command -v apk)" ] + then + sudo apk add --no-cache "${NEEDED_DEPS[@]}" + elif [ -x "$(command -v dnf)" ] + then + sudo dnf install "${NEEDED_DEPS[@]}" + elif [ -x "$(command -v zypper)" ] + then + sudo zypper install "${NEEDED_DEPS[@]}" + elif [ -x "$(command -v pacman)" ] + then + sudo pacman -S install "${NEEDED_DEPS[@]}" + elif [ -x "$(command -v yum)" ] + then + sudo yum install "${NEEDED_DEPS[@]}" + elif [ -x "$(command -v emerge)" ] + then + sudo emerge -av "${NEEDED_DEPS[@]}" + else + echo "FAILED TO INSTALL! Package manager not found. You must manually install:" "${NEEDED_DEPS[@]}" + exit 1 + fi fi +# We need to source directly from the Github repo to be able to use the functions here # shellcheck disable=2034,2059,2164 true -SCRIPT_NAME="Uninstall Script" +SCRIPT_NAME="Uninstall script" +export SCRIPT_NAME # shellcheck source=lib.sh -source lib.sh +source <(curl -sL https://raw.githubusercontent.com/rustdesk/rustdesk-server-pro/main/lib.sh) +# see https://github.com/koalaman/shellcheck/wiki/Directive +unset SCRIPT_NAME + +################################################################################################################## + +# Check if root +root_check # Output debugging info if $DEBUG set if [ "$DEBUG" = "true" ] @@ -40,7 +66,6 @@ then exit 0 fi - # Switch for Certbot if [ -d /etc/letsencrypt ] then @@ -53,7 +78,6 @@ 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:// linux package)" OFF \ "nginxconf" "(Removes Rustdesk Nginx config)" OFF \ "nginxall" "(Removes *everything* releated to Nginx)" ON \ "wget" "(Removes wget linux package)" ON \ @@ -65,12 +89,10 @@ $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 \ +"curl" "(Removes curl:// linux package)" OFF \ "Certbot" "(Removes Certbot package plus Let's Encrypt)" "$CERTBOT_SWITCH" 3>&1 1>&2 2>&3) case "$choice" in - *"curl"*) - REMOVE_CURL="yes" - ;;& *"nginxconf"*) REMOVE_NGINX_CONF="yes" ;;& @@ -104,6 +126,9 @@ case "$choice" in *"Rustdesk SERVER"*) REMOVE_RUSTDESK_SERVER="yes" ;;& + *"curl"*) + REMOVE_CURL="yes" + ;;& *"Certbot"*) REMOVE_CERTBOT="yes" ;;& @@ -113,7 +138,7 @@ esac msg_box "WARNING WARNING WARNING -This script will remove EVERYTHING that was you chose in the previous selection. +This script will remove EVERYTHING that was chosen 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?" @@ -134,8 +159,8 @@ then else ufw delete allow 21114/tcp fi - ufw disable - ufw reload + ufw --force disable + ufw --force reload fi # Rustdesk Server @@ -231,10 +256,9 @@ fi msg_box "Uninstallation complete! -Please hit OK to remove the last file." +Please hit OK to remove the last package." if [ -n "$REMOVE_WHIPTAIL" ] then purge_linux_package whiptail fi -rm -f lib.sh From e7b24d86eb686a62aa157ef8d3d871cc7cba086b Mon Sep 17 00:00:00 2001 From: Daniel Hansson Date: Thu, 5 Oct 2023 15:20:07 +0200 Subject: [PATCH 2/7] minor changes to install --- install.sh | 136 +++++++++++++++++++++++++++++------------------------ 1 file changed, 75 insertions(+), 61 deletions(-) diff --git a/install.sh b/install.sh index c9d1cb8..a3e5583 100644 --- a/install.sh +++ b/install.sh @@ -8,44 +8,50 @@ # 5. Create systemd services for hbbs and hbbr # 6. If you choose Domain, it will install Nginx and Certbot, allowing the API to be available on port 443 (https) and get an SSL certificate over port 80, it is automatically renewed +# Please note; even if the script is run as root, you will still be able to choose a non-root user during setup. + ################################################################################################################## -# We need curl to fetch the lib -# There are the package managers for different 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 -NEEDED_DEPS=(curl whiptail) -if [ -x "$(command -v apt-get)" ] +# Install curl and whiptail if needed +if [ ! -x "$(command -v curl)" ] || [ ! -x "$(command -v whiptail)" ] then - sudo apt-get install "${NEEDED_DEPS[@]}" -y -elif [ -x "$(command -v apk)" ] -then - sudo apk add --no-cache "${NEEDED_DEPS[@]}" -elif [ -x "$(command -v dnf)" ] -then - sudo dnf install "${NEEDED_DEPS[@]}" -elif [ -x "$(command -v zypper)" ] -then - sudo zypper install "${NEEDED_DEPS[@]}" -elif [ -x "$(command -v pacman)" ] -then - sudo pacman -S install "${NEEDED_DEPS[@]}" -elif [ -x "$(command -v yum)" ] -then - sudo yum install "${NEEDED_DEPS[@]}" -elif [ -x "$(command -v emerge)" ] -then - sudo emerge -av "${NEEDED_DEPS[@]}" -else - echo "FAILED TO INSTALL PACKAGE! Package manager not found. You must manually install:" "${NEEDED_DEPS[@]}" - exit 1 + # We need curl to fetch the lib + # There are the package managers for different 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 + NEEDED_DEPS=(curl whiptail) + echo "Installing these packages:" "${NEEDED_DEPS[@]}"... + if [ -x "$(command -v apt-get)" ] + then + sudo apt-get install "${NEEDED_DEPS[@]}" -y + elif [ -x "$(command -v apk)" ] + then + sudo apk add --no-cache "${NEEDED_DEPS[@]}" + elif [ -x "$(command -v dnf)" ] + then + sudo dnf install "${NEEDED_DEPS[@]}" + elif [ -x "$(command -v zypper)" ] + then + sudo zypper install "${NEEDED_DEPS[@]}" + elif [ -x "$(command -v pacman)" ] + then + sudo pacman -S install "${NEEDED_DEPS[@]}" + elif [ -x "$(command -v yum)" ] + then + sudo yum install "${NEEDED_DEPS[@]}" + elif [ -x "$(command -v emerge)" ] + then + sudo emerge -av "${NEEDED_DEPS[@]}" + else + echo "FAILED TO INSTALL! Package manager not found. You must manually install:" "${NEEDED_DEPS[@]}" + exit 1 + fi fi - # We need to source directly from the Github repo to be able to use the functions here # shellcheck disable=2034,2059,2164 true @@ -58,24 +64,32 @@ unset SCRIPT_NAME ################################################################################################################## -# This must run as root +# Check if root root_check +# 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 + # We need the WAN IP get_wanip4 -# Install needed dependencies -install_linux_package unzip -install_linux_package tar -install_linux_package dnsutils -install_linux_package ufw -if ! install_linux_package bind9-utils +# Automatic restart of services while installing +# Restart mode: (l)ist only, (i)nteractive or (a)utomatically. +if [ ! -f /etc/needrestart/needrestart.conf ] then - install_linux_package bind-utils -fi -if ! install_linux_package bind9 -then - install_linux_package bind + install_linux_package needrestart + if ! grep -rq "{restart} = 'a'" /etc/needrestart/needrestart.conf + then + # Restart mode: (l)ist only, (i)nteractive or (a)utomatically. + sed -i "s|#\$nrconf{restart} =.*|\$nrconf{restart} = 'a'\;|g" /etc/needrestart/needrestart.conf + fi fi # Select user for installation @@ -99,18 +113,20 @@ Please try again." run_as_non_root_user() { sudo -u "$RUSTDESK_USER" "$@"; } - - chown "$RUSTDESK_USER":"$RUSTDESK_USER" lib.sh fi -# Output debugging info if $DEBUG set -if [ "$DEBUG" = "true" ] +# Install needed dependencies +install_linux_package unzip +install_linux_package tar +install_linux_package dnsutils +install_linux_package ufw +if ! install_linux_package bind9-utils 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 + install_linux_package bind-utils +fi +if ! install_linux_package bind9 +then + install_linux_package bind fi # Setting up firewall @@ -374,7 +390,7 @@ Do you want to install Certbot with snap? (recommended)" install_linux_package nginx if ! install_linux_package snapd then - print_text_in_color "$IRed" "Sorry, snapd wasn't found on your system, reverting to python-certbot." + print_text_in_color "$IRed" "Sorry, snapd wasn't found on your system, using 'python3-certbot-nginx' instead." install_linux_package python3-certbot-nginx else snap install certbot --classic @@ -387,8 +403,6 @@ Do you want to install Certbot with snap? (recommended)" # Add Nginx config if [ ! -f "/etc/nginx/sites-available/rustdesk.conf" ] then - rm -f "/etc/nginx/sites-available/rustdesk.conf" - rm -f "/etc/nginx/sites-enabled/rustdesk.conf" touch "/etc/nginx/sites-available/rustdesk.conf" cat << NGINX_RUSTDESK_CONF > "/etc/nginx/sites-available/rustdesk.conf" server { @@ -415,8 +429,8 @@ NGINX_RUSTDESK_CONF # Enable firewall rules for the domain ufw allow 80/tcp ufw allow 443/tcp - ufw enable - ufw reload + ufw --force enable + ufw --force reload # Generate the certifictae if ! certbot --nginx --cert-name "${RUSTDESK_DOMAIN}" --key-type ecdsa --renew-by-default --no-eff-email --agree-tos --server https://acme-v02.api.letsencrypt.org/directory -d "${RUSTDESK_DOMAIN}" @@ -430,8 +444,8 @@ Please try again." ;; "IP") ufw allow 21114/tcp - ufw enable - ufw reload + ufw --force enable + ufw --force reload ;; *) ;; From 3aa88d0c12c6c5456322358ad5aba500de81c3f0 Mon Sep 17 00:00:00 2001 From: Daniel Hansson Date: Thu, 5 Oct 2023 15:20:38 +0200 Subject: [PATCH 3/7] details... --- uninstall.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/uninstall.sh b/uninstall.sh index 5d7a30c..94a8292 100644 --- a/uninstall.sh +++ b/uninstall.sh @@ -14,6 +14,7 @@ then # osInfo[/etc/debian_version]=apt-get # osInfo[/etc/alpine-release]=apk NEEDED_DEPS=(curl whiptail) + echo "Installing" "${NEEDED_DEPS[@]}"... if [ -x "$(command -v apt-get)" ] then sudo apt-get install "${NEEDED_DEPS[@]}" -y From 242f37d7b732f7bd8b76b740b42692fae7e70763 Mon Sep 17 00:00:00 2001 From: Daniel Hansson Date: Thu, 5 Oct 2023 15:32:50 +0200 Subject: [PATCH 4/7] consistent in lib as well --- lib.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib.sh b/lib.sh index a9a8f94..da1ee0a 100644 --- a/lib.sh +++ b/lib.sh @@ -159,6 +159,7 @@ install_linux_package() { # osInfo[/etc/SuSE-release]=zypp # osInfo[/etc/debian_version]=apt-get # osInfo[/etc/alpine-release]=apk + print_text_in_color "$IGreen" Installing "${1}"... if [ -x "$(command -v apt-get)" ] then sudo apt-get install "${1}" -y @@ -181,7 +182,7 @@ install_linux_package() { then sudo emerge -av "${1}" else - echo "FAILED TO INSTALL ${1}! Package manager not found: Your OS is currently unsupported." + print_text_in_color "$IRed" "FAILED TO INSTALL ${1}! Package manager not found: Your OS is currently unsupported." fi } @@ -208,7 +209,7 @@ purge_linux_package() { then sudo emerge -Cv "${1}" else - echo "FAILED TO REMOVE ${1}! Package manager not found: Your OS is currently unsupported." + print_text_in_color "$IRed" "FAILED TO REMOVE ${1}! Package manager not found: Your OS is currently unsupported." fi } From c0f5c1b6ba10fe2e00139ccf21da3eb29d851bdf Mon Sep 17 00:00:00 2001 From: Daniel Hansson Date: Thu, 5 Oct 2023 15:35:38 +0200 Subject: [PATCH 5/7] SC --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index a3e5583..c88d5ea 100644 --- a/install.sh +++ b/install.sh @@ -24,7 +24,7 @@ then # osInfo[/etc/debian_version]=apt-get # osInfo[/etc/alpine-release]=apk NEEDED_DEPS=(curl whiptail) - echo "Installing these packages:" "${NEEDED_DEPS[@]}"... + echo "Installing these packages:" "${NEEDED_DEPS[@]}" if [ -x "$(command -v apt-get)" ] then sudo apt-get install "${NEEDED_DEPS[@]}" -y From b223b25d4df13bcce661fac68b27d7d5ecab561c Mon Sep 17 00:00:00 2001 From: Daniel Hansson Date: Thu, 5 Oct 2023 15:36:10 +0200 Subject: [PATCH 6/7] SC --- uninstall.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uninstall.sh b/uninstall.sh index 94a8292..ad24bbc 100644 --- a/uninstall.sh +++ b/uninstall.sh @@ -14,7 +14,7 @@ then # osInfo[/etc/debian_version]=apt-get # osInfo[/etc/alpine-release]=apk NEEDED_DEPS=(curl whiptail) - echo "Installing" "${NEEDED_DEPS[@]}"... + echo "Installing" "${NEEDED_DEPS[@]}" if [ -x "$(command -v apt-get)" ] then sudo apt-get install "${NEEDED_DEPS[@]}" -y From afefb3485048ff5bb6774c5ff43ff0e1108341a7 Mon Sep 17 00:00:00 2001 From: Daniel Hansson Date: Thu, 5 Oct 2023 15:52:35 +0200 Subject: [PATCH 7/7] move " to correct place --- install.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/install.sh b/install.sh index c88d5ea..1c7505d 100644 --- a/install.sh +++ b/install.sh @@ -460,8 +460,8 @@ $PUBLICKEY Your DNS Address is: $RUSTDESK_DOMAIN -Please login at https://$RUSTDESK_DOMAIN" -Default User/Pass: admin/test1234 +Please login at https://$RUSTDESK_DOMAIN +Default User/Pass: admin/test1234" else msg_box " Your Public Key is: @@ -469,8 +469,8 @@ $PUBLICKEY Your IP Address is: $WANIP4 -Please login at http://$WANIP4:21114" -Default User/Pass: admin/test1234 +Please login at http://$WANIP4:21114 +Default User/Pass: admin/test1234" fi print_text_in_color "$IGreen" "Cleaning up..."