#!/usr/bin/env bash set -Eeuo pipefail REPO="${NG_REPO:-a2899882/NexusGate}" BRANCH="${NG_BRANCH:-main}" DOMAIN="" EMAIL="" die() { printf '错误:%s\n' "$*" >&2; exit 1; } info() { printf '\033[1;36m[NexusGate]\033[0m %s\n' "$*"; } ask() { local prompt="$1" value="" if [[ -r /dev/tty ]]; then read -r -p "$prompt" value /dev/null || groupadd --system nexusgate id nexusgate >/dev/null 2>&1 || useradd --system --gid nexusgate --home-dir /var/lib/nexusgate --shell /usr/sbin/nologin nexusgate install -d -o root -g root -m 0755 /opt/nexusgate cp -a "$tmp_dir/source/." /opt/nexusgate/ install -d -o nexusgate -g nexusgate -m 0700 /var/lib/nexusgate admin_password="$(openssl rand -base64 24 | tr -d '\n')" session_secret="$(openssl rand -hex 32)" cat > /etc/nexusgate.env < /etc/caddy/Caddyfile.d/nexusgate.caddy <> /etc/caddy/Caddyfile.d/nexusgate.caddy; fi printf '}\n' >> /etc/caddy/Caddyfile.d/nexusgate.caddy if ! grep -qF 'import /etc/caddy/Caddyfile.d/*' /etc/caddy/Caddyfile; then printf '\nimport /etc/caddy/Caddyfile.d/*\n' >> /etc/caddy/Caddyfile fi caddy fmt --overwrite /etc/caddy/Caddyfile caddy fmt --overwrite /etc/caddy/Caddyfile.d/nexusgate.caddy caddy validate --config /etc/caddy/Caddyfile systemctl daemon-reload systemctl enable --now nexusgate.service healthy=false for _ in {1..30}; do if curl -fsS http://127.0.0.1:8787/healthz >/dev/null 2>&1; then healthy=true; break; fi sleep 1 done if [[ "$healthy" != true ]]; then systemctl status nexusgate --no-pager || true journalctl -u nexusgate -n 100 --no-pager || true die "控制面启动失败,诊断信息已输出" fi sed -i '/^NG_ADMIN_PASSWORD=/d' /etc/nexusgate.env systemctl enable --now caddy systemctl reload caddy printf '\n\033[1;32m安装完成\033[0m\n' printf '地址:https://%s\n账号:admin\n密码:%s\n' "$DOMAIN" "$admin_password" printf '管理命令:nexusgate 或 ng\n请立即登录并妥善保存密码。\n'