From 50dcbccef93622cf097db5a0dfadc0bc4827a77a Mon Sep 17 00:00:00 2001 From: Daniel Hansson Date: Tue, 3 Oct 2023 22:24:57 +0200 Subject: [PATCH 1/7] Improve further Fix https://github.com/rustdesk/rustdesk-server-pro/issues/107 --- install.sh | 146 +++++++++++++++++++++++++---------------------------- 1 file changed, 70 insertions(+), 76 deletions(-) diff --git a/install.sh b/install.sh index ed01d3d..2543e76 100644 --- a/install.sh +++ b/install.sh @@ -1,6 +1,6 @@ #!/bin/bash -# shellcheck disable=SC2034 +# shellcheck disable=2034,2059,2164 true # see https://github.com/koalaman/shellcheck/wiki/Directive @@ -12,35 +12,23 @@ true # 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 -# Download the lib file -if ! curl -fSL --retry 3 https://raw.githubusercontent.com/rustdesk/rustdesk-server-pro/main/lib.sh -o /tmp/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 /tmp/lib.sh +################################################################################################################## if [[ "$EUID" -ne 0 ]] then - msg_box "Sorry, you are not root. You now have two options: - -1. Use SUDO directly: - a) :~$ sudo bash install.sh - -2. Become ROOT and then type your command: - a) :~$ sudo -i - b) :~# bash install.sh - -More information can be found here: https://unix.stackexchange.com/a/3064" + 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 -ARCH=$(uname -m) - # Identify OS if [ -f /etc/os-release ] then @@ -90,10 +78,51 @@ else VER=$(uname -r) fi +# Setup prereqs for server +# Common named prereqs +PREREQ=(curl wget unzip tar whiptail) +PREREQDEB=(dnsutils ufw) +PREREQRPM=(bind-utils) +PREREQARCH=(bind) + +echo "Installing prerequisites" +if [ "${ID}" = "debian" ] || [ "$OS" = "Ubuntu" ] || [ "$OS" = "Debian" ] || [ "${UPSTREAM_ID}" = "ubuntu" ] || [ "${UPSTREAM_ID}" = "debian" ] +then + apt-get update + apt-get install -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 update -y + yum install -y "${PREREQ[@]}" "${PREREQRPM[@]}" # git +elif [ "${ID}" = "arch" ] || [ "${UPSTREAM_ID}" = "arch" ] +then + pacman -Syu + pacman -S "${PREREQ[@]}" "${PREREQARCH[@]}" +else + echo "Unsupported OS!" + # Here you could ask the user for permission to try and install anyway + # If they say yes, then do the install + # If they say no, exit the script + 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 +fi + # shellcheck disable=2034,2059,2164 true # shellcheck source=lib.sh -source /tmp/lib.sh +source lib.sh + +ARCH=$(uname -m) +TITLE="RustDesk Linux installer" # Select user for installation msg_box "Rustdesk needs to be installed as root, but you can still do some parts as an unprivileged user. @@ -116,6 +145,8 @@ 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 @@ -127,42 +158,10 @@ then exit 0 fi -# Setup prereqs for server -# Common named prereqs -PREREQ=(curl wget unzip tar whiptail) -PREREQDEB=(dnsutils ufw) -PREREQRPM=(bind-utils) -PREREQARCH=(bind) - -print_text_in_color "$IGreen" "Installing prerequisites" -if [ "${ID}" = "debian" ] || [ "$OS" = "Ubuntu" ] || [ "$OS" = "Debian" ] || [ "${UPSTREAM_ID}" = "ubuntu" ] || [ "${UPSTREAM_ID}" = "debian" ] -then - apt-get update - apt-get install -y "${PREREQ[@]}" "${PREREQDEB[@]}" # git -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 update -y - yum install -y "${PREREQ[@]}" "${PREREQRPM[@]}" # git -elif [ "${ID}" = "arch" ] || [ "${UPSTREAM_ID}" = "arch" ] -then - pacman -Syu - pacman -S "${PREREQ[@]}" "${PREREQARCH[@]}" -else - print_text_in_color "$IRed" "Unsupported OS" - # Here you could ask the user for permission to try and install anyway - # If they say yes, then do the install - # If they say no, exit the script - exit 1 -fi - # Setting up firewall ufw allow 21115:21119/tcp ufw allow 22/tcp ufw allow 21116/udp -ufw enable # Download latest version of RustDesk RDLATEST=$(curl https://api.github.com/repos/rustdesk/rustdesk-server-pro/releases/latest -s | grep "tag_name"| awk '{print substr($2, 2, length($2)-3) }') @@ -250,11 +249,8 @@ then fi # Setup systemd to launch hbbs -if [ -f "/etc/systemd/system/rustdesk-hbbs.service" ] +if [ ! -f "/etc/systemd/system/rustdesk-hbbs.service" ] then - systemctl stop rustdesk-hbbs.service - rm -f "/etc/systemd/system/rustdesk-hbbs.service" - systemctl daemon-reload touch "/etc/systemd/system/rustdesk-hbbs.service" if [ -n "$RUSTDESK_USER" ] then @@ -297,16 +293,10 @@ WantedBy=multi-user.target HBBS_RUSTDESK_SERVICE fi fi -systemctl daemon-reload -systemctl enable rustdesk-hbbs.service -systemctl start rustdesk-hbbs.service # Setup systemd to launch hbbr -if [ -f "/etc/systemd/system/rustdesk-hbbr.service" ] +if [ ! -f "/etc/systemd/system/rustdesk-hbbr.service" ] then - systemctl stop rustdesk-hbbs.service - rm -f "/etc/systemd/system/rustdesk-hbbr.service" - systemctl daemon-reload touch "/etc/systemd/system/rustdesk-hbbr.service" if [ -n "$RUSTDESK_USER" ] then @@ -349,9 +339,14 @@ WantedBy=multi-user.target HBBR_RUSTDESK_SERVICE fi fi -systemctl daemon-reload + +# Enable services +# HBBR systemctl enable rustdesk-hbbr.service systemctl start rustdesk-hbbr.service +# HBBS +systemctl enable rustdesk-hbbs.service +systemctl start rustdesk-hbbs.service while : do @@ -378,12 +373,6 @@ do fi done -echo "Tidying up install" -rm -f rustdesk-server-linux-"${ACTUAL_TAR_NAME}".zip -rm -rf "${ACTUAL_TAR_NAME}" - - - choice=$(whiptail --title "Rustdesk installation script" --menu \ "Choose your preferred option, IP or DNS/Domain: @@ -524,5 +513,10 @@ $PUBLICKEY Your IP Address is: $WANIP4 -Please login at http://$WANIP4" +Please login at http://$WANIP4:21114" fi + +print_text_in_color "$IGreen" "Cleaning up..." +rm -f rustdesk-server-linux-"${ACTUAL_TAR_NAME}".zip +rm -rf "${ACTUAL_TAR_NAME}" +rm -f lib.sh From 23d9d936ad01b4a7427a1395edbb5077a0ad0306 Mon Sep 17 00:00:00 2001 From: Daniel Hansson Date: Tue, 3 Oct 2023 22:25:55 +0200 Subject: [PATCH 2/7] add more vars to lib --- lib.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib.sh b/lib.sh index b416c3a..6b6e75f 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 From efa485173fc79342614b2af94b74e6d8eca42fa3 Mon Sep 17 00:00:00 2001 From: Daniel Hansson Date: Tue, 3 Oct 2023 22:26:20 +0200 Subject: [PATCH 3/7] remove from main script --- install.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/install.sh b/install.sh index 2543e76..62389df 100644 --- a/install.sh +++ b/install.sh @@ -121,9 +121,6 @@ true # shellcheck source=lib.sh source lib.sh -ARCH=$(uname -m) -TITLE="RustDesk Linux installer" - # Select user for installation msg_box "Rustdesk needs to be installed as root, but you can still do some parts as an unprivileged user. Running with an unprivileged user enhances security, and is recommended." From 3f039cb5029d77d4b03c9f2b97a887c7303eaab0 Mon Sep 17 00:00:00 2001 From: Daniel Hansson Date: Tue, 3 Oct 2023 22:36:15 +0200 Subject: [PATCH 4/7] intendent correctly --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 62389df..fda49d2 100644 --- a/install.sh +++ b/install.sh @@ -19,7 +19,7 @@ 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 " a) :~$ sudo bash install.sh" echo echo "2. Become ROOT and then type your command:" echo " a) :~$ sudo -i" From eaceefd8bbe3922ddb2f7ee0dc85945427a953e0 Mon Sep 17 00:00:00 2001 From: Daniel Hansson Date: Tue, 3 Oct 2023 22:39:09 +0200 Subject: [PATCH 5/7] typo --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index fda49d2..4384962 100644 --- a/install.sh +++ b/install.sh @@ -364,7 +364,7 @@ do print_text_in_color "$ICyan" "Checking if public key is generated..." sleep 5 else - print_text_in_color "$IGreen" "Pubilc key path: $PUBKEYNAME" + print_text_in_color "$IGreen" "Public key path: $PUBKEYNAME" PUBLICKEY=$(cat "$PUBKEYNAME") break fi From 04369b60db74ab6dc88527edfca458991d3d5a9c Mon Sep 17 00:00:00 2001 From: Daniel Hansson Date: Tue, 3 Oct 2023 22:40:49 +0200 Subject: [PATCH 6/7] add default user pass --- install.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/install.sh b/install.sh index 4384962..c89560d 100644 --- a/install.sh +++ b/install.sh @@ -503,6 +503,7 @@ Your DNS Address is: $RUSTDESK_DOMAIN Please login at https://$RUSTDESK_DOMAIN" +Default User/Pass: admin/test1234 else msg_box " Your Public Key is: @@ -511,6 +512,7 @@ Your IP Address is: $WANIP4 Please login at http://$WANIP4:21114" +Default User/Pass: admin/test1234 fi print_text_in_color "$IGreen" "Cleaning up..." From d12bc5f9669b2ab4d9d494ae9d8e37c0c4c1055f Mon Sep 17 00:00:00 2001 From: Daniel Hansson Date: Tue, 3 Oct 2023 22:56:53 +0200 Subject: [PATCH 7/7] wording --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index c89560d..d4fbc15 100644 --- a/install.sh +++ b/install.sh @@ -435,7 +435,7 @@ Do you want to install Certbot with snap? (recommended)" pacman -S install python3-certbot-nginx else msg_box "Sorry, your OS is unsupported" - if ! yesno_box_no "It might work anyway though... Do you want to continue anyway?" + if ! yesno_box_no "It might work anyway though... Do you want to give it a shot?" then exit 1 fi