#!/usr/bin/env bash
set -euo pipefail

root=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)
[[ $(id -u) -eq 0 ]] || { echo 'run as root on the production server' >&2; exit 1; }

install -d -m 0755 /usr/local/lib/easyai-ai-gateway-release
install -m 0755 "$root/deploy/manual/easyai-ai-gateway-release" \
  /usr/local/sbin/easyai-ai-gateway-release
install -m 0644 "$root/scripts/release-manifest.mjs" \
  /usr/local/lib/easyai-ai-gateway-release/release-manifest.mjs
if [[ ! -e /etc/easyai-ai-gateway-release.conf ]]; then
  install -m 0600 "$root/deploy/manual/easyai-ai-gateway-release.conf.example" \
    /etc/easyai-ai-gateway-release.conf
  echo 'created /etc/easyai-ai-gateway-release.conf; review it before the first release'
fi

echo 'installed manual release helper; no service, timer, webhook, or watcher was enabled'
