#!/usr/bin/env bash # Launch the hsa-app binary with its environment loaded from an env file. # # Usage: # hsa-app.sh [ENV_FILE] # # ENV_FILE resolves to, in order: the first argument, then $HSA_ENV_FILE, then # /etc/hsa-app/hsa-app.env. The binary defaults to ./hsa next to this script; # override with $HSA_BIN (e.g. HSA_BIN=/usr/local/bin/hsa). # # Designed as a systemd ExecStart: it exports every KEY=VALUE in the env file and # then exec's the binary, so the binary becomes the unit's main process (signals # and exit codes propagate correctly). The env file should use ABSOLUTE paths for # DB_PATH / STORAGE_DIR / BACKUP_DIR / CONFIG_PATH, since the app resolves relative # paths from the working directory. set -euo pipefail ENV_FILE="${1:-${HSA_ENV_FILE:-/etc/hsa-app/hsa-app.env}}" HERE="$(cd "$(dirname "$(readlink -f "$0")")" && pwd)" BIN="${HSA_BIN:-$HERE/hsa}" if [[ ! -r "$ENV_FILE" ]]; then echo "hsa-app: env file not found or unreadable: $ENV_FILE" >&2 exit 1 fi if [[ ! -x "$BIN" ]]; then echo "hsa-app: binary not found or not executable: $BIN" >&2 exit 1 fi # Export every assignment in the env file (KEY=VALUE lines; '#' comments and blank # lines are fine). set -a marks all subsequently-set vars for export. set -a # shellcheck disable=SC1090 source "$ENV_FILE" set +a exec "$BIN"