From 591173d1cfbcf72ac758a9d0d6aa6656deaeccdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=8B=9C=EA=B3=A8=EC=95=BD=EC=82=AC?= Date: Thu, 11 Sep 2025 00:42:38 +0900 Subject: [PATCH] Enhanced script to handle existing Tailscale connections MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add automatic detection of existing Tailscale/Headscale connections - Implement smart server comparison to avoid unnecessary re-registration - Add --force option for mandatory re-registration - Improve user interaction for terminal vs pipe execution - Add better logout verification with retry logic - Update documentation with force registration examples - Change default behavior to auto-register (Y) instead of skip (N) πŸš€ Generated with Claude Code Co-Authored-By: Claude --- QUICK_INSTALL_GUIDE.md | 12 ++++++ README.md | 5 +++ quick-install.sh | 91 +++++++++++++++++++++++++++++++++++++----- 3 files changed, 98 insertions(+), 10 deletions(-) diff --git a/QUICK_INSTALL_GUIDE.md b/QUICK_INSTALL_GUIDE.md index a02bc27..0cde8e6 100644 --- a/QUICK_INSTALL_GUIDE.md +++ b/QUICK_INSTALL_GUIDE.md @@ -21,6 +21,18 @@ chmod +x quick-install.sh sudo ./quick-install.sh ``` +### 방법 4: κΈ°μ‘΄ Tailscale 연결이 μžˆλŠ” 경우 (κ°•μ œ μž¬λ“±λ‘) +```bash +# κΈ°μ‘΄ Tailscale/Headscale 연결을 κ°•μ œλ‘œ ν•΄μ œν•˜κ³  μž¬λ“±λ‘ +curl -fsSL https://git.0bin.in/thug0bin/headscale-tailscale-replacement/raw/branch/feature/working-headscale-setup/quick-install.sh | sudo bash -s -- --force +``` + +### 방법 5: 슀크립트 μ˜΅μ…˜ 확인 +```bash +# μ‚¬μš© κ°€λŠ₯ν•œ μ˜΅μ…˜ 보기 +curl -fsSL https://git.0bin.in/thug0bin/headscale-tailscale-replacement/raw/branch/feature/working-headscale-setup/quick-install.sh | bash -s -- --help +``` + ## ✨ μžλ™μœΌλ‘œ μˆ˜ν–‰λ˜λŠ” μž‘μ—… ### 1. πŸ” μ‹œμŠ€ν…œ 뢄석 diff --git a/README.md b/README.md index ff134ca..a398c60 100644 --- a/README.md +++ b/README.md @@ -145,6 +145,11 @@ curl -fsSL https://git.0bin.in/thug0bin/headscale-tailscale-replacement/raw/bran wget -qO- https://git.0bin.in/thug0bin/headscale-tailscale-replacement/raw/branch/feature/working-headscale-setup/quick-install.sh | sudo bash ``` +### κΈ°μ‘΄ Tailscale 연결이 μžˆλŠ” 경우 (κ°•μ œ μž¬λ“±λ‘) +```bash +curl -fsSL https://git.0bin.in/thug0bin/headscale-tailscale-replacement/raw/branch/feature/working-headscale-setup/quick-install.sh | sudo bash -s -- --force +``` + ### 지원 OS - Ubuntu, Debian, CentOS, RHEL, Rocky Linux, Fedora, Arch Linux - μžλ™ Tailscale μ„€μΉ˜ + Headscale 등둝 diff --git a/quick-install.sh b/quick-install.sh index 72f8a8c..e49af88 100755 --- a/quick-install.sh +++ b/quick-install.sh @@ -1,8 +1,9 @@ #!/bin/bash # 팜큐(FARMQ) Headscale 원클릭 μ„€μΉ˜ 및 등둝 슀크립트 -# μ‚¬μš©λ²•: curl -fsSL https://raw.githubusercontent.com/your-repo/headscale-setup/main/quick-install.sh | sudo bash -# λ˜λŠ”: wget -qO- https://raw.githubusercontent.com/your-repo/headscale-setup/main/quick-install.sh | sudo bash +# μ‚¬μš©λ²•: curl -fsSL https://git.0bin.in/.../quick-install.sh | sudo bash +# λ˜λŠ”: wget -qO- https://git.0bin.in/.../quick-install.sh | sudo bash +# κ°•μ œ μž¬λ“±λ‘: curl -fsSL https://git.0bin.in/.../quick-install.sh | sudo bash -s -- --force set -e @@ -13,6 +14,27 @@ HEADSCALE_SERVER="https://head.0bin.in" # Headscale μ„œλ²„ μ£Όμ†Œ PREAUTH_KEY="8b3df41d37cb158ea39f41fc32c9af46e761de817ad06038" # 7일간 μž¬μ‚¬μš© κ°€λŠ₯ν•œ ν‚€ FARMQ_NETWORK="100.64.0.0/10" # 팜큐 λ„€νŠΈμ›Œν¬ λŒ€μ—­ +# λͺ…λ Ήν–‰ μ˜΅μ…˜ 처리 +FORCE_REGISTER=false +for arg in "$@"; do + case $arg in + --force|-f) + FORCE_REGISTER=true + shift + ;; + --help|-h) + echo "μ‚¬μš©λ²•: $0 [μ˜΅μ…˜]" + echo "μ˜΅μ…˜:" + echo " --force, -f κΈ°μ‘΄ 연결을 κ°•μ œλ‘œ ν•΄μ œν•˜κ³  μž¬λ“±λ‘" + echo " --help, -h 도움말 ν‘œμ‹œ" + exit 0 + ;; + *) + # μ•Œ 수 μ—†λŠ” μ˜΅μ…˜ λ¬΄μ‹œ + ;; + esac +done + # ================================ # 색상 좜λ ₯ ν•¨μˆ˜ # ================================ @@ -246,18 +268,67 @@ register_headscale() { # κΈ°μ‘΄ μ—°κ²° 확인 if tailscale status >/dev/null 2>&1; then print_warning "이미 Tailscale/Headscale에 μ—°κ²°λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€." - tailscale status - read -p "κΈ°μ‘΄ 연결을 ν•΄μ œν•˜κ³  μƒˆλ‘œ λ“±λ‘ν•˜μ‹œκ² μŠ΅λ‹ˆκΉŒ? (y/N): " -n 1 -r - echo - if [[ $REPLY =~ ^[Yy]$ ]]; then + # ν˜„μž¬ μ—°κ²° μƒνƒœ ν‘œμ‹œ + CURRENT_STATUS=$(tailscale status 2>/dev/null | head -5) + print_info "ν˜„μž¬ μ—°κ²° μƒνƒœ:" + echo "$CURRENT_STATUS" + + # ν˜„μž¬ μ„œλ²„ 확인 + CURRENT_SERVER=$(tailscale status --json 2>/dev/null | grep -o '"CurrentTailnet":[^,]*' | cut -d'"' -f4 2>/dev/null || echo "μ•Œ 수 μ—†μŒ") + TARGET_SERVER=$(echo "$HEADSCALE_SERVER" | sed 's|https\?://||' | sed 's|:[0-9]*||') + + print_info "ν˜„μž¬ μ„œλ²„: $CURRENT_SERVER" + print_info "λŒ€μƒ μ„œλ²„: $TARGET_SERVER" + + # κ°•μ œ 등둝 μ˜΅μ…˜ 확인 + if [ "$FORCE_REGISTER" = true ]; then + print_warning "κ°•μ œ μž¬λ“±λ‘ μ˜΅μ…˜μ΄ ν™œμ„±ν™”λ˜μ—ˆμŠ΅λ‹ˆλ‹€." + print_info "κΈ°μ‘΄ 연결을 ν•΄μ œν•˜κ³  μž¬λ“±λ‘ν•©λ‹ˆλ‹€..." + tailscale logout >/dev/null 2>&1 || true + sleep 3 + # 같은 μ„œλ²„μΈμ§€ 확인 + elif [[ "$CURRENT_SERVER" == *"$TARGET_SERVER"* ]] || [[ "$TARGET_SERVER" == *"$CURRENT_SERVER"* ]]; then + print_success "이미 μ˜¬λ°”λ₯Έ Headscale μ„œλ²„μ— μ—°κ²°λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€!" + print_info "등둝을 κ±΄λ„ˆλœλ‹ˆλ‹€." + return 0 + # λŒ€ν™”ν˜• 싀행인지 확인 (ν„°λ―Έλ„μ—μ„œ 직접 μ‹€ν–‰) + elif [ -t 0 ] && [ -t 1 ]; then + print_warning "λ‹€λ₯Έ μ„œλ²„μ— μ—°κ²°λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€." + echo -n "κΈ°μ‘΄ 연결을 ν•΄μ œν•˜κ³  팜큐 Headscale둜 λ“±λ‘ν•˜μ‹œκ² μŠ΅λ‹ˆκΉŒ? (Y/n): " + read -r REPLY + + # 기본값을 Y둜 λ³€κ²½ (μ—”ν„°λ§Œ λˆ„λ₯΄λ©΄ Y) + if [[ -z "$REPLY" ]] || [[ $REPLY =~ ^[Yy]$ ]]; then + print_info "κΈ°μ‘΄ 연결을 ν•΄μ œν•©λ‹ˆλ‹€..." + tailscale logout >/dev/null 2>&1 || true + sleep 3 + else + print_info "등둝을 κ±΄λ„ˆλœλ‹ˆλ‹€." + return 0 + fi + else + # νŒŒμ΄ν”„ μ‹€ν–‰ μ‹œ μžλ™μœΌλ‘œ μž¬λ“±λ‘ (κΈ°λ³Έκ°’: Y) + print_warning "λ‹€λ₯Έ μ„œλ²„μ— μ—°κ²°λ˜μ–΄ μžˆμ–΄ μžλ™μœΌλ‘œ 팜큐 Headscale둜 μž¬λ“±λ‘ν•©λ‹ˆλ‹€." print_info "κΈ°μ‘΄ 연결을 ν•΄μ œν•©λ‹ˆλ‹€..." tailscale logout >/dev/null 2>&1 || true - sleep 2 - else - print_info "등둝을 κ±΄λ„ˆλœλ‹ˆλ‹€." - return + sleep 3 fi + + # μΆ”κ°€ 확인: μ™„μ „νžˆ λ‘œκ·Έμ•„μ›ƒλ˜μ—ˆλŠ”μ§€ 검증 + print_status "μ—°κ²° ν•΄μ œ 확인 쀑..." + for i in {1..10}; do + if ! tailscale status >/dev/null 2>&1; then + print_success "κΈ°μ‘΄ 연결이 μ™„μ „νžˆ ν•΄μ œλ˜μ—ˆμŠ΅λ‹ˆλ‹€." + break + fi + print_info "λ‘œκ·Έμ•„μ›ƒ λŒ€κΈ° 쀑... ($i/10)" + sleep 2 + + if [ $i -eq 10 ]; then + print_warning "λ‘œκ·Έμ•„μ›ƒμ΄ μ™„λ£Œλ˜μ§€ μ•Šμ•˜μ§€λ§Œ 계속 μ§„ν–‰ν•©λ‹ˆλ‹€." + fi + done fi print_info "Headscale μ„œλ²„: $HEADSCALE_SERVER"