#!/usr/bin/env bash set -euo pipefail if [[ ${1:-} == --help ]]; then echo '用法:bash deploy/install.sh [--interactive [--role combined|controller|node] | --non-interactive]' echo '终端运行默认进入中文交互向导;--non-interactive 保留原本机安装行为。' exit 0 fi if [[ ${1:-} == --interactive || ( $# -eq 0 && -t 0 && -t 1 ) ]]; then [[ ${1:-} != --interactive ]] || shift exec python3 "$(dirname "${BASH_SOURCE[0]}")/install-wizard.py" "$@" fi if [[ ${1:-} == --non-interactive ]]; then shift; fi [[ $# -eq 0 ]] || { echo '未知参数,使用 --help 查看安装方式。' >&2; exit 1; } if [[ "${EUID}" -ne 0 ]]; then echo "Run this installer as root." >&2 exit 1 fi source_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" build_dir="${source_dir}/build" for binary in sea-vhost-api sea-vhost-agent sea-vhost-panel-broker sea-vhost-run sea-vhost-scheduler; do [[ -f "${build_dir}/bin/$binary" && ! -L "${build_dir}/bin/$binary" ]] || { echo "Missing $binary" >&2; exit 1; } done if [[ ! -f "${build_dir}/bin/sea-vhost-api" || -L "${build_dir}/bin/sea-vhost-api" || ! -f "${build_dir}/bin/sea-vhost-agent" || -L "${build_dir}/bin/sea-vhost-agent" || ! -f "${build_dir}/bin/sea-vhost-panel-broker" || -L "${build_dir}/bin/sea-vhost-panel-broker" || ! -f "${build_dir}/web/index.html" || -L "${build_dir}/web/index.html" ]]; then echo "Missing build output. Run deploy/build.sh first." >&2 exit 1 fi if ! command -v setfacl >/dev/null 2>&1 || ! command -v getfacl >/dev/null 2>&1; then export DEBIAN_FRONTEND=noninteractive apt-get update apt-get install -y --no-install-recommends acl fi # Current security releases for older Python branches are source-only. Keep the # compiler and standard-library headers available so the privileged installer # can build the latest patch of each supported branch from verified CPython # sources instead of relying on aaPanel's stale prebuilt-version list. python_build_packages=(build-essential ca-certificates xz-utils libssl-dev zlib1g-dev libncurses-dev libreadline-dev libsqlite3-dev libgdbm-dev libdb-dev libbz2-dev libexpat1-dev liblzma-dev tk-dev libffi-dev uuid-dev) missing_python_build_packages=() for package in "${python_build_packages[@]}"; do dpkg-query -W -f='${Status}' "${package}" 2>/dev/null | grep -q 'ok installed' || missing_python_build_packages+=("${package}") done if (( ${#missing_python_build_packages[@]} > 0 )); then export DEBIAN_FRONTEND=noninteractive apt-get update apt-get install -y --no-install-recommends "${missing_python_build_packages[@]}" fi bash "$source_dir/deploy/prepare-runtime-roots.sh" for required in chattr systemctl openssl mktemp setfacl getfacl useradd usermod passwd make tar xz; do command -v "${required}" >/dev/null || { echo "Missing required command: ${required}" >&2; exit 1; } done legacy_config="/var/lib/sea-vhost/config.json" if [[ -f "${legacy_config}" ]] && grep -q '"panel_api_key"' "${legacy_config}"; then echo "Legacy Web API configuration still contains a root-equivalent panel API key." >&2 echo "Refusing an automatic migration. Back up the file, move the key into the panel broker through a root-controlled maintenance procedure, then remove it from ${legacy_config}." >&2 exit 1 fi getent group sea-vhost-control >/dev/null || groupadd --system sea-vhost-control getent group sea-vhost-agent-control >/dev/null || groupadd --system sea-vhost-agent-control getent group sea-vhost-panel-control >/dev/null || groupadd --system sea-vhost-panel-control id sea-vhost >/dev/null 2>&1 || useradd --system --gid sea-vhost-control --groups sea-vhost-agent-control,sea-vhost-panel-control --home-dir /var/lib/sea-vhost --shell /usr/sbin/nologin sea-vhost usermod -g sea-vhost-control -aG sea-vhost-agent-control,sea-vhost-panel-control sea-vhost id sea-vhost-panel >/dev/null 2>&1 || useradd --system --gid sea-vhost-panel-control --groups sea-vhost-control --home-dir /var/lib/sea-vhost-panel --shell /usr/sbin/nologin sea-vhost-panel usermod -g sea-vhost-panel-control -aG sea-vhost-control sea-vhost-panel gpasswd -d sea-vhost-panel sea-vhost-agent-control >/dev/null 2>&1 || true gpasswd -d sea-vhost-panel sea-vhost-files >/dev/null 2>&1 || true gpasswd -d sea-vhost sea-vhost-files >/dev/null 2>&1 || true if ! id www >/dev/null 2>&1; then echo "Missing Nginx/PHP service user: www" >&2 exit 1 fi if getent group sea-vhost >/dev/null 2>&1 && id www >/dev/null 2>&1; then gpasswd -d www sea-vhost >/dev/null 2>&1 || true fi if id www >/dev/null 2>&1; then gpasswd -d www sea-vhost-control >/dev/null 2>&1 || true gpasswd -d www sea-vhost-agent-control >/dev/null 2>&1 || true gpasswd -d www sea-vhost-panel-control >/dev/null 2>&1 || true gpasswd -d www sea-vhost-files >/dev/null 2>&1 || true if id -nG www | tr ' ' '\n' | grep -Eq '^sea-vhost-(control|agent-control|panel-control)$'; then echo "The www user still belongs to a Sea vHost control group; refusing to expose privileged sockets." >&2 exit 1 fi fi install -d -o root -g sea-vhost-control -m 0750 /etc/sea-vhost install -d -o root -g root -m 0755 /opt/sea-vhost if [[ -L /www/wwwroot || ( -e /www/wwwroot && ! -d /www/wwwroot ) ]]; then echo "The aaPanel site root /www/wwwroot is not a physical directory." >&2 exit 1 fi if [[ ! -d /www/wwwroot ]]; then install -d -o root -g root -m 0755 /www/wwwroot fi tenant_root="/www/wwwroot/seavHost/vHost" for managed_dir in /www/wwwroot/seavHost "${tenant_root}"; do if [[ -L "${managed_dir}" || ( -e "${managed_dir}" && ! -d "${managed_dir}" ) ]]; then echo "Unsafe Sea vHost managed directory: ${managed_dir}" >&2 exit 1 fi if [[ ! -d "${managed_dir}" ]]; then install -d -o root -g root -m 0755 "${managed_dir}" fi done nginx_vhost_root="/www/server/panel/vhost/nginx" nginx_binary="/www/server/nginx/sbin/nginx" if [[ -L "${nginx_vhost_root}" || ! -d "${nginx_vhost_root}" ]]; then echo "The aaPanel Nginx vhost root is missing or not a physical directory: ${nginx_vhost_root}" >&2 exit 1 fi if [[ ! -x "${nginx_binary}" ]]; then echo "The aaPanel Nginx binary is unavailable: ${nginx_binary}" >&2 exit 1 fi install -d -o root -g root -m 0755 "${nginx_vhost_root}/extension" security_global="${nginx_vhost_root}/sea-vhost-security-global.conf" security_backup="" if [[ -e "${security_global}" ]]; then if [[ -L "${security_global}" || ! -f "${security_global}" ]]; then echo "Unsafe existing Sea vHost Nginx security file: ${security_global}" >&2 exit 1 fi security_backup="$(mktemp)" cp --preserve=mode,ownership,timestamps -- "${security_global}" "${security_backup}" fi install -o root -g root -m 0644 "${source_dir}/deploy/nginx/sea-vhost-security-global.conf" "${security_global}" if ! "${nginx_binary}" -t; then if [[ -n "${security_backup}" ]]; then cp --preserve=mode,ownership,timestamps -- "${security_backup}" "${security_global}" else rm -f -- "${security_global}" fi [[ -z "${security_backup}" ]] || rm -f -- "${security_backup}" echo "Nginx rejected the Sea vHost security baseline; the previous configuration was restored." >&2 exit 1 fi [[ -z "${security_backup}" ]] || rm -f -- "${security_backup}" install -d -o root -g root -m 0755 /usr/local/libexec install -o root -g root -m 0755 "${build_dir}/bin/sea-vhost-run" /usr/local/libexec/sea-vhost-run install -d -o root -g sea-vhost-control -m 0750 /opt/sea-vhost/bin install -o root -g root -m 0750 "${build_dir}/bin/sea-vhost-scheduler" /opt/sea-vhost/bin/sea-vhost-scheduler install -d -o root -g root -m 0755 /opt/sea-vhost/web install -d -o sea-vhost -g sea-vhost-control -m 0700 /var/lib/sea-vhost install -d -o sea-vhost-panel -g sea-vhost-panel-control -m 0700 /var/lib/sea-vhost-panel install -d -o root -g root -m 0700 /www/backup/sea-vhost install -o root -g sea-vhost-control -m 0750 "${build_dir}/bin/sea-vhost-api" /opt/sea-vhost/bin/ install -o root -g sea-vhost-control -m 0750 "${build_dir}/bin/sea-vhost-agent" /opt/sea-vhost/bin/ install -o root -g sea-vhost-control -m 0750 "${build_dir}/bin/sea-vhost-panel-broker" /opt/sea-vhost/bin/ # aaPanel adds an immutable PHP .user.ini when a directory is registered as a # site, even for Sea vHost's static console. This directory is fully managed by # the installer and does not execute PHP, so remove that panel artifact before # normalizing ownership during upgrades. if [[ -e /opt/sea-vhost/web/.user.ini ]]; then if [[ -L /opt/sea-vhost/web/.user.ini || ! -f /opt/sea-vhost/web/.user.ini ]]; then echo "Unsafe aaPanel .user.ini artifact in the managed Web directory." >&2 exit 1 fi chattr -i -a -- /opt/sea-vhost/web/.user.ini 2>/dev/null || true rm -f -- /opt/sea-vhost/web/.user.ini fi cp -a "${build_dir}/web/." /opt/sea-vhost/web/ chown -R root:root /opt/sea-vhost/web find /opt/sea-vhost/web -type d -exec chmod 0755 {} + find /opt/sea-vhost/web -type f -exec chmod 0644 {} + if [[ ! -f /etc/sea-vhost/sea-vhost.env ]]; then setup_token="$(openssl rand -hex 32)" internal_auth_token="$(openssl rand -hex 32)" install -o root -g sea-vhost-control -m 0640 /dev/null /etc/sea-vhost/sea-vhost.env { echo "SEA_ADDR=127.0.0.1:8080" echo "SEA_CONFIG_FILE=/var/lib/sea-vhost/config.json" echo "SEA_SETUP_TOKEN=${setup_token}" echo "SEA_INTERNAL_AUTH_TOKEN=${internal_auth_token}" echo "SEA_COOKIE_SECURE=true" echo "SEA_TENANT_ROOT=${tenant_root}" echo "SEA_BACKUP_ROOT=/www/backup/sea-vhost" echo "SEA_UPLOAD_LIMIT=20971520" echo "SEA_AGENT_SOCKET=/run/sea-vhost/agent.sock" echo "SEA_PANEL_BROKER_SOCKET=/run/sea-vhost-panel/broker.sock" echo "SEA_PANEL_BROKER_STATE=/var/lib/sea-vhost-panel" echo "SEA_FILE_OWNER=sea-vhost" echo "SEA_NODE_PID_ROOT=/www/server/nodejs/vhost/pids" echo "SEA_NGINX_VHOST_ROOT=${nginx_vhost_root}" echo "SEA_NGINX_BINARY=${nginx_binary}" echo "SEA_PURE_PW_BINARY=/www/server/pure-ftpd/bin/pure-pw" echo "SEA_PHP_IDENTITY_STATE=/var/lib/sea-vhost-agent/php" echo "SEA_PHP_IDENTITY_RUN=/run/sea-vhost-php" echo "SEA_USAGE_STATE=/var/lib/sea-vhost-agent/traffic.json" echo "SEA_NGINX_LOG_ROOT=/www/wwwlogs" echo "SEA_CERT_ROOT=/www/server/panel/vhost/cert" echo "SEA_PURE_FTP_CONFIG=/www/server/pure-ftpd/etc/pure-ftpd.conf" echo "SEA_PURE_FTP_PEM=/www/server/pure-ftpd/etc/pure-ftpd.pem" } > /etc/sea-vhost/sea-vhost.env chown root:sea-vhost-control /etc/sea-vhost/sea-vhost.env chmod 0640 /etc/sea-vhost/sea-vhost.env echo "Created /etc/sea-vhost/sea-vhost.env." echo "A one-time setup token was created. Retrieve it locally as root from /etc/sea-vhost/sea-vhost.env." else echo "Keeping existing /etc/sea-vhost/sea-vhost.env and setup token." fi chown root:sea-vhost-control /etc/sea-vhost/sea-vhost.env chmod 0640 /etc/sea-vhost/sea-vhost.env grep -q '^SEA_PANEL_BROKER_SOCKET=' /etc/sea-vhost/sea-vhost.env || echo 'SEA_PANEL_BROKER_SOCKET=/run/sea-vhost-panel/broker.sock' >> /etc/sea-vhost/sea-vhost.env if ! grep -q '^SEA_INTERNAL_AUTH_TOKEN=' /etc/sea-vhost/sea-vhost.env; then internal_auth_token="$(openssl rand -hex 32)" echo "SEA_INTERNAL_AUTH_TOKEN=${internal_auth_token}" >> /etc/sea-vhost/sea-vhost.env fi grep -q '^SEA_PANEL_BROKER_STATE=' /etc/sea-vhost/sea-vhost.env || echo 'SEA_PANEL_BROKER_STATE=/var/lib/sea-vhost-panel' >> /etc/sea-vhost/sea-vhost.env grep -q '^SEA_TENANT_ROOT=' /etc/sea-vhost/sea-vhost.env || echo "SEA_TENANT_ROOT=${tenant_root}" >> /etc/sea-vhost/sea-vhost.env grep -q '^SEA_BACKUP_ROOT=' /etc/sea-vhost/sea-vhost.env || echo 'SEA_BACKUP_ROOT=/www/backup/sea-vhost' >> /etc/sea-vhost/sea-vhost.env grep -q '^SEA_NGINX_VHOST_ROOT=' /etc/sea-vhost/sea-vhost.env || echo "SEA_NGINX_VHOST_ROOT=${nginx_vhost_root}" >> /etc/sea-vhost/sea-vhost.env grep -q '^SEA_NGINX_BINARY=' /etc/sea-vhost/sea-vhost.env || echo "SEA_NGINX_BINARY=${nginx_binary}" >> /etc/sea-vhost/sea-vhost.env grep -q '^SEA_PURE_PW_BINARY=' /etc/sea-vhost/sea-vhost.env || echo 'SEA_PURE_PW_BINARY=/www/server/pure-ftpd/bin/pure-pw' >> /etc/sea-vhost/sea-vhost.env grep -q '^SEA_PHP_IDENTITY_STATE=' /etc/sea-vhost/sea-vhost.env || echo 'SEA_PHP_IDENTITY_STATE=/var/lib/sea-vhost-agent/php' >> /etc/sea-vhost/sea-vhost.env grep -q '^SEA_PHP_IDENTITY_RUN=' /etc/sea-vhost/sea-vhost.env || echo 'SEA_PHP_IDENTITY_RUN=/run/sea-vhost-php' >> /etc/sea-vhost/sea-vhost.env grep -q '^SEA_USAGE_STATE=' /etc/sea-vhost/sea-vhost.env || echo 'SEA_USAGE_STATE=/var/lib/sea-vhost-agent/traffic.json' >> /etc/sea-vhost/sea-vhost.env grep -q '^SEA_NGINX_LOG_ROOT=' /etc/sea-vhost/sea-vhost.env || echo 'SEA_NGINX_LOG_ROOT=/www/wwwlogs' >> /etc/sea-vhost/sea-vhost.env grep -q '^SEA_CERT_ROOT=' /etc/sea-vhost/sea-vhost.env || echo 'SEA_CERT_ROOT=/www/server/panel/vhost/cert' >> /etc/sea-vhost/sea-vhost.env grep -q '^SEA_PURE_FTP_CONFIG=' /etc/sea-vhost/sea-vhost.env || echo 'SEA_PURE_FTP_CONFIG=/www/server/pure-ftpd/etc/pure-ftpd.conf' >> /etc/sea-vhost/sea-vhost.env grep -q '^SEA_PURE_FTP_PEM=' /etc/sea-vhost/sea-vhost.env || echo 'SEA_PURE_FTP_PEM=/www/server/pure-ftpd/etc/pure-ftpd.pem' >> /etc/sea-vhost/sea-vhost.env grep -q '^SEA_FILE_OWNER=' /etc/sea-vhost/sea-vhost.env || echo 'SEA_FILE_OWNER=sea-vhost' >> /etc/sea-vhost/sea-vhost.env grep -q '^SEA_NODE_PID_ROOT=' /etc/sea-vhost/sea-vhost.env || echo 'SEA_NODE_PID_ROOT=/www/server/nodejs/vhost/pids' >> /etc/sea-vhost/sea-vhost.env sed -i '/^SEA_RUNTIME_USER=/d' /etc/sea-vhost/sea-vhost.env sed -i '/^SEA_RUNTIME_GROUP=/d' /etc/sea-vhost/sea-vhost.env sed -i '/^SEA_AGENT_GROUP=/d' /etc/sea-vhost/sea-vhost.env sed -i '/^SEA_QUOTA_MOUNT=/d' /etc/sea-vhost/sea-vhost.env install -o root -g root -m 0644 "${source_dir}/deploy/systemd/sea-vhost-agent.service" /etc/systemd/system/ install -o root -g root -m 0644 "${source_dir}/deploy/systemd/sea-vhost-panel-broker.service" /etc/systemd/system/ install -o root -g root -m 0644 "${source_dir}/deploy/systemd/sea-vhost-api.service" /etc/systemd/system/ systemctl daemon-reload echo "Files installed. Services were not started. Configure the Nginx vhost, create an empty MySQL database and user, then run:" echo " systemctl enable --now sea-vhost-agent sea-vhost-panel-broker sea-vhost-api" echo "Open the Sea vHost console and complete the Web installation wizard."