Last active
July 2, 2026 17:02
-
-
Save hintoz/31016e23950ecfbade2d64f26d8e580e to your computer and use it in GitHub Desktop.
A modified script for downloading and installing the latest version of RustDesk for macOS
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 the value random password to the password variable | |
| rustdesk_pw=$(openssl rand -hex 4) | |
| # Provide a link to your script. | |
| # If you use the script to host it on your server and run it through 'curl -sL https://domain.ru/script.sh | bash' | |
| script_url="" | |
| # Get your config string from your Web portal and Fill Below | |
| # Use a reverse Base64 string in the format {"host":"HOSTADDRESS","relay":"","api":"","key":"HOSTKEY"} | |
| rustdesk_cfg="configstring" | |
| ################################### Please Do Not Edit Below This Line ######################################### | |
| # Root password request for privilege escalation | |
| #[ "$UID" -eq 0 ] || exec sudo bash "$0" "$@" | |
| # Checking if the script is running from root (UID 0) | |
| if [ "$(id -u)" -ne 0 ]; then | |
| echo "Administrator rights are requested..." | |
| # Checking if the script is running via curl | |
| if [ "$0" = "bash" ] || [ ! -f "$0" ]; then | |
| # The trick for macOS is to download the script again into a variable and pass it to sudo bash | |
| SCRIPT_CONTENT=$(curl -sL "$script_url") | |
| exec sudo bash -c "$SCRIPT_CONTENT" "$@" | |
| else | |
| # If the script is running as a regular local file | |
| exec sudo bash "$0" "$@" | |
| fi | |
| fi | |
| # Get the page of the latest RustDesk release and extract the blank version number. | |
| 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 | |
| # Checking the currently installed version in macOS | |
| INSTALLED_VERSION="" | |
| IS_NEW_INSTALL="false" | |
| APP_PATH="/Applications/RustDesk.app" | |
| if [ -d "$APP_PATH" ]; then | |
| INSTALLED_VERSION=$(defaults read "$APP_PATH/Contents/Info.plist" CFBundleShortVersionString 2>/dev/null) | |
| fi | |
| # Comparing the versions | |
| 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 is not found in macOS. Starting a clean install of the $LATEST_VERSION version..." | |
| IS_NEW_INSTALL="true" | |
| fi | |
| # Check the processor architecture and create links | |
| ARCH=$(arch) | |
| if [[ "$ARCH" == 'arm64' ]]; then | |
| rd_link=$(echo "$RELEASE_PAGE" | grep -Eo "(http|https)://[a-zA-Z0-9./?=_-]*/[0-9.]+/rustdesk.[0-9.]+.aarch64.dmg" | head -n 1) | |
| dmg_file=$(echo "$rd_link" | grep -Eo "rustdesk.[0-9.]+.aarch64.dmg") | |
| else | |
| rd_link=$(echo "$RELEASE_PAGE" | grep -Eo "(http|https)://[a-zA-Z0-9./?=_-]*/[0-9.]+/rustdesk.[0-9.]+.x86_64.dmg" | head -n 1) | |
| dmg_file=$(echo "$rd_link" | grep -Eo "rustdesk.[0-9.]+.x86_64.dmg") | |
| fi | |
| if [ -z "$rd_link" ]; then | |
| echo "Error: The link to the .dmg file for the $ARCH architecture could not be found." | |
| exit 1 | |
| fi | |
| # Downloading and silent installation of DMG | |
| echo "Downloading a file $dmg_file..." | |
| curl -L "$rd_link" --output "$dmg_file" | |
| echo "Mounting the image and installing it..." | |
| # Mount the dmg and get the name of the mount point. | |
| MOUNT_DIR=$(hdiutil attach "$dmg_file" -nobrowse -plist | grep -A1 'mount-point' | grep -o '/Volumes/[^<]*') | |
| if [ -n "$MOUNT_DIR" ]; then | |
| # Copy the application to the system directory (with replacement if this is an update) | |
| cp -R "$MOUNT_DIR/RustDesk.app" /Applications/ | |
| # Unmount the image | |
| hdiutil detach "$MOUNT_DIR" -quiet | |
| else | |
| echo "Failed to mount the RustDesk DMG. Installation aborted." | |
| rm -f "$dmg_file" | |
| exit 1 | |
| fi | |
| # Deleting the downloaded installer | |
| rm -f "$dmg_file" | |
| # Kill all processes named RustDesk | |
| rdpid=$(pgrep RustDesk) | |
| kill $rdpid &> /dev/null | |
| # Run the rustdesk command with --get-id and store the output in the rustdesk_id variable | |
| cd /Applications/RustDesk.app/Contents/MacOS/ | |
| rustdesk_id=$(./RustDesk --get-id) | |
| # Apply new password to RustDesk if set_rustdesk_pw=true | |
| if [ "$IS_NEW_INSTALL" = "true" ]; then | |
| ./RustDesk --server & | |
| /Applications/RustDesk.app/Contents/MacOS/RustDesk --password $rustdesk_pw &> /dev/null | |
| fi | |
| /Applications/RustDesk.app/Contents/MacOS/RustDesk --config $rustdesk_cfg | |
| # Kill all processes named RustDesk | |
| rdpid=$(pgrep RustDesk) | |
| kill $rdpid &> /dev/null | |
| 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 | |
| if [ "$IS_NEW_INSTALL" = "true" ]; then | |
| echo "Password: $rustdesk_pw" | |
| else | |
| echo "RustDesk has been successfully updated. The previous password are saved." | |
| fi | |
| echo "..............................................." | |
| echo "Please complete install on GUI, launching RustDesk now." | |
| open -n /Applications/RustDesk.app |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment