#!/usr/bin/env bash set -euo pipefail if [[ ${1:-} == --help ]]; then echo '独立主控:bash deploy/install.sh --interactive --role controller;自动化:bash deploy/install-controller.sh --non-interactive' exit 0 fi if [[ $# -eq 0 && -t 0 && -t 1 ]]; then exec python3 "$(dirname "${BASH_SOURCE[0]}")/install-wizard.py" --role controller; fi if [[ ${1:-} == --non-interactive ]]; then shift; fi [[ $# -eq 0 ]] || { echo '未知参数。' >&2; exit 1; } [[ ${EUID} -eq 0 ]] || { echo 'Run as root.' >&2; exit 1; } source_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" [[ -f "$source_dir/build/bin/sea-vhost-api" && -f "$source_dir/build/web/index.html" ]] || { echo 'Build output missing.' >&2; exit 1; } [[ ! -e /var/lib/sea-vhost-panel/credentials.json ]] || { echo 'Existing combined installation detected; use the documented migration procedure.' >&2; exit 1; } getent group sea-vhost-control >/dev/null || groupadd --system sea-vhost-control id sea-vhost >/dev/null 2>&1 || useradd --system --gid sea-vhost-control --no-create-home --home-dir /var/lib/sea-vhost --shell /usr/sbin/nologin sea-vhost install -d -o root -g root -m 0755 /opt/sea-vhost /opt/sea-vhost/bin /opt/sea-vhost/web install -d -o root -g sea-vhost-control -m 0750 /etc/sea-vhost install -d -o sea-vhost -g sea-vhost-control -m 0700 /var/lib/sea-vhost install -o root -g root -m 0755 "$source_dir/build/bin/sea-vhost-api" /opt/sea-vhost/bin/sea-vhost-api cp -a "$source_dir/build/web/." /opt/sea-vhost/web/ chmod -R a+rX /opt/sea-vhost/web if [[ ! -e /etc/sea-vhost/sea-vhost.env ]]; then umask 077 token="$(openssl rand -hex 32)" printf 'SEA_CONTROLLER_ONLY=true\nSEA_SETUP_TOKEN=%s\nSEA_ADDR=127.0.0.1:8080\nSEA_CONFIG_FILE=/var/lib/sea-vhost/config.json\n' "$token" > /etc/sea-vhost/sea-vhost.env echo 'Created installation token in /etc/sea-vhost/sea-vhost.env.' fi grep -qx 'SEA_CONTROLLER_ONLY=true' /etc/sea-vhost/sea-vhost.env || { echo 'Existing environment is not controller-only.' >&2; exit 1; } install -o root -g root -m 0644 "$source_dir/deploy/systemd/sea-vhost-controller.service" /etc/systemd/system/sea-vhost-api.service systemctl daemon-reload systemctl enable --now sea-vhost-api.service echo 'Controller listening on 127.0.0.1:8080. Serve /opt/sea-vhost/web and proxy /api to this address using your management domain. Complete the Web installation with the local MySQL account.'