更新 setup-relay.sh

This commit is contained in:
i
2026-03-18 21:13:15 +08:00
parent 06b1e248d7
commit f09231786f
+61 -4
View File
@@ -620,8 +620,7 @@ $DRY_RUN && { warn "DRY-RUN: skipping firewall step."; exit 0; }
if ! ask_yn "Configure firewall rules now?" "y"; then
info "Skipped. Remember to open the ports listed above manually."
exit 0
fi
else
# ── Detect firewall ───────────────────────────────────────────────────────────
detect_firewall() {
@@ -647,9 +646,13 @@ case "$FW" in
iptables) info "Detected: iptables" ;;
none) warn "No supported firewall detected (firewalld / ufw / nftables / iptables)."
info "Open the ports listed in Step 5 manually."
exit 0 ;;
_FW_SKIP=true ;;
esac
if [[ "${_FW_SKIP:-false}" == "true" ]]; then
: # fall through to Step 7
else
# ── Collect all ports to open across all relays ───────────────────────────────
declare -a FW_TCP=()
declare -a FW_UDP=()
@@ -795,4 +798,58 @@ fi
apply_firewall_rules "$FW"
echo ""
success "Firewall rules applied. 🎉"
success "Firewall rules applied. 🎉"
fi # end _FW_SKIP check
fi # end firewall step
# ═════════════════════════════════════════════════════════════════════════════
# STEP 7 – Start / Restart containers (optional)
# ═════════════════════════════════════════════════════════════════════════════
header "Step 7 · Start / Restart Containers (optional)"
$DRY_RUN && { warn "DRY-RUN: skipping container step."; exit 0; }
if ! ask_yn "Run 'docker compose down && docker compose up -d' for each relay now?" "y"; then
info "Skipped. Start the containers manually:"
for i in "${!RELAY_DIRS[@]}"; do
echo " cd ${RELAY_DIRS[$i]} && docker compose down && docker compose up -d"
done
exit 0
fi
if ! command -v docker &>/dev/null; then
error "docker not found — cannot start containers."
info "Install Docker and run manually:"
for i in "${!RELAY_DIRS[@]}"; do
echo " cd ${RELAY_DIRS[$i]} && docker compose down && docker compose up -d"
done
exit 1
fi
for i in "${!RELAY_DIRS[@]}"; do
DIR="${RELAY_DIRS[$i]}"
D="${RELAY_DOMAINS[$i]}"
echo ""
info "Relay: ${D}"
if [[ ! -f "${DIR}/docker-compose.yml" ]]; then
error " ${DIR}/docker-compose.yml not found — skipping."
continue
fi
info " Stopping existing container (if any) ..."
( cd "$DIR" && docker compose down ) && success " docker compose down: OK" \
|| warn " docker compose down returned non-zero (container may not have been running)"
info " Starting container ..."
if ( cd "$DIR" && docker compose up -d ); then
success " docker compose up -d: OK"
info " Logs: cd ${DIR} && docker compose logs -f"
else
error " docker compose up -d failed. Check logs:"
error " cd ${DIR} && docker compose logs -f"
fi
done
echo ""
success "All done! 🎉"