#!/bin/bash # This script updates the user's RustDesk2.toml (configuration) file to use # VerrilloTrading relay server. Unlike the Windows version, this script does # not require elevated privileges to run. This is because the RustDesk Service # does not run the same on MacOS as it does on Windows. On Windows this Service # holds the gui settings of RustDesk in memory which causes problems when it # comes to changing a config file as this script is doing. # # RustDesk is more secure without the RustDesk service because it requires # the RustDesk application to be started and running by the user before any # remote desktop connection can be made. # # You can run this script again if you made changes to the RustDesk network # settings by accident or if you were using another relay server temporarily. # This script will autopopulate the required settings for VerrilloTrading relay # server. If you go ahead and manually change the network settings in RustDesk # you will need to run this script again to connect to our relay server. # # There is no danger in executing this script. # # Check if RustDesk is running and quit it if pgrep -f "RustDesk" > /dev/null; then echo "RustDesk is running. Closing it now..." pkill -f "RustDesk" # Wait briefly to ensure it’s closed sleep 2 fi # Define the path to RustDesk2.toml on macOS CONFIG_PATH="$HOME/Library/Preferences/com.carriez.RustDesk/RustDesk2.toml" # Define path to RustDesk RUSTDESK_APP="/Applications/RustDesk.app/Contents/MacOS/RustDesk" # Check if RustDesk2.toml exists; if not, try to start RustDesk if [ ! -f "$CONFIG_PATH" ]; then echo "RustDesk2.toml not found. Attempting to start RustDesk to generate it..." if [ -f "$RUSTDESK_APP" ]; then echo "Trying to start RustDesk..." # Start RustDesk in the background open -a "RustDesk" & # Wait a bit for RustDesk to create the config file sleep 2 # Check again if the file exists if [ ! -f "$CONFIG_PATH" ]; then echo "Operation failed: Please install and run RustDesk manually one time before running this script." read -p "Press Enter to exit..." exit 1 else echo "Success: Closing RustDesk and proceeding..." # Close RustDesk now that the config files were autogenerated pkill -f "RustDesk" 2>/dev/null # Wait a moment to ensure it’s fully closed sleep 2 fi else echo "Could not find RustDesk at $RUSTDESK_APP." echo "Operation failed: Please install and run RustDesk manually one time before running this script." read -p "Press Enter to exit..." exit 1 fi fi # Define the desired configuration lines DESIRED_LINES=( "custom-rendezvous-server = '178.156.134.213'" "relay-server = '178.156.134.213'" "key = '00Faq92+WCmEvsPfDmJiC8kXVBvYbMAP2LCEE+eRIgU='" ) # Keys to look for (extracted from DESIRED_LINES for matching) KEYS=( "custom-rendezvous-server" "relay-server" "key" ) # Check if RustDesk2.toml exists (assuming it’s created earlier by starting RustDesk) if [ -f "$CONFIG_PATH" ]; then # Read existing content line-by-line, filter out empty lines TEMP_FILE=$(mktemp) cat "$CONFIG_PATH" | grep -v '^$' > "$TEMP_FILE" # Initialize variables UPDATED_LINES="" FOUND_KEYS="" NEEDS_UPDATE=0 # Process each line while IFS= read -r line; do TRIMMED_LINE=$(echo "$line" | xargs) # Trim whitespace REPLACED=0 # Check if the line matches any key for key in "${KEYS[@]}"; do if echo "$TRIMMED_LINE" | grep -q "^$key"; then # Replace with the desired line for desired in "${DESIRED_LINES[@]}"; do if echo "$desired" | grep -q "^$key"; then UPDATED_LINES="$UPDATED_LINES$desired\n" FOUND_KEYS="$FOUND_KEYS$key\n" REPLACED=1 break fi done break fi done # Keep non-matching lines if [ $REPLACED -eq 0 ]; then UPDATED_LINES="$UPDATED_LINES$line\n" fi done < "$TEMP_FILE" # Add any missing keys for key in "${KEYS[@]}"; do if ! echo -e "$FOUND_KEYS" | grep -q "^$key$"; then for desired in "${DESIRED_LINES[@]}"; do if echo "$desired" | grep -q "^$key"; then UPDATED_LINES="$UPDATED_LINES$desired\n" NEEDS_UPDATE=1 break fi done fi done # Write updated content back to the file printf "%b" "$UPDATED_LINES" > "$CONFIG_PATH" # Provide feedback if [ -n "$FOUND_KEYS" ] || [ $NEEDS_UPDATE -eq 1 ]; then echo "Success: Configuration file was updated to use VerrilloTrading Relay server." else echo "Success: Configuration file already matches VerrilloTrading Relay server settings." fi # Clean up temporary file rm -f "$TEMP_FILE" fi # Try to restart RustDesk if [ -f "$RUSTDESK_APP" ]; then echo "Success: Starting RustDesk." open -a "RustDesk" & else echo "Could not find RustDesk at $RUSTDESK_APP. Please start RustDesk manually." fi # Notify the user echo "Success: RustDesk is now setup to receive support by VerrilloTrading." echo "If you have any questions, contact support@verrillotrading.com"