#!/usr/bin/env bash # Install CyberLux as a systemd service (Next.js on 127.0.0.1:3000). # Tor + nginx must already be configured (run: sudo bash scripts/install-tor-onion.sh # after npm run build / ./start.sh has generated configs). # # Usage (from repo root): # sudo CYBERLUX_USER=drjones bash scripts/install-systemd.sh # # Optional env: # CYBERLUX_USER — Unix user to run the app (default: $SUDO_USER or first arg) # CYBERLUX_REPO — Absolute path to repo (default: parent of this script) # CYBERLUX_GROUP — Group (default: primary group of CYBERLUX_USER) set -euo pipefail [[ "${EUID}" -eq 0 ]] || { echo "Run as root: sudo bash $0"; exit 1; } REPO_DEFAULT="$(cd "$(dirname "$0")/.." && pwd)" CYBERLUX_REPO="${CYBERLUX_REPO:-$REPO_DEFAULT}" CYBERLUX_USER="${CYBERLUX_USER:-${SUDO_USER:-}}" if [[ -z "${CYBERLUX_USER}" ]] && [[ -n "${1:-}" ]]; then CYBERLUX_USER="$1" fi if [[ -z "${CYBERLUX_USER}" ]]; then echo "Set CYBERLUX_USER or run: sudo bash $0 " exit 1 fi if ! id -u "${CYBERLUX_USER}" >/dev/null 2>&1; then echo "[!] Unix user '${CYBERLUX_USER}' does not exist. Create it first, e.g.:" echo " sudo useradd -r -m -s /bin/bash ${CYBERLUX_USER}" exit 1 fi CYBERLUX_GROUP="${CYBERLUX_GROUP:-$(id -gn "${CYBERLUX_USER}")}" if [[ ! -d "${CYBERLUX_REPO}" ]]; then echo "[!] CYBERLUX_REPO is not a directory: ${CYBERLUX_REPO}" exit 1 fi NODE_BIN="$(command -v node || true)" NPM_BIN="$(command -v npm || true)" if [[ -z "${NODE_BIN}" ]] || [[ -z "${NPM_BIN}" ]]; then echo "[!] node and npm must be on PATH for root when installing (or edit the unit)." echo " e.g. export PATH=/usr/bin:\$PATH" exit 1 fi ENV_FILE="/etc/default/cyberlux" UNIT_DST="/etc/systemd/system/cyberlux.service" # Minimal PATH so systemd finds node/npm when not using login shells cat > "${ENV_FILE}" < "${UNIT_DST}" <