#!/bin/bash
# ============================================================
# Instalador RustDesk preconfigurado - DAROSI Soporte Remoto
# Para Linux (Debian/Ubuntu) - Ejecutar en Terminal
# ============================================================

SERVER="soporte.darosi.com.mx"
KEY="vfZ9e9zmgIHJ59t19ng5AnPge1dDilg0wVT6Yv17XtI="
URL="https://soporte.darosi.com.mx/descargas/clients/rustdesk-linux.deb"

echo ""
echo "============================================"
echo "  DAROSI - Instalador de Soporte Remoto"
echo "============================================"
echo ""

DEB="/tmp/rustdesk-darosi.deb"

echo "[1/3] Descargando RustDesk..."
curl -sL "$URL" -o "$DEB"
echo "       Descarga completada."

echo "[2/3] Instalando RustDesk..."
sudo dpkg -i "$DEB" 2>/dev/null
sudo apt-get install -f -y -qq 2>/dev/null
rm -f "$DEB"
echo "       Instalación completada."

echo "[3/3] Configurando servidor DAROSI..."
CONFIG_DIR="$HOME/.config/rustdesk"
mkdir -p "$CONFIG_DIR"
cat > "$CONFIG_DIR/RustDesk2.toml" << TOML
rendezvous_server = 'soporte.darosi.com.mx'
nat_type = 1
serial = 0

[options]
custom-rendezvous-server = '$SERVER'
relay-server = '$SERVER'
api-server = 'https://$SERVER'
key = '$KEY'
TOML
echo "       Servidor configurado: $SERVER"

echo ""
echo "============================================"
echo "  ¡Instalación completada!"
echo "  Servidor: $SERVER"
echo "============================================"
echo ""
echo "Abre RustDesk y comparte tu ID y contraseña"
echo "con el técnico de DAROSI."
echo ""

rustdesk &>/dev/null &
