#!/usr/bin/env bash
set -euo pipefail

# RustDesk server config (rustdesk.jaenulton.com)
RUSTDESK_CFG='0nI9UlZ1c0TpNVbr4EaSlWbPh0V0lDWZNDMOFkWpJ2dNlHNTNnUKRGVS12Y6lmI6ISeltmIsISbvNmLu9GdsVnblFmaus2clRGdzVnciojI5FGblJnIsISbvNmLu9GdsVnblFmaus2clRGdzVnciojI0N3boJye'
DEB_URL='https://github.com/rustdesk/rustdesk/releases/download/1.4.5/rustdesk-1.4.5-x86_64.deb'
TMP_DEB='/tmp/rustdesk-1.4.5-x86_64.deb'

if [[ ${EUID:-$(id -u)} -ne 0 ]]; then
  echo 'Please run as root (sudo).'
  exit 1
fi

echo 'Downloading RustDesk .deb...'
curl -fL "$DEB_URL" -o "$TMP_DEB"

echo 'Installing RustDesk...'
apt-get update -y
apt-get install -y "$TMP_DEB"

echo 'Applying server config...'
rustdesk --config "$RUSTDESK_CFG"

echo 'Done. RustDesk is configured for rustdesk.jaenulton.com'
