Files
deepdrft/deploy/deploy-public.sh
T

59 lines
2.2 KiB
Bash

#!/usr/bin/env bash
# Installed to: /opt/<APP_USER>/bin/deploy-public.sh
# Deployed by: deploy-public Gitea Actions workflow (ssh forced-command)
#
# Expects in ${APP_HOME}/staging/:
# deepdrft-public.tar.gz -- published self-contained linux-x64 binary tree
#
# DeepDrftPublic reads its API URL credential from environment/api.json at startup
# (populated by setup-step10-creds.sh). The env-file copy block below keeps it current.
#
# Paths are derived at runtime — no hardcoded usernames or home dirs.
# APP_HOME comes from $HOME (sshd sets this for the app user).
set -euo pipefail
export XDG_RUNTIME_DIR="/run/user/$(id -u)"
APP_HOME="${HOME}"
export PATH="${APP_HOME}/.local/bin:${PATH}"
STAGING="${APP_HOME}/staging"
APPROOT="${APP_HOME}/public"
ARCHIVE="deepdrft-public.tar.gz"
echo "[deploy-public] $(date -u +%Y-%m-%dT%H:%M:%SZ) starting"
# ── Swap in new binary tree ────────────────────────────────────────────────
rm -rf "${APPROOT}/bin.prev"
if [[ -d "${APPROOT}/bin" ]]; then
mv "${APPROOT}/bin" "${APPROOT}/bin.prev"
fi
mkdir -p "${APPROOT}/bin"
tar -xzf "${STAGING}/${ARCHIVE}" -C "${APPROOT}/bin"
rm -f "${STAGING}/${ARCHIVE}"
echo "[deploy-public] archive extracted"
# ── Apply environment files (host-managed, not in archive) ────────────────
if [[ -d "${APPROOT}/environment" ]]; then
shopt -s nullglob
env_files=("${APPROOT}/environment/"*)
shopt -u nullglob
if [[ ${#env_files[@]} -gt 0 ]]; then
mkdir -p "${APPROOT}/bin/environment"
cp "${env_files[@]}" "${APPROOT}/bin/environment/"
echo "[deploy-public] environment files applied"
fi
fi
# ── Enable and restart service ─────────────────────────────────────────────
systemctl --user enable deepdrftpublic.service
systemctl --user restart deepdrftpublic.service
systemctl --user is-active --quiet deepdrftpublic.service \
&& echo "[deploy-public] service is active" \
|| { echo "[deploy-public] ERROR: service failed to start" >&2; exit 1; }
echo "[deploy-public] done"