You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

55 lines
1.7 KiB

#!/usr/bin/env bash
set -euo pipefail
APP_USER="${APP_USER:-hw}"
APP_GROUP="${APP_GROUP:-$APP_USER}"
APP_DIR="${APP_DIR:-/opt/hw}"
ENV_DIR="${ENV_DIR:-/etc/hw}"
SERVICE_NAME="${SERVICE_NAME:-hw}"
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
require_root() {
if [[ "${EUID}" -ne 0 ]]; then
printf 'Please run this script as root.\n' >&2
exit 1
fi
}
ensure_user() {
if ! id -u "$APP_USER" >/dev/null 2>&1; then
useradd --system --create-home --shell /usr/sbin/nologin "$APP_USER"
fi
}
main() {
require_root
ensure_user
install -d -m 755 -o "$APP_USER" -g "$APP_GROUP" "$APP_DIR"
install -d -m 755 -o "$APP_USER" -g "$APP_GROUP" "$APP_DIR/instance"
install -d -m 755 -o "$APP_USER" -g "$APP_GROUP" "$APP_DIR/instance/csv_previews"
install -d -m 750 -o root -g "$APP_GROUP" "$ENV_DIR"
if [[ ! -d "$APP_DIR/.venv" ]]; then
python3 -m venv "$APP_DIR/.venv"
fi
"$APP_DIR/.venv/bin/python" -m pip install --upgrade pip
install -m 644 "$PROJECT_ROOT/deploy/systemd/hw.service" "/etc/systemd/system/${SERVICE_NAME}.service"
if [[ ! -f "$ENV_DIR/hw.env" ]]; then
install -m 640 -o root -g "$APP_GROUP" "$PROJECT_ROOT/deploy/env/hw.env.example" "$ENV_DIR/hw.env"
printf 'Created %s/hw.env from template. Please edit it before starting the service.\n' "$ENV_DIR"
else
printf 'Keeping existing %s/hw.env\n' "$ENV_DIR"
fi
printf '\nNext steps:\n'
printf '1. Sync project files into %s\n' "$APP_DIR"
printf '2. Edit %s/hw.env with real production values\n' "$ENV_DIR"
printf '3. Copy deploy/caddy/Caddyfile into your Caddy config and replace the domain\n'
printf '4. Run scripts/deploy-systemd.sh as root\n'
}
main "$@"