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>
This commit is contained in:
Claude 2025-11-17 01:58:43 +00:00
parent 41e9fa1056
commit 2bf3754d62
2 changed files with 46 additions and 2 deletions

View File

@ -7,6 +7,28 @@ 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"
@ -67,7 +89,7 @@ echo "=========================================="
echo "RDP Toggle API 설치 완료!"
echo "=========================================="
echo ""
echo "📍 API 서버: http://$(hostname -I | awk '{print $1}'):8090"
echo "📍 API 서버: http://$(get_primary_ip):8090"
echo "📁 설치 위치: $INSTALL_DIR"
echo ""
echo "✅ 사용 방법:"

View File

@ -73,6 +73,28 @@ check_proxmox_version() {
msg_ok "Proxmox VE $pve_version.x 버전 확인됨"
}
# 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"
}
# 루트 권한 확인
check_root() {
if [ "$EUID" -ne 0 ]; then
@ -600,7 +622,7 @@ print_completion() {
echo -e "${YELLOW}참고:${NC}"
echo " - 물리 모니터(tty1)에서 RDP 연결이 시작됩니다"
echo " - SSH 세션은 계속 사용 가능합니다"
echo " - RDP Toggle API: http://$(hostname -I | awk '{print $1}'):8090"
echo " - RDP Toggle API: http://$(get_primary_ip):8090"
echo ""
echo -e "${CYAN}API 사용 예시:${NC}"
echo " Shell 모드로 전환: curl -X POST http://localhost:8090/toggle -H 'Content-Type: application/json' -d '{\"mode\":\"shell\"}'"