From 4f9c175355c6137a07b04d1434dfb97e54e69466 Mon Sep 17 00:00:00 2001 From: Phil Clifford Date: Thu, 11 Aug 2022 17:42:28 +0100 Subject: [PATCH] A few suggestions that might help improve/extend OS detection/support install more of the dependencies - curl and wget were missing --- install.sh | 97 ++++++++++++++++++++++++++++++++++++------- linuxclientinstall.sh | 65 ++++++++++++++++++++++++----- update.sh | 60 ++++++++++++++++++++++---- 3 files changed, 188 insertions(+), 34 deletions(-) diff --git a/install.sh b/install.sh index 35c04e0..9be99f8 100644 --- a/install.sh +++ b/install.sh @@ -17,26 +17,95 @@ break "DNS/Domain") echo -ne "Enter your preferred domain/dns address ${NC}: " read wanip +#check wanip is valid domain +if ! [[ $wanip =~ ^[a-zA-Z0-9]+([a-zA-Z0-9.-]*[a-zA-Z0-9]+)?$ ]]; then + echo -e "${RED}Invalid domain/dns address${NC}" + exit 1 +fi break ;; *) echo "invalid option $REPLY";; esac done -# Setup prereqs for server -if [[ $(which yum) ]]; then - sudo yum install unzip -y - sudo yum install bind-utils -y - sudo yum install tar -y -elif [[ $(which apt) ]]; then - sudo apt-get update - sudo apt-get install unzip -y - sudo apt-get install dnsutils -y - sudo apt-get install tar -y +# identify OS +if [ -f /etc/os-release ]; then + # freedesktop.org and systemd + . /etc/os-release + OS=$NAME + VER=$VERSION_ID + IDLIKE=$ID_LIKE +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 + . /etc/lsb-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 - echo "Unknown Platform, the install might fail" + # 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="curl wget unzip tar" +echo "Installing prerequisites" +if [ "$OS" = "Ubuntu" ] || [ "$OS" = "Debian" ]; then + prereq+=" dnsutils" + apt-get update + apt-get install -y "${prereq}" # git +elif [ "$OS" = "CentOS" ] || [ "$OS" = "RedHat" ]; then + prereq+=" bind-utils" + yum update -y + yum install -y "${prereq}" # git +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 + +# #/* +# Alternatively since case is faster than if then else +# case ${IDLIKE} in +# ubuntu|debian) +# # Debian/Ubuntu/etc. +# sudo apt-get update +# sudo apt-get install -y curl wget unzip dnsutils tar # git +# ;; +# centos|fedora|redhat) #|amazon) +# # CentOS/RedHat/Fedora/Amazon/etc. +# sudo yum update -y +# sudo yum install -y curl wget unzip bind-utils tar # git +# ;; +# *) +# echo "Unsupported OS" +# echo "Unknown Platform, the install might fail" +# # 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 +# ;; +# esac +# */ + # Make Folder /opt/rustdesk/ if [ ! -d "/opt/rustdesk" ]; then echo "Creating /opt/rustdesk" @@ -116,14 +185,14 @@ done pubname=$(find /opt/rustdesk -name *.pub) key=$(cat "${pubname}") -sudo rm rustdesk-server-linux-x64.zip +rm rustdesk-server-linux-x64.zip -# Create windows install script +# Create windows install script wget https://raw.githubusercontent.com/dinger1986/rustdeskinstall/master/WindowsAgentAIOInstall.ps1 sudo sed -i "s|wanipreg|${wanip}|g" WindowsAgentAIOInstall.ps1 sudo sed -i "s|keyreg|${key}|g" WindowsAgentAIOInstall.ps1 -# Create linux install script +# Create linux install script wget https://raw.githubusercontent.com/dinger1986/rustdeskinstall/master/linuxclientinstall.sh sudo sed -i "s|wanipreg|${wanip}|g" linuxclientinstall.sh sudo sed -i "s|keyreg|${key}|g" linuxclientinstall.sh diff --git a/linuxclientinstall.sh b/linuxclientinstall.sh index 386d1e3..a0f2d0d 100644 --- a/linuxclientinstall.sh +++ b/linuxclientinstall.sh @@ -3,17 +3,60 @@ uname=$(whoami) admintoken=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c8) -# Install Rustdesk -if [[ $(which yum) ]]; then - wget https://github.com/rustdesk/rustdesk/releases/download/1.1.9/rustdesk-1.1.9.rpm - sudo yum localinstall ./rustdesk-1.1.9.rpm -elif [[ $(which apt) ]]; then - wget https://github.com/rustdesk/rustdesk/releases/download/1.1.9/rustdesk-1.1.9.deb - sudo apt install -fy ./rustdesk-1.1.9.deb + +# identify OS +if [ -f /etc/os-release ]; then + # freedesktop.org and systemd + . /etc/os-release + OS=$NAME + VER=$VERSION_ID + IDLIKE=$ID_LIKE +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 + . /etc/lsb-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 - echo "Unknown Platform, the install will fail" - exit -fi + # Fall back to uname, e.g. "Linux ", also works for BSD, etc. + OS=$(uname -s) + VER=$(uname -r) + +# Install Rustdesk +case ${OS,,} in + # or case ${IDLIKE,,} in .. to support derivatives + ubuntu|debian) + # Debian/Ubuntu/etc. + wget https://github.com/rustdesk/rustdesk/releases/download/1.1.9/rustdesk-1.1.9.deb + sudo apt install -fy ./rustdesk-1.1.9.deb + ;; + fedora|centos|redhat|amazon) + # Red Hat, CentOS, etc. + + wget https://github.com/rustdesk/rustdesk/releases/download/1.1.9/rustdesk-1.1.9.rpm + sudo yum localinstall ./rustdesk-1.1.9.rpm + # sudo dnf install -y ./rustdesk-1.1.9.rpm + ;; + *) + echo "Unsupported OS" + exit 1 + ;; +esac rustdesk --password ${admintoken} pkill -f "rustdesk" @@ -50,7 +93,7 @@ EOF )" echo "${rustdesktoml2b}" | sudo tee /root/.config/rustdesk/RustDesk2.toml > /dev/null -chown ${uname}:${uname} /home/${uname}/.config/rustdesk/RustDesk2.toml +chown ${uname}:${uname} /home/${uname}/.config/rustdesk/RustDesk2.toml systemctl restart rustdesk diff --git a/update.sh b/update.sh index cdccefb..88f1f22 100644 --- a/update.sh +++ b/update.sh @@ -8,16 +8,58 @@ sudo systemctl stop rustdesksignal.service sudo systemctl stop rustdeskrelay.service -# Setup prereqs for server -if [[ $(which yum) ]]; then - sudo yum install unzip -y - sudo yum install bind-utils -y -elif [[ $(which apt) ]]; then - sudo apt-get update - sudo apt-get install unzip -y - sudo apt-get install dnsutils -y +# identify OS +if [ -f /etc/os-release ]; then + # freedesktop.org and systemd + . /etc/os-release + OS=$NAME + VER=$VERSION_ID + IDLIKE=$ID_LIKE +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 + . /etc/lsb-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 - echo "Unknown Platform, the install might fail" + # 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="curl wget unzip tar" +echo "Installing prerequisites" +if [ "$OS" = "Ubuntu" ] || [ "$OS" = "Debian" ]; then + prereq+=" dnsutils" + apt-get update + apt-get install -y "${prereq}" # git +elif [ "$OS" = "CentOS" ] || [ "$OS" = "RedHat" ]; then + prereq+=" bind-utils" + yum update -y + yum install -y "${prereq}" # git +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 cd /opt/rustdesk/