#!/bin/bash # 1. Set the password for 'hfuser' based on the Hugging Face Secret echo "$USERNAME:${RDP_PASSWORD:-defaultpassword}" | chpasswd # 2. Prepare Tailscale directories mkdir -p /var/run/tailscale /var/cache/tailscale /var/lib/tailscale # 3. Start Tailscale daemon in userspace networking mode (Crucial for Docker) echo "Starting Tailscale daemon..." tailscaled --tun=userspace-networking --state=/var/lib/tailscale/tailscaled.state & sleep 5 # 4. Authenticate Tailscale node to your network if [ -n "$TAILSCALE_AUTHKEY" ]; then echo "Authenticating to Tailscale..." tailscale up --authkey=${TAILSCALE_AUTHKEY} --hostname=hf-centos-desktop else echo "Error: TAILSCALE_AUTHKEY is not set in Hugging Face Secrets." fi # 5. Generate XRDP keys (required on first run) and start RDP services xrdp-keygen xrdp auto /usr/sbin/xrdp-sesman /usr/sbin/xrdp # 6. Start a dummy HTTP server on port 7860 to keep the Hugging Face Space alive echo "Starting dummy server for HF Spaces health check on port 7860..." python3 -m http.server 7860