#!/usr/bin/env bash set -euo pipefail APP_USER="${APP_USER:-daniel}" APP_DIR="${APP_DIR:-/opt/investor-rpg}" SERVICE_NAME="${SERVICE_NAME:-investor-rpg}" SERVER_NAME="${SERVER_NAME:-_}" if [[ "${EUID}" -ne 0 ]]; then echo "請用 sudo 執行:sudo bash $0" >&2 exit 1 fi apt-get update DEBIAN_FRONTEND=noninteractive apt-get install -y ca-certificates curl nginx rsync sqlite3 if ! command -v node >/dev/null 2>&1 || [[ "$(node -p 'Number(process.versions.node.split(".")[0])')" -lt 22 ]]; then curl -fsSL https://deb.nodesource.com/setup_22.x | bash - DEBIAN_FRONTEND=noninteractive apt-get install -y nodejs fi install -d -o "${APP_USER}" -g "${APP_USER}" "${APP_DIR}" "${APP_DIR}/backups" install -d -o "${APP_USER}" -g "${APP_USER}" "/opt/content" "/opt/content/raw" "/opt/content/raw/patterns" cat >"/etc/systemd/system/${SERVICE_NAME}.service" <"/etc/nginx/sites-available/${SERVICE_NAME}" <"/etc/sudoers.d/${SERVICE_NAME}-deploy" <