#!/bin/bash
clear
echo ''
echo '  ================================================'
echo '   WhoisNetworking Remote Support Setup'
echo '  ================================================'
echo ''
echo '  Downloading RustDesk...'

# Detect Apple Silicon vs Intel
ARCH=arm64
if [ "" = "arm64" ]; then
    URL="https://remote.whoisnetworking.com/downloads/rustdesk-macos-apple.dmg"
else
    URL="https://remote.whoisnetworking.com/downloads/rustdesk-macos-intel.dmg"
fi

curl -L -o /tmp/rustdesk-setup.dmg "" --progress-bar

echo '  Mounting installer...'
hdiutil attach /tmp/rustdesk-setup.dmg -nobrowse -quiet

echo '  Installing RustDesk...'
cp -R /Volumes/RustDesk/RustDesk.app /Applications/ 2>/dev/null || true
hdiutil detach /Volumes/RustDesk -quiet 2>/dev/null || true

echo '  Applying server configuration...'
CONFIG_DIR="/Users/aaronowens/Library/Application Support/com.carriez.RustDesk"
mkdir -p ""
cat > "/RustDesk2.toml" << EOF
[options]
custom-rendezvous-server = "89.167.88.232"
relay-server = "89.167.88.232"
key = "hEovlP9IofPv0aGcOpIcyr8eWI5hnWiKG8b5rL7pUYw="
EOF

echo ''
echo '  Done! Starting RustDesk...'
open /Applications/RustDesk.app

echo ''
echo '  ================================================'
echo '   RustDesk is ready!'
echo ''
echo '   Tell your technician the ID and password'
echo '   shown in the RustDesk window.'
echo '  ================================================'
echo ''
