| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454 |
- #!/usr/bin/env bash
- set -euo pipefail
- ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
- BINDIR=/usr/local/bin
- SHAREDIR=/usr/local/share/hth
- ETCDIR=/etc/hth
- UNITDIR=/etc/systemd/system
- LIBDIR=/usr/lib
- STATEDIR=/var/lib/hth
- RUNDIR=/run/hth
- SERVICE=hthd.service
- PREVIOUS_RELEASE_VERSION=v0.1.1
- PREVIOUS_RELEASE_COMMIT=7128a205a5cf70256bf6bb3cc87068b1d03e7fd4
- BACKEND=mock
- BACKEND_EXPLICIT=0
- SERIAL_PATH=/dev/hth/controller0
- NO_START=0
- UPGRADE=0
- usage() {
- cat >&2 <<'EOF'
- Usage: sudo ./install.sh [--upgrade] [--backend mock|serial]
- [--serial-path PATH] [--no-start]
- With no options this performs an idempotent 6400 Production Mock install.
- --upgrade migrates the previous formal release (v0.1.1) automatically.
- Serial mode is opt-in and requires an existing stable device path.
- EOF
- }
- while [[ $# -gt 0 ]]; do
- case "$1" in
- --upgrade) UPGRADE=1; shift ;;
- --backend) BACKEND="${2:-}"; BACKEND_EXPLICIT=1; shift 2 ;;
- --serial-path) SERIAL_PATH="${2:-}"; shift 2 ;;
- --no-start) NO_START=1; shift ;;
- -h|--help) usage; exit 0 ;;
- *) echo "install: unknown argument: $1" >&2; usage; exit 2 ;;
- esac
- done
- fail() { echo "install: $*" >&2; exit 1; }
- json_string() {
- local key="$1" file="$2"
- sed -n "s/^[[:space:]]*\"${key}\"[[:space:]]*:[[:space:]]*\"\([^\"]*\)\".*/\1/p" "$file" | head -n 1
- }
- no_symlink_parents() {
- local path="$1" parent
- parent="${path%/*}"
- [[ -n "$parent" ]] || parent=/
- while [[ "$parent" != / ]]; do
- if [[ -L "$parent" ]]; then
- echo "install: symlink parent rejected: $parent (target $path)" >&2
- return 1
- fi
- parent="${parent%/*}"
- [[ -n "$parent" ]] || parent=/
- done
- }
- safe_product_path() {
- local kind="$1" path="$2" resolved
- [[ "$path" == /* ]] || fail "non-absolute product path: $path"
- resolved="$(realpath -m -s -- "$path")"
- [[ "$resolved" == "$path" ]] || fail "unresolved product path rejected: $path -> $resolved"
- no_symlink_parents "$resolved" || fail "unsafe symlink parent for product path: $resolved"
- case "$kind:$resolved" in
- file:/usr/local/bin/hthd|file:/usr/local/bin/hthctl|file:/usr/local/bin/hth-capture|\
- file:/etc/systemd/system/hthd.service|\
- file:/usr/lib/sysusers.d/hth.conf|file:/usr/lib/tmpfiles.d/hth.conf|\
- config:/etc/hth/hthd.yaml|config:/etc/hth/release-metadata.json|\
- config:/etc/hth/install-manifest.txt|\
- config:/etc/hth/profiles/6400-control/profile.json|\
- config:/etc/hth/profiles/prod2u-door-temp/profile.json|\
- symlink:/etc/systemd/system/multi-user.target.wants/hthd.service|\
- managed_tree:/run/hth|managed_tree:/var/lib/hth/captures|\
- managed_tree:/var/lib/hth/replay|managed_tree:/var/lib/hth/receipts|\
- owned_dir:/usr/local/share/hth/sdk|owned_dir:/usr/local/share/hth|\
- owned_dir:/etc/hth/profiles/6400-control|\
- owned_dir:/etc/hth/profiles/prod2u-door-temp|owned_dir:/etc/hth/profiles|\
- owned_dir:/etc/hth|owned_dir:/var/lib/hth) return 0 ;;
- file:/usr/local/share/hth/sdk/hth_sdk-*.whl)
- [[ "${resolved#/usr/local/share/hth/sdk/}" != */* ]] ||
- fail "nested SDK wheel path rejected: $resolved"
- return 0
- ;;
- *) fail "product path outside upgrade allowlist: $kind $resolved" ;;
- esac
- }
- remove_product_path() {
- local kind="$1" path="$2"
- safe_product_path "$kind" "$path"
- case "$kind" in
- file|config|symlink) rm -f -- "$path" ;;
- managed_tree)
- if [[ -e "$path" || -L "$path" ]]; then
- rm -rf --one-file-system -- "$path"
- fi
- ;;
- owned_dir) rmdir -- "$path" 2>/dev/null || true ;;
- *) fail "unsupported product removal kind: $kind" ;;
- esac
- }
- identity_allowed() {
- case "$1:$2" in
- created_account:hth|created_account:hth-observe|created_account:hth-control|\
- created_group:hth|created_group:hth-observe|created_group:hth-control) return 0 ;;
- *) fail "identity outside product allowlist: $1 $2" ;;
- esac
- }
- verify_legacy_v011() {
- local kind path expected actual
- while read -r kind path expected; do
- safe_product_path "$kind" "$path"
- [[ -f "$path" ]] || fail "legacy v0.1.1 fingerprint missing file: $path"
- actual="$(sha256sum "$path" | awk '{print $1}')"
- [[ "$actual" == "$expected" ]] ||
- fail "legacy v0.1.1 fingerprint mismatch: $path"
- done <<'EOF'
- file /usr/local/bin/hthd 498ee4146b2d44490d58d0e13404978331772fd85bf546f5eea7cdded8c55ad8
- file /usr/local/bin/hthctl b57403ff3d3dfc0163aba4b35af33d26cb9aa64e54e4017e52f124aae0cf2421
- file /usr/local/bin/hth-capture 382e3e72f61732d26ce77b50323432c8ad534dffba2bea6b9ec029f89fcd1f43
- file /etc/systemd/system/hthd.service a6a83979d4d2195adf4704719dc750c0abdd48e803f6f8cc178234695d4afc7e
- file /usr/lib/sysusers.d/hth.conf 4894e25647825ea614f8ffaffd72c66b0dc31c6efda1c8481dddd2316a07ae96
- file /usr/lib/tmpfiles.d/hth.conf 3c783b5dfb7a17ed1f44eccb1956c5a8ec25e5daebab5d5287111c1387166364
- config /etc/hth/profiles/prod2u-door-temp/profile.json 348a07b6b23a9fd3e860b830c15e0bdea17d1da5f28a380bea4065f6fbe800ac
- EOF
- safe_product_path config "$ETCDIR/hthd.yaml"
- [[ -f "$ETCDIR/hthd.yaml" ]] || fail "legacy v0.1.1 config is missing"
- grep -Fqx 'api_version: hth.api.v1' "$ETCDIR/hthd.yaml" ||
- fail "legacy v0.1.1 config API marker mismatch"
- grep -Fqx 'profile: /etc/hth/profiles/prod2u-door-temp/profile.json' "$ETCDIR/hthd.yaml" ||
- fail "legacy v0.1.1 config profile marker mismatch"
- if [[ -e "$UNITDIR/hthd@.service" || -L "$UNITDIR/hthd@.service" ]]; then
- fail "unexpected hthd@.service beside legacy v0.1.1; refusing ambiguous upgrade"
- fi
- }
- [[ "$(uname -m)" == x86_64 ]] || fail "this release targets x86_64 Linux (found $(uname -m))"
- [[ "$(id -u)" -eq 0 ]] || fail "run as root, for example: sudo ./install.sh"
- [[ -f "$ROOT/RELEASE-METADATA.json" ]] || fail "package is missing RELEASE-METADATA.json"
- VERSION="$(json_string version "$ROOT/RELEASE-METADATA.json")"
- SOURCE_COMMIT="$(json_string source_commit "$ROOT/RELEASE-METADATA.json")"
- [[ -n "$VERSION" && -n "$SOURCE_COMMIT" ]] || fail "invalid release metadata"
- case "$BACKEND" in mock|serial) ;; *) fail "--backend must be mock or serial" ;; esac
- [[ "$SERIAL_PATH" != *$'\n'* && "$SERIAL_PATH" != *'|'* ]] || fail "unsafe serial path"
- if [[ "$BACKEND" == serial && ! -e "$SERIAL_PATH" ]]; then
- fail "serial device does not exist: $SERIAL_PATH"
- fi
- for command_name in realpath readlink sha256sum systemctl systemd-sysusers systemd-tmpfiles \
- base64 find getent groupadd awk basename grep; do
- command -v "$command_name" >/dev/null 2>&1 || fail "required command is missing: $command_name"
- done
- shopt -s nullglob
- PACKAGE_WHEELS=("$ROOT"/sdk/*.whl)
- shopt -u nullglob
- [[ "${#PACKAGE_WHEELS[@]}" -eq 1 ]] || fail "package must contain exactly one Python SDK wheel"
- PACKAGE_WHEEL="${PACKAGE_WHEELS[0]}"
- for required in \
- "$ROOT/bin/hthd" "$ROOT/bin/hthctl" "$ROOT/bin/hth-capture" \
- "$ROOT/config/hthd.6400-mock.yaml" "$ROOT/config/hthd.6400-serial.yaml" \
- "$ROOT/service/hthd.service" "$ROOT/service/hth.conf" \
- "$ROOT/service/hthd-tmpfiles.conf" "$ROOT/profiles/6400-control/profile.json" \
- "$PACKAGE_WHEEL" "$ROOT/verify-install.sh"; do
- [[ -f "$required" ]] || fail "package is incomplete: $required"
- done
- if [[ -f "$ROOT/SHA256SUMS" ]]; then
- (cd "$ROOT" && sha256sum -c SHA256SUMS >/dev/null) || fail "package checksum verification failed"
- fi
- for absolute_dir in \
- "$BINDIR" "$SHAREDIR" "$SHAREDIR/sdk" \
- "$ETCDIR" "$ETCDIR/profiles" "$ETCDIR/profiles/6400-control" \
- "$UNITDIR" "$UNITDIR/multi-user.target.wants" \
- "$LIBDIR/sysusers.d" "$LIBDIR/tmpfiles.d" \
- "$STATEDIR" "$STATEDIR/captures" "$STATEDIR/replay" "$STATEDIR/receipts" \
- "$RUNDIR" "$RUNDIR/observe" "$RUNDIR/control"; do
- [[ "$absolute_dir" == /* && "$(realpath -m -s -- "$absolute_dir")" == "$absolute_dir" ]] ||
- fail "unsafe install path: $absolute_dir"
- no_symlink_parents "$absolute_dir" || fail "unsafe symlink parent for install path: $absolute_dir"
- [[ ! -L "$absolute_dir" ]] || fail "install path is a symlink: $absolute_dir"
- done
- INSTALLED_META="$ETCDIR/release-metadata.json"
- OLD_MANIFEST="$ETCDIR/install-manifest.txt"
- INSTALLED_VERSION=""
- INSTALLED_COMMIT=""
- if [[ -f "$INSTALLED_META" ]]; then
- INSTALLED_VERSION="$(json_string version "$INSTALLED_META")"
- INSTALLED_COMMIT="$(json_string source_commit "$INSTALLED_META")"
- fi
- FOOTPRINT=0
- for path in "$BINDIR/hthd" "$BINDIR/hthctl" "$BINDIR/hth-capture" \
- "$UNITDIR/hthd.service" "$UNITDIR/hthd@.service" \
- "$UNITDIR/multi-user.target.wants/hthd.service" \
- "$LIBDIR/sysusers.d/hth.conf" "$LIBDIR/tmpfiles.d/hth.conf" \
- "$ETCDIR/hthd.yaml" "$ETCDIR/release-metadata.json" \
- "$ETCDIR/install-manifest.txt" \
- "$ETCDIR/profiles/6400-control/profile.json" \
- "$RUNDIR" "$STATEDIR/captures" "$STATEDIR/replay" \
- "$STATEDIR/receipts" \
- "$SHAREDIR/sdk/$(basename "$PACKAGE_WHEEL")"; do
- [[ -e "$path" || -L "$path" ]] && FOOTPRINT=1
- done
- if [[ -d "$SHAREDIR/sdk" ]] &&
- find "$SHAREDIR/sdk" -maxdepth 1 -type f -name 'hth_sdk-*.whl' -print -quit | grep -q .; then
- FOOTPRINT=1
- fi
- declare -A OLD_MANIFEST_ENTRIES=()
- declare -a OWNED_WHEELS=()
- WANTS_MANIFEST_KEY="symlink $UNITDIR/multi-user.target.wants/hthd.service"
- if [[ -f "$OLD_MANIFEST" ]]; then
- safe_product_path config "$INSTALLED_META"
- safe_product_path config "$OLD_MANIFEST"
- [[ -f "$INSTALLED_META" ]] || fail "trusted install manifest requires release metadata"
- [[ "$INSTALLED_VERSION" =~ ^v[0-9][0-9A-Za-z.+-]*$ ]] ||
- fail "installed release metadata has an invalid version"
- [[ "$INSTALLED_COMMIT" =~ ^[0-9a-f]{40}([0-9a-f]{24})?$ ]] ||
- fail "installed release metadata has an invalid source_commit"
- OLD_WHEEL_COUNT=0
- while read -r old_kind old_value old_extra; do
- [[ -z "$old_kind" || "$old_kind" == \#* ]] && continue
- [[ -n "$old_value" && -z "${old_extra:-}" ]] ||
- fail "malformed old manifest line: $old_kind $old_value ${old_extra:-}"
- if [[ "$old_kind:$old_value" == "config:$ETCDIR/profiles/prod2u-door-temp/profile.json" ||
- "$old_kind:$old_value" == "owned_dir:$ETCDIR/profiles/prod2u-door-temp" ]]; then
- fail "old manifest claims an unowned legacy door-temperature path: $old_kind $old_value"
- fi
- case "$old_kind" in
- file|config|symlink|managed_tree|owned_dir)
- safe_product_path "$old_kind" "$old_value"
- ;;
- created_account)
- identity_allowed "$old_kind" "$old_value"
- ;;
- created_group)
- identity_allowed "$old_kind" "$old_value"
- ;;
- account|group)
- [[ "$old_value" == hth || "$old_value" == hth-observe || "$old_value" == hth-control ]] ||
- fail "legacy manifest identity outside product allowlist: $old_kind $old_value"
- ;;
- *) fail "unknown old manifest kind: $old_kind" ;;
- esac
- manifest_key="$old_kind $old_value"
- [[ -z "${OLD_MANIFEST_ENTRIES[$manifest_key]:-}" ]] ||
- fail "duplicate old manifest entry: $manifest_key"
- OLD_MANIFEST_ENTRIES["$manifest_key"]=1
- if [[ "$old_kind" == file && "$old_value" == "$SHAREDIR"/sdk/hth_sdk-*.whl ]]; then
- OWNED_WHEELS+=("$old_value")
- ((OLD_WHEEL_COUNT += 1))
- fi
- done <"$OLD_MANIFEST"
- while read -r required_kind required_path; do
- required_key="$required_kind $required_path"
- [[ "${OLD_MANIFEST_ENTRIES[$required_key]:-0}" -eq 1 ]] ||
- fail "old manifest is incomplete: $required_key"
- done <<EOF
- file $BINDIR/hthd
- file $BINDIR/hthctl
- file $BINDIR/hth-capture
- file $UNITDIR/hthd.service
- file $LIBDIR/sysusers.d/hth.conf
- file $LIBDIR/tmpfiles.d/hth.conf
- config $ETCDIR/hthd.yaml
- config $ETCDIR/release-metadata.json
- config $ETCDIR/install-manifest.txt
- config $ETCDIR/profiles/6400-control/profile.json
- managed_tree $RUNDIR
- managed_tree $STATEDIR/captures
- managed_tree $STATEDIR/replay
- managed_tree $STATEDIR/receipts
- owned_dir $SHAREDIR/sdk
- owned_dir $SHAREDIR
- owned_dir $ETCDIR/profiles/6400-control
- owned_dir $ETCDIR/profiles
- owned_dir $ETCDIR
- owned_dir $STATEDIR
- EOF
- [[ "$OLD_WHEEL_COUNT" -eq 1 ]] || fail "old manifest must contain exactly one owned SDK wheel"
- fi
- ACTION=install
- FROM_VERSION=none
- PRESERVE_CONFIG=0
- if [[ "$FOOTPRINT" -eq 1 ]]; then
- if [[ "$INSTALLED_VERSION" == "$VERSION" && "$INSTALLED_COMMIT" == "$SOURCE_COMMIT" && "$UPGRADE" -eq 0 ]]; then
- ACTION=reinstall
- FROM_VERSION="$INSTALLED_VERSION"
- PRESERVE_CONFIG=1
- elif [[ "$UPGRADE" -eq 1 ]]; then
- ACTION=upgrade
- FROM_VERSION="${INSTALLED_VERSION:-$PREVIOUS_RELEASE_VERSION}"
- else
- fail "an existing installation was found; use --upgrade for a different/legacy version"
- fi
- elif [[ "$UPGRADE" -eq 1 ]]; then
- fail "--upgrade requested but no existing HTH installation was found"
- fi
- if [[ "$ACTION" == reinstall && "$BACKEND_EXPLICIT" -eq 1 ]]; then
- PRESERVE_CONFIG=0
- fi
- if [[ -f "$UNITDIR/hthd.service" ]] && ! grep -Fq '/usr/local/bin/hthd --config /etc/hth/hthd.yaml' "$UNITDIR/hthd.service"; then
- fail "existing hthd.service is not the recognized HTH unit; refusing to overwrite it"
- fi
- if [[ -e "$UNITDIR/hthd@.service" || -L "$UNITDIR/hthd@.service" ]]; then
- fail "unexpected hthd@.service; refusing to overwrite an ambiguous installation"
- fi
- if [[ "$ACTION" == upgrade && ! -f "$OLD_MANIFEST" ]]; then
- verify_legacy_v011
- fi
- if [[ "$ACTION" == upgrade && -f "$OLD_MANIFEST" ]]; then
- for path in "$BINDIR/hthd" "$BINDIR/hthctl" "$BINDIR/hth-capture" \
- "$UNITDIR/hthd.service" "$ETCDIR/hthd.yaml" "$INSTALLED_META" \
- "$ETCDIR/profiles/6400-control/profile.json" "${OWNED_WHEELS[@]}"; do
- [[ -f "$path" ]] || fail "trusted manifest footprint is incomplete at upgrade: $path"
- done
- fi
- systemctl disable --now "$SERVICE" >/dev/null 2>&1 || true
- if systemctl is-active --quiet "$SERVICE"; then
- fail "$SERVICE is still active after stop"
- fi
- if [[ "$ACTION" == upgrade ]]; then
- for path in "$BINDIR/hthd" "$BINDIR/hthctl" "$BINDIR/hth-capture" \
- "$UNITDIR/hthd.service" \
- "$LIBDIR/sysusers.d/hth.conf" "$LIBDIR/tmpfiles.d/hth.conf"; do
- remove_product_path file "$path"
- done
- if [[ ! -f "$OLD_MANIFEST" || "${OLD_MANIFEST_ENTRIES[$WANTS_MANIFEST_KEY]:-0}" -eq 1 ]]; then
- remove_product_path symlink "$UNITDIR/multi-user.target.wants/hthd.service"
- fi
- for path in "$ETCDIR/hthd.yaml" "$ETCDIR/release-metadata.json" \
- "$ETCDIR/install-manifest.txt" \
- "$ETCDIR/profiles/6400-control/profile.json"; do
- remove_product_path config "$path"
- done
- if [[ ! -f "$OLD_MANIFEST" ]]; then
- remove_product_path config "$ETCDIR/profiles/prod2u-door-temp/profile.json"
- remove_product_path owned_dir "$ETCDIR/profiles/prod2u-door-temp"
- fi
- remove_product_path managed_tree "$RUNDIR"
- systemctl daemon-reload
- fi
- install -d -m 0755 "$BINDIR" "$SHAREDIR/sdk" "$UNITDIR" "$LIBDIR/sysusers.d" "$LIBDIR/tmpfiles.d"
- install -d -m 0750 "$ETCDIR" "$ETCDIR/profiles" "$ETCDIR/profiles/6400-control"
- install -d -m 0750 "$STATEDIR" "$STATEDIR/captures" "$STATEDIR/replay" "$STATEDIR/receipts"
- install -m 0755 "$ROOT/bin/hthd" "$BINDIR/hthd"
- install -m 0755 "$ROOT/bin/hthctl" "$BINDIR/hthctl"
- install -m 0755 "$ROOT/bin/hth-capture" "$BINDIR/hth-capture"
- install -m 0644 "$ROOT/service/hthd.service" "$UNITDIR/hthd.service"
- install -m 0644 "$ROOT/service/hth.conf" "$LIBDIR/sysusers.d/hth.conf"
- install -m 0644 "$ROOT/service/hthd-tmpfiles.conf" "$LIBDIR/tmpfiles.d/hth.conf"
- install -m 0644 "$ROOT/RELEASE-METADATA.json" "$ETCDIR/release-metadata.json"
- install -m 0644 "$ROOT/profiles/6400-control/profile.json" "$ETCDIR/profiles/6400-control/profile.json"
- for path in "${OWNED_WHEELS[@]}"; do remove_product_path file "$path"; done
- install -m 0644 "$PACKAGE_WHEEL" "$SHAREDIR/sdk/"
- if [[ "$PRESERVE_CONFIG" -eq 0 || ! -f "$ETCDIR/hthd.yaml" ]]; then
- template="$ROOT/config/hthd.6400-${BACKEND}.yaml"
- temp_config="$(mktemp -t hth-install-config.XXXXXX)"
- trap 'rm -f "${temp_config:-}"' EXIT
- if [[ "$BACKEND" == serial ]]; then
- sed "s|@SERIAL_PATH@|$SERIAL_PATH|g" "$template" >"$temp_config"
- else
- cp "$template" "$temp_config"
- fi
- install -m 0640 "$temp_config" "$ETCDIR/hthd.yaml"
- fi
- getent group dialout >/dev/null 2>&1 || groupadd --system dialout
- systemd-sysusers "$LIBDIR/sysusers.d/hth.conf"
- systemd-tmpfiles --create "$LIBDIR/tmpfiles.d/hth.conf"
- cat >"$ETCDIR/install-manifest.txt" <<EOF
- # HTH owned paths; generated by ${VERSION} (${SOURCE_COMMIT})
- file $BINDIR/hthd
- file $BINDIR/hthctl
- file $BINDIR/hth-capture
- file $UNITDIR/hthd.service
- file $LIBDIR/sysusers.d/hth.conf
- file $LIBDIR/tmpfiles.d/hth.conf
- file $SHAREDIR/sdk/$(basename "$PACKAGE_WHEEL")
- config $ETCDIR/hthd.yaml
- config $ETCDIR/release-metadata.json
- config $ETCDIR/install-manifest.txt
- config $ETCDIR/profiles/6400-control/profile.json
- managed_tree $RUNDIR
- managed_tree $STATEDIR/captures
- managed_tree $STATEDIR/replay
- managed_tree $STATEDIR/receipts
- owned_dir $SHAREDIR/sdk
- owned_dir $SHAREDIR
- owned_dir $ETCDIR/profiles/6400-control
- owned_dir $ETCDIR/profiles
- owned_dir $ETCDIR
- owned_dir $STATEDIR
- EOF
- chmod 0644 "$ETCDIR/install-manifest.txt"
- chown root:hth "$ETCDIR" "$ETCDIR/hthd.yaml" "$ETCDIR/profiles" "$ETCDIR/profiles/6400-control" 2>/dev/null || true
- chown hth:hth "$STATEDIR" "$STATEDIR/captures" "$STATEDIR/replay" "$STATEDIR/receipts" 2>/dev/null || true
- chmod 0750 "$ETCDIR" "$ETCDIR/profiles" "$ETCDIR/profiles/6400-control"
- chmod 0640 "$ETCDIR/hthd.yaml"
- "$BINDIR/hthd" --check-config --config "$ETCDIR/hthd.yaml"
- systemctl daemon-reload
- if [[ "$NO_START" -eq 0 ]]; then
- systemctl enable --now "$SERVICE"
- for _ in $(seq 1 50); do
- systemctl is-active --quiet "$SERVICE" && break
- sleep 0.1
- done
- systemctl is-active --quiet "$SERVICE" || {
- journalctl -u "$SERVICE" -n 80 --no-pager >&2 || true
- fail "$SERVICE did not become active"
- }
- fi
- if [[ -L "$UNITDIR/multi-user.target.wants/hthd.service" ]]; then
- safe_product_path symlink "$UNITDIR/multi-user.target.wants/hthd.service"
- echo "symlink $UNITDIR/multi-user.target.wants/hthd.service" >>"$ETCDIR/install-manifest.txt"
- fi
- receipt="$STATEDIR/receipts/install-latest.txt"
- EFFECTIVE_BACKEND="$(sed -n 's/^[[:space:]]*backend:[[:space:]]*//p' "$ETCDIR/hthd.yaml" | head -n 1)"
- {
- echo "schema=hth-install-receipt-v1"
- echo "status=PASS"
- echo "action=$ACTION"
- echo "from_version=$FROM_VERSION"
- echo "version=$VERSION"
- echo "source_commit=$SOURCE_COMMIT"
- echo "backend=$EFFECTIVE_BACKEND"
- echo "service=$SERVICE"
- echo "config=$ETCDIR/hthd.yaml"
- echo "generated_at_utc=$(date -u +%Y-%m-%dT%H:%M:%SZ)"
- } >"$receipt"
- chown hth:hth "$receipt" 2>/dev/null || true
- chmod 0644 "$receipt"
- if [[ "$NO_START" -eq 0 ]]; then
- "$ROOT/verify-install.sh" --no-escalate
- fi
- echo "HTH_INSTALL_PASS action=$ACTION from=$FROM_VERSION version=$VERSION backend=$EFFECTIVE_BACKEND"
|