#!/bin/bash # Points RustDesk on this Mac at rd.jebitservices.ca. # Double-click this file, or run: bash set-server-macos.command HOST='rd.jebitservices.ca' KEY='2fXPVfTQT9ox0NdI9GYY4ux5+FY9ibxnJnLvbEHIFbU=' RELAY='' API='https://rd.jebitservices.ca' CONFIG='Qfi0TViZUSIVkY2xkbK5GeilWOZZ0K1gXd0kVWHlTSk5EM49WOUFFVmZFUYZmMiojI5V2aiwiIhNmLzV2YpZnclNHdpJWZq5CZy9yL6MHc0RHaiojIpBXYiwiIiojI5FGblJnIsISYj5yclNWa2JXZzRXaiVmauQmciojI0N3boJye' APP=/Applications/RustDesk.app PREFS=Library/Preferences/com.carriez.RustDesk/RustDesk2.toml # Write the server into the [options] table of a RustDesk2.toml, keeping everything else. set_options() { mkdir -p "$(dirname "$1")" && touch "$1" || return 1 awk -v host="$HOST" -v key="$KEY" -v relay="$RELAY" -v api="$API" ' function emit() { printf "custom-rendezvous-server = \047%s\047\nkey = \047%s\047\nrelay-server = \047%s\047\napi-server = \047%s\047\n", host, key, relay, api } /^\[options\][ \t]*$/ { print; emit(); done = 1; next } /^(custom-rendezvous-server|key|relay-server|api-server)[ \t]*=/ { next } { print } END { if (!done) { print ""; print "[options]"; emit() } } ' "$1" > "$1.new" && mv "$1.new" "$1" } if [ ! -d "$APP" ]; then echo "RustDesk is not installed in /Applications. Install it first, then run this again." exit 1 fi echo "Closing RustDesk..." osascript -e 'quit app "RustDesk"' >/dev/null 2>&1 sleep 2 set_options "$HOME/$PREFS" && echo "Updated your RustDesk settings." # The background service (installed from RustDesk's own "Install" button) has its own settings. if ls /Library/LaunchDaemons/com.carriez.RustDesk*.plist >/dev/null 2>&1; then echo "Updating the RustDesk service settings (your Mac password may be asked)..." tmp=$(mktemp) sudo cat "/var/root/$PREFS" > "$tmp" 2>/dev/null set_options "$tmp" sudo mkdir -p "/var/root/$(dirname "$PREFS")" sudo cp "$tmp" "/var/root/$PREFS" rm -f "$tmp" sudo "$APP/Contents/MacOS/RustDesk" --config "$CONFIG" >/dev/null 2>&1 || true sudo pkill -f "$APP/Contents/MacOS/RustDesk" >/dev/null 2>&1 || true fi open -a RustDesk echo "RustDesk on this Mac now uses $HOST."