#!/usr/bin/env bash # One-time setup: create the games user, install directory, and systemd unit. # Run as root (or with sudo). set -euo pipefail if [[ $EUID -ne 0 ]]; then echo "Run as root: sudo $0" >&2 exit 1 fi # Create system user if it doesn't exist if ! id -u games &>/dev/null; then useradd --system --shell /usr/sbin/nologin --home-dir /opt/c4 --create-home games echo "Created system user: games" else echo "User 'games' already exists" fi # Ensure install directory exists with correct ownership install -d -o games -g games -m 755 /opt/c4 install -d -o games -g games -m 755 /opt/c4/data # Install systemd unit SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" cp "$SCRIPT_DIR/c4.service" /etc/systemd/system/c4.service systemctl daemon-reload systemctl enable c4.service echo "Setup complete. Run deploy.sh to build and start the service."