Merge pull request #108 from enoch85/patch-1

Improve further
This commit is contained in:
RustDesk
2023-10-04 13:41:59 +08:00
committed by GitHub
2 changed files with 73 additions and 79 deletions

View File

@@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
# shellcheck disable=SC2034 # shellcheck disable=2034,2059,2164
true true
# see https://github.com/koalaman/shellcheck/wiki/Directive # see https://github.com/koalaman/shellcheck/wiki/Directive
@@ -12,35 +12,23 @@ true
# 5. Create systemd services for hbbs and hbbr # 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 # 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 ]] if [[ "$EUID" -ne 0 ]]
then then
msg_box "Sorry, you are not root. You now have two options: echo "Sorry, you are not root. You now have two options:"
echo
1. Use SUDO directly: echo "1. Use SUDO directly:"
a) :~$ sudo bash install.sh echo " a) :~$ sudo bash install.sh"
echo
2. Become ROOT and then type your command: echo "2. Become ROOT and then type your command:"
a) :~$ sudo -i echo " a) :~$ sudo -i"
b) :~# bash install.sh echo " b) :~# bash install.sh"
echo
More information can be found here: https://unix.stackexchange.com/a/3064" echo "More information can be found here: https://unix.stackexchange.com/a/3064"
exit 1 exit 1
fi fi
ARCH=$(uname -m)
# Identify OS # Identify OS
if [ -f /etc/os-release ] if [ -f /etc/os-release ]
then then
@@ -90,10 +78,48 @@ else
VER=$(uname -r) VER=$(uname -r)
fi 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 # shellcheck disable=2034,2059,2164
true true
# shellcheck source=lib.sh # shellcheck source=lib.sh
source /tmp/lib.sh source lib.sh
# Select user for installation # Select user for installation
msg_box "Rustdesk needs to be installed as root, but you can still do some parts as an unprivileged user. msg_box "Rustdesk needs to be installed as root, but you can still do some parts as an unprivileged user.
@@ -116,6 +142,8 @@ Please try again."
run_as_non_root_user() { run_as_non_root_user() {
sudo -u "$RUSTDESK_USER" "$@"; sudo -u "$RUSTDESK_USER" "$@";
} }
chown "$RUSTDESK_USER":"$RUSTDESK_USER" lib.sh
fi fi
# Output debugging info if $DEBUG set # Output debugging info if $DEBUG set
@@ -127,42 +155,10 @@ then
exit 0 exit 0
fi 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 # Setting up firewall
ufw allow 21115:21119/tcp ufw allow 21115:21119/tcp
ufw allow 22/tcp ufw allow 22/tcp
ufw allow 21116/udp ufw allow 21116/udp
ufw enable
# Download latest version of RustDesk # 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) }') 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 +246,8 @@ then
fi fi
# Setup systemd to launch hbbs # Setup systemd to launch hbbs
if [ -f "/etc/systemd/system/rustdesk-hbbs.service" ] if [ ! -f "/etc/systemd/system/rustdesk-hbbs.service" ]
then then
systemctl stop rustdesk-hbbs.service
rm -f "/etc/systemd/system/rustdesk-hbbs.service"
systemctl daemon-reload
touch "/etc/systemd/system/rustdesk-hbbs.service" touch "/etc/systemd/system/rustdesk-hbbs.service"
if [ -n "$RUSTDESK_USER" ] if [ -n "$RUSTDESK_USER" ]
then then
@@ -297,16 +290,10 @@ WantedBy=multi-user.target
HBBS_RUSTDESK_SERVICE HBBS_RUSTDESK_SERVICE
fi fi
fi fi
systemctl daemon-reload
systemctl enable rustdesk-hbbs.service
systemctl start rustdesk-hbbs.service
# Setup systemd to launch hbbr # Setup systemd to launch hbbr
if [ -f "/etc/systemd/system/rustdesk-hbbr.service" ] if [ ! -f "/etc/systemd/system/rustdesk-hbbr.service" ]
then then
systemctl stop rustdesk-hbbs.service
rm -f "/etc/systemd/system/rustdesk-hbbr.service"
systemctl daemon-reload
touch "/etc/systemd/system/rustdesk-hbbr.service" touch "/etc/systemd/system/rustdesk-hbbr.service"
if [ -n "$RUSTDESK_USER" ] if [ -n "$RUSTDESK_USER" ]
then then
@@ -349,9 +336,14 @@ WantedBy=multi-user.target
HBBR_RUSTDESK_SERVICE HBBR_RUSTDESK_SERVICE
fi fi
fi fi
systemctl daemon-reload
# Enable services
# HBBR
systemctl enable rustdesk-hbbr.service systemctl enable rustdesk-hbbr.service
systemctl start rustdesk-hbbr.service systemctl start rustdesk-hbbr.service
# HBBS
systemctl enable rustdesk-hbbs.service
systemctl start rustdesk-hbbs.service
while : while :
do do
@@ -372,18 +364,12 @@ do
print_text_in_color "$ICyan" "Checking if public key is generated..." print_text_in_color "$ICyan" "Checking if public key is generated..."
sleep 5 sleep 5
else else
print_text_in_color "$IGreen" "Pubilc key path: $PUBKEYNAME" print_text_in_color "$IGreen" "Public key path: $PUBKEYNAME"
PUBLICKEY=$(cat "$PUBKEYNAME") PUBLICKEY=$(cat "$PUBKEYNAME")
break break
fi fi
done 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 \ choice=$(whiptail --title "Rustdesk installation script" --menu \
"Choose your preferred option, IP or DNS/Domain: "Choose your preferred option, IP or DNS/Domain:
@@ -449,7 +435,7 @@ Do you want to install Certbot with snap? (recommended)"
pacman -S install python3-certbot-nginx pacman -S install python3-certbot-nginx
else else
msg_box "Sorry, your OS is unsupported" 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 then
exit 1 exit 1
fi fi
@@ -517,6 +503,7 @@ Your DNS Address is:
$RUSTDESK_DOMAIN $RUSTDESK_DOMAIN
Please login at https://$RUSTDESK_DOMAIN" Please login at https://$RUSTDESK_DOMAIN"
Default User/Pass: admin/test1234
else else
msg_box " msg_box "
Your Public Key is: Your Public Key is:
@@ -524,5 +511,11 @@ $PUBLICKEY
Your IP Address is: Your IP Address is:
$WANIP4 $WANIP4
Please login at http://$WANIP4" Please login at http://$WANIP4:21114"
Default User/Pass: admin/test1234
fi 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

3
lib.sh
View File

@@ -8,7 +8,8 @@ true
RUSTDESK_INSTALL_DIR=/var/lib/rustdesk-server RUSTDESK_INSTALL_DIR=/var/lib/rustdesk-server
RUSTDESK_LOG_DIR=/var/log/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) WANIP4=$(curl -s -k -m 5 -4 https://api64.ipify.org)
############ Functions ############ Functions