Created
July 2, 2026 17:06
-
-
Save hintoz/e344cec9689531c0eccb04c4f9c83324 to your computer and use it in GitHub Desktop.
A modified script for downloading and installing the latest version of RustDesk for Linux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Assign a random value to the password variable | |
| rustdesk_pw=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1) | |
| # Get your config string from your Web portal and Fill Below | |
| rustdesk_cfg="configstring" | |
| ################################## Please Do Not Edit Below This Line ######################################### | |
| # Check if the script is being run as root | |
| if [ "$(id -u)" -ne 0 ]; then | |
| echo "Root permissions are requested to install RustDesk..." | |
| # If the script is run via curl | bash | |
| if [ "$0" = "bash" ] || [ ! -f "$0" ]; then | |
| exec sudo bash -c "$(cat)" "$@" | |
| else | |
| # If the script is saved as a file | |
| exec sudo bash "$0" "$@" | |
| fi | |
| fi | |
| # Identify OS | |
| if [ -f /etc/os-release ]; then | |
| # freedesktop.org and systemd | |
| . /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 | |
| . /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 | |
| # Fall back to uname, e.g. "Linux <version>", also works for BSD, etc. | |
| OS=$(uname -s) | |
| VER=$(uname -r) | |
| fi | |
| ARCH=$(arch) | |
| if [[ "$ARCH" == "x86_64" ]]; then | |
| DEB_PATTERN="rustdesk-[0-9.]+-x86_64\.deb" | |
| RPM_PATTERN="rustdesk-[0-9.]+(-\d+)?\.x86_64\.rpm" | |
| elif [[ "$ARCH" == "aarch64" || "$ARCH" == "arm64" ]]; then | |
| DEB_PATTERN="rustdesk-[0-9.]+-aarch64\.deb" | |
| RPM_PATTERN="rustdesk-[0-9.]+(-\d+)?\.aarch64\.rpm" | |
| else | |
| echo "Error: The $ARCH architecture is not supported." | |
| exit 1 | |
| fi | |
| # Check version | |
| RELEASE_PAGE=$(curl -sL https://github.com/rustdesk/rustdesk/releases/latest) | |
| LATEST_VERSION=$(echo "$RELEASE_PAGE" | grep -Eo "releases/tag/[0-9.]+" | head -n 1 | sed 's|releases/tag/||') | |
| if [ -z "$LATEST_VERSION" ]; then | |
| echo "Error: The latest version of RustDesk could not be identified from GitHub." | |
| exit 1 | |
| fi | |
| INSTALLED_VERSION="" | |
| IS_NEW_INSTALL="false" | |
| if command -v dpkg-query &> /dev/null; then | |
| # Debian, Ubuntu | |
| INSTALLED_VERSION=$(dpkg-query -W -f='${Version}' rustdesk 2>/dev/null) | |
| elif command -v rpm &> /dev/null; then | |
| # CentOS, RedHat, Fedora, Rocky, Alma | |
| INSTALLED_VERSION=$(rpm -q --queryformat '%{VERSION}' rustdesk 2>/dev/null) | |
| fi | |
| if [ -n "$INSTALLED_VERSION" ]; then | |
| INSTALLED_VERSION_CLEAN=$(echo "$INSTALLED_VERSION" | grep -Eo "^[0-9.]+") | |
| if [ "$INSTALLED_VERSION_CLEAN" = "$LATEST_VERSION" ]; then | |
| echo "RustDesk is already installed with the current version ($INSTALLED_VERSION). No update is required." | |
| exit 0 | |
| else | |
| echo "The installed RustDesk version of $INSTALLED_VERSION was found. An upgrade to $LATEST_VERSION is available." | |
| fi | |
| else | |
| echo "RustDesk was not found in the system. Starting the installation $LATEST_VERSION version..." | |
| IS_NEW_INSTALL="true" | |
| fi | |
| # Install RustDesk | |
| echo "Installing RustDesk..." | |
| if [ "${ID}" = "debian" ] || [ "$OS" = "Ubuntu" ] || [ "$OS" = "Debian" ] || [ "${UPSTREAM_ID}" = "ubuntu" ] || [ "${UPSTREAM_ID}" = "debian" ]; then | |
| rd_link=$(echo "$RELEASE_PAGE" | grep -Eo "(http|https)://[a-zA-Z0-9./?=_-]*/$DEB_PATTERN" | head -n 1) | |
| deb_file=$(echo "$rd_link" | grep -Eo "$DEB_PATTERN") | |
| if [ -z "$rd_link" ]; then echo "The DEB package could not be found"; exit 1; fi | |
| wget -q "$rd_link" -O "$deb_file" | |
| apt-get install -fy "./$deb_file" > /dev/null | |
| rm -f "$deb_file" | |
| elif [ "$OS" = "CentOS" ] || [ "$OS" = "RedHat" ] || [ "$OS" = "Fedora Linux" ] || [ "${UPSTREAM_ID}" = "rhel" ] || [ "$OS" = "Almalinux" ] || [[ "$OS" == Rocky* ]] ; then | |
| rd_link=$(echo "$RELEASE_PAGE" | grep -Eo "(http|https)://[a-zA-Z0-9./?=_-]*/$RPM_PATTERN" | head -n 1) | |
| rpm_file=$(echo "$rd_link" | grep -Eo "$RPM_PATTERN") | |
| if [ -z "$rd_link" ]; then echo "The RPM package could not be found"; exit 1; fi | |
| wget -q "$rd_link" -O "$rpm_file" | |
| # We use dnf, if available, otherwise yum | |
| if command -v dnf &> /dev/null; then | |
| dnf localinstall "./$rpm_file" -y > /dev/null | |
| else | |
| yum localinstall "./$rpm_file" -y > /dev/null | |
| fi | |
| rm -f "$rpm_file" | |
| 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 | |
| # Run the rustdesk command with --get-id and store the output in the rustdesk_id variable | |
| rustdesk_id=$(rustdesk --get-id) | |
| # Apply new password to RustDesk | |
| if [ "$IS_NEW_INSTALL" = "true" ]; then | |
| rustdesk --password $rustdesk_pw &> /dev/null | |
| fi | |
| rustdesk --config $rustdesk_cfg | |
| systemctl restart rustdesk | |
| echo "..............................................." | |
| # Check if the rustdesk_id is not empty | |
| if [ -n "$rustdesk_id" ]; then | |
| echo "RustDesk ID: $rustdesk_id" | |
| else | |
| echo "Failed to get RustDesk ID." | |
| fi | |
| # Echo the value of the password variable | |
| if [ "$IS_NEW_INSTALL" = "true" ]; then | |
| echo "Password: $rustdesk_pw" | |
| else | |
| echo "RustDesk has been successfully updated. The previous password are saved." | |
| fi | |
| echo "..............................................." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment