| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402 |
- #!/usr/bin/env bash
- # Run the four required installer scenarios in one disposable Debian systemd container.
- set -euo pipefail
- if [[ $# -ne 3 ]]; then
- echo "Usage: $0 NEW_ARCHIVE PREVIOUS_V0.1.1_ARCHIVE OUTPUT_DIR" >&2
- exit 2
- fi
- NEW_ARCHIVE="$(realpath -e -- "$1")"
- OLD_ARCHIVE="$(realpath -e -- "$2")"
- OUTPUT_DIR="$(realpath -m -- "$3")"
- SYSTEMD_IMAGE="${HTH_SYSTEMD_TEST_IMAGE:-localhost/hth-systemd-test:debian13}"
- RUN_ID="hth-install-matrix-$(date -u +%Y%m%dT%H%M%SZ)-$$"
- CONTAINER="$RUN_ID"
- LOG="$OUTPUT_DIR/matrix.log"
- RECEIPT="$OUTPUT_DIR/matrix-receipt.txt"
- command -v podman >/dev/null 2>&1 || { echo "podman is required" >&2; exit 2; }
- podman image exists "$SYSTEMD_IMAGE" || {
- echo "missing disposable systemd test image: $SYSTEMD_IMAGE" >&2
- exit 2
- }
- mkdir -p "$OUTPUT_DIR"
- : >"$LOG"
- cleanup() { podman rm -f "$CONTAINER" >/dev/null 2>&1 || true; }
- trap cleanup EXIT
- NEW_SHA="$(sha256sum "$NEW_ARCHIVE" | awk '{print $1}')"
- OLD_SHA="$(sha256sum "$OLD_ARCHIVE" | awk '{print $1}')"
- IMAGE_ID="$(podman image inspect --format '{{.Id}}' "$SYSTEMD_IMAGE")"
- podman run -d --name "$CONTAINER" --privileged --systemd=always --tmpfs /run --tmpfs /run/lock -v "$NEW_ARCHIVE:/packages/new.tar.gz:ro" -v "$OLD_ARCHIVE:/packages/old.tar.gz:ro" "$SYSTEMD_IMAGE" /sbin/init >/dev/null
- for _ in $(seq 1 100); do
- if podman exec "$CONTAINER" systemctl is-system-running >/dev/null 2>&1; then break; fi
- sleep 0.1
- done
- podman exec "$CONTAINER" bash -lc "
- set -e
- mkdir -p /opt/matrix/new /opt/matrix/old
- tar -xzf /packages/new.tar.gz -C /opt/matrix/new
- tar -xzf /packages/old.tar.gz -C /opt/matrix/old
- chmod +x /opt/matrix/new/*/*.sh /opt/matrix/old/*/*.sh
- " 2>&1 | tee -a "$LOG"
- run_guest() {
- local label="$1" command_text="$2"
- echo "${label}_BEGIN" | tee -a "$LOG"
- podman exec "$CONTAINER" bash -lc "$command_text" 2>&1 | tee -a "$LOG"
- echo "${label}_PASS" | tee -a "$LOG"
- }
- run_guest SCENARIO_SYMLINK_PATH_REJECTION '
- set -e
- cd /opt/matrix/new/*
- assert_symlink_rejected() {
- link_path="$1"
- outside_path="$2"
- mkdir -p "$(dirname "$link_path")" "$outside_path"
- printf "do-not-touch\n" >"$outside_path/sentinel"
- ln -s "$outside_path" "$link_path"
- if ./install.sh --no-start >/tmp/symlink-install.log 2>&1; then
- echo "install unexpectedly accepted symlink path: $link_path" >&2
- exit 1
- fi
- grep -Eq "symlink parent rejected|install path is a symlink" /tmp/symlink-install.log
- grep -Fxq "do-not-touch" "$outside_path/sentinel"
- [ "$(find "$outside_path" -mindepth 1 -maxdepth 1 -type f | wc -l)" -eq 1 ]
- unlink "$link_path"
- rm -f "$outside_path/sentinel"
- rmdir "$outside_path"
- }
- assert_symlink_rejected /usr/local/share/hth/sdk /opt/hth-outside-sdk
- assert_symlink_rejected /etc/hth/profiles /opt/hth-outside-profiles
- mkdir -p /var/lib/hth
- assert_symlink_rejected /var/lib/hth/captures /opt/hth-outside-captures
- rmdir /usr/local/share/hth /etc/hth /var/lib/hth 2>/dev/null || true
- '
- run_guest SCENARIO_FAKE_MANIFEST_REJECTION '
- set -e
- cd /opt/matrix/new/*
- mkdir -p /etc/hth /etc/systemd/system /usr/local/bin
- printf "unknown-binary\n" >/usr/local/bin/hthd
- cat >/etc/systemd/system/hthd.service <<"EOF"
- [Service]
- ExecStart=/usr/local/bin/hthd --config /etc/hth/hthd.yaml
- EOF
- printf "api_version: fake\n" >/etc/hth/hthd.yaml
- cat >/etc/hth/release-metadata.json <<"EOF"
- {
- "version": "v9.9.9",
- "source_commit": "0000000000000000000000000000000000000000"
- }
- EOF
- cat >/etc/hth/install-manifest.txt <<"EOF"
- file /usr/local/bin/hthd
- unknown /etc/hth/not-owned
- EOF
- before_binary="$(sha256sum /usr/local/bin/hthd | awk "{print \$1}")"
- before_unit="$(sha256sum /etc/systemd/system/hthd.service | awk "{print \$1}")"
- if ./install.sh --upgrade --no-start >/tmp/fake-manifest-upgrade.log 2>&1; then
- echo "upgrade unexpectedly accepted a fake manifest" >&2
- exit 1
- fi
- grep -Eq "unknown old manifest kind|old manifest is incomplete" /tmp/fake-manifest-upgrade.log
- [ "$before_binary" = "$(sha256sum /usr/local/bin/hthd | awk "{print \$1}")" ]
- [ "$before_unit" = "$(sha256sum /etc/systemd/system/hthd.service | awk "{print \$1}")" ]
- rm -f /usr/local/bin/hthd /etc/systemd/system/hthd.service \
- /etc/hth/hthd.yaml /etc/hth/release-metadata.json /etc/hth/install-manifest.txt
- rmdir /etc/hth 2>/dev/null || true
- '
- run_guest SCENARIO_CURRENT_PROFILE_SENTINEL_REJECTION '
- set -e
- cd /opt/matrix/new/*
- mkdir -p /etc/hth/profiles/6400-control
- printf "unknown-current-profile\n" >/etc/hth/profiles/6400-control/profile.json
- before_profile="$(sha256sum /etc/hth/profiles/6400-control/profile.json | awk "{print \$1}")"
- if ./install.sh --no-start >/tmp/current-profile-install.log 2>&1; then
- echo "fresh install unexpectedly overwrote an unknown current profile" >&2
- exit 1
- fi
- grep -Fq "an existing installation was found" /tmp/current-profile-install.log
- [ "$before_profile" = "$(sha256sum /etc/hth/profiles/6400-control/profile.json | awk "{print \$1}")" ]
- rm -f /etc/hth/profiles/6400-control/profile.json
- rmdir /etc/hth/profiles/6400-control /etc/hth/profiles /etc/hth
- '
- run_guest SCENARIO_MANAGED_TREE_SENTINEL_REJECTION '
- set -e
- cd /opt/matrix/new/*
- assert_managed_tree_rejected() {
- managed_path="$1"
- mkdir -p "$managed_path"
- printf "unknown-managed-state\n" >"$managed_path/unknown-sentinel"
- before_sentinel="$(sha256sum "$managed_path/unknown-sentinel" | awk "{print \$1}")"
- if ./install.sh --no-start >/tmp/managed-tree-install.log 2>&1; then
- echo "fresh install unexpectedly claimed an unknown managed tree: $managed_path" >&2
- exit 1
- fi
- grep -Fq "an existing installation was found" /tmp/managed-tree-install.log
- [ "$before_sentinel" = "$(sha256sum "$managed_path/unknown-sentinel" | awk "{print \$1}")" ]
- rm -f "$managed_path/unknown-sentinel"
- rmdir "$managed_path"
- }
- assert_managed_tree_rejected /run/hth
- assert_managed_tree_rejected /var/lib/hth/captures
- assert_managed_tree_rejected /var/lib/hth/replay
- assert_managed_tree_rejected /var/lib/hth/receipts
- rmdir /var/lib/hth 2>/dev/null || true
- '
- run_guest SCENARIO_UNKNOWN_LEGACY_PROFILE_PRESERVED '
- set -e
- cd /opt/matrix/new/*
- mkdir -p /etc/hth/profiles/prod2u-door-temp
- printf "unknown-user-profile\n" >/etc/hth/profiles/prod2u-door-temp/profile.json
- before_profile="$(sha256sum /etc/hth/profiles/prod2u-door-temp/profile.json | awk "{print \$1}")"
- ./install.sh
- if grep -Fq "/etc/hth/profiles/prod2u-door-temp" /etc/hth/install-manifest.txt; then
- echo "fresh install incorrectly claimed an unknown legacy profile" >&2
- exit 1
- fi
- ./uninstall.sh --purge --yes
- [ "$before_profile" = "$(sha256sum /etc/hth/profiles/prod2u-door-temp/profile.json | awk "{print \$1}")" ]
- rm -f /etc/hth/profiles/prod2u-door-temp/profile.json
- rmdir /etc/hth/profiles/prod2u-door-temp /etc/hth/profiles /etc/hth
- '
- run_guest SCENARIO_FAKE_MANIFEST_UNINSTALL_REJECTION '
- set -e
- cd /opt/matrix/new/*
- mkdir -p /etc/hth /usr/local/bin
- if ! getent group hth >/dev/null 2>&1; then groupadd --system hth; fi
- if ! getent passwd hth >/dev/null 2>&1; then
- useradd --system --gid hth --home-dir /var/lib/hth --shell /usr/sbin/nologin --no-create-home hth
- fi
- cp RELEASE-METADATA.json /etc/hth/release-metadata.json
- package_version="$(sed -n "s/^[[:space:]]*\"version\"[[:space:]]*:[[:space:]]*\"\([^\"]*\)\".*/\1/p" RELEASE-METADATA.json | head -n 1)"
- package_commit="$(sed -n "s/^[[:space:]]*\"source_commit\"[[:space:]]*:[[:space:]]*\"\([^\"]*\)\".*/\1/p" RELEASE-METADATA.json | head -n 1)"
- printf "unknown-binary\n" >/usr/local/bin/hthd
- cat >/etc/hth/install-manifest.txt <<EOF
- # HTH owned paths; generated by ${package_version} (${package_commit})
- file /usr/local/bin/hthd
- created_account hth
- created_group hth
- EOF
- before_binary="$(sha256sum /usr/local/bin/hthd | awk "{print \$1}")"
- before_identity="$(id -u hth):$(getent group hth | cut -d: -f3)"
- if ./uninstall.sh --purge --yes >/tmp/fake-manifest-uninstall.log 2>&1; then
- echo "uninstall unexpectedly accepted a partial fake manifest" >&2
- exit 1
- fi
- grep -Fq "immutable installed file does not match uninstall package" /tmp/fake-manifest-uninstall.log
- [ "$before_binary" = "$(sha256sum /usr/local/bin/hthd | awk "{print \$1}")" ]
- [ "$before_identity" = "$(id -u hth):$(getent group hth | cut -d: -f3)" ]
- cp bin/hthd /usr/local/bin/hthd
- mkdir -p /etc/hth/profiles/6400-control /usr/local/share/hth/sdk \
- /usr/lib/sysusers.d /usr/lib/tmpfiles.d
- package_wheel="$(find sdk -maxdepth 1 -type f -name "*.whl" -printf "%f\n")"
- cp bin/hthctl /usr/local/bin/hthctl
- cp bin/hth-capture /usr/local/bin/hth-capture
- cp service/hthd.service /etc/systemd/system/hthd.service
- cp service/hth.conf /usr/lib/sysusers.d/hth.conf
- cp service/hthd-tmpfiles.conf /usr/lib/tmpfiles.d/hth.conf
- cp profiles/6400-control/profile.json /etc/hth/profiles/6400-control/profile.json
- cp "sdk/$package_wheel" "/usr/local/share/hth/sdk/$package_wheel"
- if ./uninstall.sh --purge --yes >/tmp/identity-manifest-uninstall.log 2>&1; then
- echo "uninstall unexpectedly accepted a manifest-owned service identity" >&2
- exit 1
- fi
- grep -Fq "current manifest cannot claim service identity ownership" /tmp/identity-manifest-uninstall.log
- [ "$before_identity" = "$(id -u hth):$(getent group hth | cut -d: -f3)" ]
- sed -i "/^created_/d" /etc/hth/install-manifest.txt
- if ./uninstall.sh --purge --yes >/tmp/partial-manifest-uninstall.log 2>&1; then
- echo "uninstall unexpectedly accepted an incomplete current manifest" >&2
- exit 1
- fi
- grep -Fq "current manifest is incomplete" /tmp/partial-manifest-uninstall.log
- rm -f /usr/local/bin/hthd /usr/local/bin/hthctl /usr/local/bin/hth-capture \
- /etc/systemd/system/hthd.service /usr/lib/sysusers.d/hth.conf /usr/lib/tmpfiles.d/hth.conf \
- /etc/hth/profiles/6400-control/profile.json /etc/hth/install-manifest.txt \
- /etc/hth/release-metadata.json "/usr/local/share/hth/sdk/$package_wheel"
- rmdir /usr/local/share/hth/sdk /usr/local/share/hth \
- /etc/hth/profiles/6400-control /etc/hth/profiles /etc/hth
- userdel hth
- groupdel hth
- '
- run_guest SCENARIO_FULL_MANIFEST_PARTIAL_CLOSURE_REJECTION '
- set -e
- cd /opt/matrix/new/*
- package_version="$(sed -n "s/^[[:space:]]*\"version\"[[:space:]]*:[[:space:]]*\"\([^\"]*\)\".*/\1/p" RELEASE-METADATA.json | head -n 1)"
- package_commit="$(sed -n "s/^[[:space:]]*\"source_commit\"[[:space:]]*:[[:space:]]*\"\([^\"]*\)\".*/\1/p" RELEASE-METADATA.json | head -n 1)"
- package_wheel="$(find sdk -maxdepth 1 -type f -name "*.whl" -printf "%f\n")"
- mkdir -p /etc/hth/profiles/6400-control /etc/systemd/system /usr/local/bin \
- /usr/local/share/hth/sdk /usr/lib/sysusers.d /usr/lib/tmpfiles.d \
- /var/lib/hth/captures
- cp RELEASE-METADATA.json /etc/hth/release-metadata.json
- cp bin/hthd /usr/local/bin/hthd
- cp bin/hth-capture /usr/local/bin/hth-capture
- cp service/hthd.service /etc/systemd/system/hthd.service
- cp service/hth.conf /usr/lib/sysusers.d/hth.conf
- cp service/hthd-tmpfiles.conf /usr/lib/tmpfiles.d/hth.conf
- cp profiles/6400-control/profile.json /etc/hth/profiles/6400-control/profile.json
- cp "sdk/$package_wheel" "/usr/local/share/hth/sdk/$package_wheel"
- printf "unknown-managed-state\n" >/var/lib/hth/captures/unknown-sentinel
- before_sentinel="$(sha256sum /var/lib/hth/captures/unknown-sentinel | awk "{print \$1}")"
- cat >/etc/hth/install-manifest.txt <<EOF
- # HTH owned paths; generated by ${package_version} (${package_commit})
- 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
- file /usr/local/share/hth/sdk/${package_wheel}
- 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
- 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
- owned_dir /etc/hth
- owned_dir /var/lib/hth
- EOF
- if ./uninstall.sh --purge --yes >/tmp/partial-installed-closure.log 2>&1; then
- echo "uninstall unexpectedly accepted a full manifest with a partial installed closure" >&2
- exit 1
- fi
- grep -Fq "required immutable installed file is missing or not regular: /usr/local/bin/hthctl" \
- /tmp/partial-installed-closure.log
- [ "$before_sentinel" = "$(sha256sum /var/lib/hth/captures/unknown-sentinel | awk "{print \$1}")" ]
- rm -f /usr/local/bin/hthd /usr/local/bin/hth-capture \
- /etc/systemd/system/hthd.service /usr/lib/sysusers.d/hth.conf /usr/lib/tmpfiles.d/hth.conf \
- /etc/hth/profiles/6400-control/profile.json /etc/hth/release-metadata.json \
- /etc/hth/install-manifest.txt "/usr/local/share/hth/sdk/$package_wheel" \
- /var/lib/hth/captures/unknown-sentinel
- rmdir /usr/local/share/hth/sdk /usr/local/share/hth \
- /etc/hth/profiles/6400-control /etc/hth/profiles /etc/hth \
- /var/lib/hth/captures /var/lib/hth
- '
- run_guest SCENARIO_FRESH '
- set -e
- cd /opt/matrix/new/*
- ./install.sh
- ./verify-install.sh --no-escalate
- '
- run_guest SCENARIO_REINSTALL '
- set -e
- cd /opt/matrix/new/*
- ./install.sh
- ./verify-install.sh --no-escalate
- '
- run_guest SCENARIO_PURGE_REINSTALL '
- set -e
- cd /opt/matrix/new/*
- ./uninstall.sh --purge --yes
- ./install.sh
- ./verify-install.sh --no-escalate
- '
- run_guest SCENARIO_PREEXISTING_IDENTITIES '
- set -e
- cd /opt/matrix/new/*
- ./uninstall.sh --purge --yes
- for identity_name in hth hth-observe hth-control; do
- if ! getent group "$identity_name" >/dev/null 2>&1; then groupadd --system "$identity_name"; fi
- if ! getent passwd "$identity_name" >/dev/null 2>&1; then
- if [ "$identity_name" = hth ]; then identity_home=/var/lib/hth; else identity_home=/nonexistent; fi
- useradd --system --gid "$identity_name" --home-dir "$identity_home" \
- --shell /usr/sbin/nologin --no-create-home "$identity_name"
- fi
- done
- identity_snapshot() {
- for identity_name in hth hth-observe hth-control; do
- printf "%s:%s:%s\n" "$identity_name" "$(id -u "$identity_name")" \
- "$(getent group "$identity_name" | cut -d: -f3)"
- done
- }
- identities_before="$(identity_snapshot)"
- ./install.sh
- if grep -Eq "^(created_account|created_group|account|group) " /etc/hth/install-manifest.txt; then
- echo "service identity was incorrectly claimed by HTH" >&2
- exit 1
- fi
- ./uninstall.sh --purge --yes
- identities_after="$(identity_snapshot)"
- [ "$identities_before" = "$identities_after" ]
- for identity_name in hth hth-observe hth-control; do userdel "$identity_name"; done
- for identity_name in hth-control hth-observe hth; do groupdel "$identity_name"; done
- '
- run_guest SCENARIO_UPGRADE '
- set -e
- cd /opt/matrix/new/*
- ./uninstall.sh --purge --yes
- cd /opt/matrix/old/*
- if ./install.sh --backend mock >/tmp/previous-install.log 2>&1; then
- previous_direct=PASS
- else
- previous_direct=KNOWN_PROFILE_PERMISSION_FAILURE
- systemctl stop hthd.service >/dev/null 2>&1 || true
- chgrp hth /etc/hth/profiles/prod2u-door-temp/profile.json
- chmod 0640 /etc/hth/profiles/prod2u-door-temp/profile.json
- systemctl start hthd.service
- fi
- systemctl is-active --quiet hthd.service
- /usr/local/bin/hthctl --observe-sock /run/hth/observe/observe.sock --timeout 5s devices >/dev/null
- echo "PREVIOUS_RELEASE_RUNNING tag=v0.1.1 commit=7128a205a5cf70256bf6bb3cc87068b1d03e7fd4 direct_install=$previous_direct"
- cd /opt/matrix/new/*
- ./install.sh --upgrade
- ./verify-install.sh --no-escalate
- '
- run_guest SCENARIO_UPGRADE_FROM_FAILED_OLD '
- set -e
- cd /opt/matrix/new/*
- ./uninstall.sh --purge --yes
- cd /opt/matrix/old/*
- if ./install.sh --backend mock >/tmp/previous-failed-install.log 2>&1; then
- echo "expected v0.1.1 permission failure was not reproduced" >&2
- exit 1
- fi
- grep -q "Job for hthd.service failed" /tmp/previous-failed-install.log
- cd /opt/matrix/new/*
- ./install.sh --upgrade
- ./verify-install.sh --no-escalate
- '
- {
- echo "schema=hth-install-matrix-receipt-v1"
- echo "status=PASS"
- echo "run_id=$RUN_ID"
- echo "systemd_image=$SYSTEMD_IMAGE"
- echo "systemd_image_id=$IMAGE_ID"
- echo "new_archive=$NEW_ARCHIVE"
- echo "new_archive_sha256=$NEW_SHA"
- echo "previous_release_tag=v0.1.1"
- echo "previous_release_commit=7128a205a5cf70256bf6bb3cc87068b1d03e7fd4"
- echo "previous_archive=$OLD_ARCHIVE"
- echo "previous_archive_sha256=$OLD_SHA"
- echo "symlink_path_rejection=PASS"
- echo "fake_manifest_rejection=PASS"
- echo "fake_manifest_uninstall_rejection=PASS"
- echo "full_manifest_partial_closure_rejection=PASS"
- echo "current_profile_sentinel_rejection=PASS"
- echo "managed_tree_sentinel_rejection=PASS"
- echo "unknown_legacy_profile_preserved=PASS"
- echo "fresh_install=PASS"
- echo "same_version_reinstall=PASS"
- echo "purge_reinstall=PASS"
- echo "preexisting_identity_preservation=PASS"
- echo "previous_release_upgrade=PASS"
- echo "upgrade_from_failed_previous_install=PASS"
- echo "hardware_validation=NOT RUN"
- echo "com_validation=NOT RUN"
- echo "jtag_validation=NOT RUN"
- echo "real_thermal_performance=NOT RUN"
- echo "generated_at_utc=$(date -u +%Y-%m-%dT%H:%M:%SZ)"
- echo "log_sha256=$(sha256sum "$LOG" | awk '{print $1}')"
- } >"$RECEIPT"
- cat "$RECEIPT"
- echo "HTH_INSTALL_MATRIX_PASS"
|