pve9-repo-fix/RDP/install-rdp-api.sh
Claude 2bf3754d62 Improve IP detection: prioritize Headscale VPN IP
- Added get_primary_ip() helper function
- Prioritize Headscale VPN IP (100.64.x.x) detection
- Fallback to local IP if Headscale not available
- Applied to both proxmox-auto-rdp-setup.sh and install-rdp-api.sh
- More reliable IP display for API endpoint

This ensures VPN IP is shown when available, making remote access
more reliable and predictable.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-17 01:58:43 +00:00

113 lines
3.0 KiB
Bash
Executable File

#!/bin/bash
# RDP Toggle API 설치 스크립트
# curl -fsSL https://git.0bin.in/thug0bin/pve9-repo-fix/raw/branch/main/RDP/install-rdp-api.sh | bash
set -e
echo "RDP Toggle API 설치 시작..."
# IP 주소 가져오기 (Headscale 우선, 없으면 로컬 IP)
get_primary_ip() {
# Headscale VPN IP 확인 (100.64.x.x 대역)
local headscale_ip=$(hostname -I | tr ' ' '\n' | grep '^100\.64\.' | head -n1)
if [ -n "$headscale_ip" ]; then
echo "$headscale_ip"
return 0
fi
# Headscale IP가 없으면 로컬 IP (첫 번째)
local local_ip=$(hostname -I | awk '{print $1}')
if [ -n "$local_ip" ]; then
echo "$local_ip"
return 0
fi
# 그것도 없으면 localhost
echo "127.0.0.1"
}
# 설치 디렉토리 설정
INSTALL_DIR="/opt/rdp-toggle-api"
VENV_DIR="$INSTALL_DIR/venv"
GITEA_BASE_URL="https://git.0bin.in/thug0bin/pve9-repo-fix/raw/branch/main/RDP"
# Python 및 venv 설치
echo "Python 및 필수 패키지 설치 중..."
apt update
apt install -y python3 python3-venv python3-pip curl
# 설치 디렉토리 생성
mkdir -p "$INSTALL_DIR"
# 가상환경 생성
echo "가상환경 생성 중..."
python3 -m venv "$VENV_DIR"
# 가상환경에서 패키지 설치
echo "Python 패키지 설치 중..."
"$VENV_DIR/bin/pip" install --upgrade pip
"$VENV_DIR/bin/pip" install fastapi==0.115.5 uvicorn==0.32.1 python-multipart==0.0.20 pydantic==2.10.3
# API 파일 다운로드
echo "API 서버 파일 다운로드 중..."
curl -fsSL "$GITEA_BASE_URL/rdp-toggle-api.py" -o "$INSTALL_DIR/rdp-toggle-api.py"
chmod +x "$INSTALL_DIR/rdp-toggle-api.py"
# systemd 서비스 생성
echo "systemd 서비스 생성 중..."
cat > /etc/systemd/system/rdp-toggle-api.service << EOF
[Unit]
Description=RDP Toggle API Service
After=network.target
[Service]
Type=simple
User=root
WorkingDirectory=$INSTALL_DIR
ExecStart=$VENV_DIR/bin/python $INSTALL_DIR/rdp-toggle-api.py
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
# 서비스 활성화 및 시작
echo "서비스 활성화 및 시작 중..."
systemctl daemon-reload
systemctl enable rdp-toggle-api.service
systemctl start rdp-toggle-api.service
# 잠시 대기 후 상태 확인
sleep 2
echo ""
echo "=========================================="
echo "RDP Toggle API 설치 완료!"
echo "=========================================="
echo ""
echo "📍 API 서버: http://$(get_primary_ip):8090"
echo "📁 설치 위치: $INSTALL_DIR"
echo ""
echo "✅ 사용 방법:"
echo " 상태 확인:"
echo " curl http://localhost:8090/status"
echo ""
echo " RDP 모드 활성화:"
echo " curl -X POST http://localhost:8090/toggle \\"
echo " -H 'Content-Type: application/json' \\"
echo " -d '{\"mode\":\"rdp\"}'"
echo ""
echo " Shell 모드 전환:"
echo " curl -X POST http://localhost:8090/toggle \\"
echo " -H 'Content-Type: application/json' \\"
echo " -d '{\"mode\":\"shell\"}'"
echo ""
echo "🔧 서비스 관리:"
echo " systemctl status rdp-toggle-api"
echo " systemctl restart rdp-toggle-api"
echo " systemctl stop rdp-toggle-api"
echo ""