run_amd64_release_matrix.sh 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #!/usr/bin/env bash
  2. # Run the four required installer scenarios in one disposable Debian systemd container.
  3. set -euo pipefail
  4. if [[ $# -ne 3 ]]; then
  5. echo "Usage: $0 NEW_ARCHIVE PREVIOUS_V0.1.1_ARCHIVE OUTPUT_DIR" >&2
  6. exit 2
  7. fi
  8. NEW_ARCHIVE="$(realpath -e -- "$1")"
  9. OLD_ARCHIVE="$(realpath -e -- "$2")"
  10. OUTPUT_DIR="$(realpath -m -- "$3")"
  11. SYSTEMD_IMAGE="${HTH_SYSTEMD_TEST_IMAGE:-localhost/hth-systemd-test:debian13}"
  12. RUN_ID="hth-install-matrix-$(date -u +%Y%m%dT%H%M%SZ)-$$"
  13. CONTAINER="$RUN_ID"
  14. LOG="$OUTPUT_DIR/matrix.log"
  15. RECEIPT="$OUTPUT_DIR/matrix-receipt.txt"
  16. command -v podman >/dev/null 2>&1 || { echo "podman is required" >&2; exit 2; }
  17. podman image exists "$SYSTEMD_IMAGE" || {
  18. echo "missing disposable systemd test image: $SYSTEMD_IMAGE" >&2
  19. exit 2
  20. }
  21. mkdir -p "$OUTPUT_DIR"
  22. : >"$LOG"
  23. cleanup() { podman rm -f "$CONTAINER" >/dev/null 2>&1 || true; }
  24. trap cleanup EXIT
  25. NEW_SHA="$(sha256sum "$NEW_ARCHIVE" | awk '{print $1}')"
  26. OLD_SHA="$(sha256sum "$OLD_ARCHIVE" | awk '{print $1}')"
  27. IMAGE_ID="$(podman image inspect --format '{{.Id}}' "$SYSTEMD_IMAGE")"
  28. 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
  29. for _ in $(seq 1 100); do
  30. if podman exec "$CONTAINER" systemctl is-system-running >/dev/null 2>&1; then break; fi
  31. sleep 0.1
  32. done
  33. podman exec "$CONTAINER" bash -lc "
  34. set -e
  35. mkdir -p /opt/matrix/new /opt/matrix/old
  36. tar -xzf /packages/new.tar.gz -C /opt/matrix/new
  37. tar -xzf /packages/old.tar.gz -C /opt/matrix/old
  38. chmod +x /opt/matrix/new/*/*.sh /opt/matrix/old/*/*.sh
  39. " 2>&1 | tee -a "$LOG"
  40. run_guest() {
  41. local label="$1" command_text="$2"
  42. echo "${label}_BEGIN" | tee -a "$LOG"
  43. podman exec "$CONTAINER" bash -lc "$command_text" 2>&1 | tee -a "$LOG"
  44. echo "${label}_PASS" | tee -a "$LOG"
  45. }
  46. run_guest SCENARIO_FRESH '
  47. set -e
  48. cd /opt/matrix/new/*
  49. ./install.sh
  50. ./verify-install.sh --no-escalate
  51. '
  52. run_guest SCENARIO_REINSTALL '
  53. set -e
  54. cd /opt/matrix/new/*
  55. ./install.sh
  56. ./verify-install.sh --no-escalate
  57. '
  58. run_guest SCENARIO_PURGE_REINSTALL '
  59. set -e
  60. cd /opt/matrix/new/*
  61. ./uninstall.sh --purge --yes
  62. ./install.sh
  63. ./verify-install.sh --no-escalate
  64. '
  65. run_guest SCENARIO_PREEXISTING_IDENTITIES '
  66. set -e
  67. cd /opt/matrix/new/*
  68. ./uninstall.sh --purge --yes
  69. for identity_name in hth hth-observe hth-control; do
  70. groupadd --system "$identity_name"
  71. if [ "$identity_name" = hth ]; then identity_home=/var/lib/hth; else identity_home=/nonexistent; fi
  72. useradd --system --gid "$identity_name" --home-dir "$identity_home" \
  73. --shell /usr/sbin/nologin --no-create-home "$identity_name"
  74. done
  75. identity_snapshot() {
  76. for identity_name in hth hth-observe hth-control; do
  77. printf "%s:%s:%s\n" "$identity_name" "$(id -u "$identity_name")" \
  78. "$(getent group "$identity_name" | cut -d: -f3)"
  79. done
  80. }
  81. identities_before="$(identity_snapshot)"
  82. ./install.sh
  83. if grep -Eq "^created_(account|group) (hth|hth-observe|hth-control)$" /etc/hth/install-manifest.txt; then
  84. echo "pre-existing identity was incorrectly claimed by HTH" >&2
  85. exit 1
  86. fi
  87. ./uninstall.sh --purge --yes
  88. identities_after="$(identity_snapshot)"
  89. [ "$identities_before" = "$identities_after" ]
  90. for identity_name in hth hth-observe hth-control; do userdel "$identity_name"; done
  91. for identity_name in hth-control hth-observe hth; do groupdel "$identity_name"; done
  92. '
  93. run_guest SCENARIO_UPGRADE '
  94. set -e
  95. cd /opt/matrix/new/*
  96. ./uninstall.sh --purge --yes
  97. cd /opt/matrix/old/*
  98. if ./install.sh --backend mock >/tmp/previous-install.log 2>&1; then
  99. previous_direct=PASS
  100. else
  101. previous_direct=KNOWN_PROFILE_PERMISSION_FAILURE
  102. systemctl stop hthd.service >/dev/null 2>&1 || true
  103. chgrp hth /etc/hth/profiles/prod2u-door-temp/profile.json
  104. chmod 0640 /etc/hth/profiles/prod2u-door-temp/profile.json
  105. systemctl start hthd.service
  106. fi
  107. systemctl is-active --quiet hthd.service
  108. /usr/local/bin/hthctl --observe-sock /run/hth/observe/observe.sock --timeout 5s devices >/dev/null
  109. echo "PREVIOUS_RELEASE_RUNNING tag=v0.1.1 commit=7128a205a5cf70256bf6bb3cc87068b1d03e7fd4 direct_install=$previous_direct"
  110. cd /opt/matrix/new/*
  111. ./install.sh --upgrade
  112. ./verify-install.sh --no-escalate
  113. '
  114. run_guest SCENARIO_UPGRADE_FROM_FAILED_OLD '
  115. set -e
  116. cd /opt/matrix/new/*
  117. ./uninstall.sh --purge --yes
  118. cd /opt/matrix/old/*
  119. if ./install.sh --backend mock >/tmp/previous-failed-install.log 2>&1; then
  120. echo "expected v0.1.1 permission failure was not reproduced" >&2
  121. exit 1
  122. fi
  123. grep -q "Job for hthd.service failed" /tmp/previous-failed-install.log
  124. cd /opt/matrix/new/*
  125. ./install.sh --upgrade
  126. ./verify-install.sh --no-escalate
  127. '
  128. {
  129. echo "schema=hth-install-matrix-receipt-v1"
  130. echo "status=PASS"
  131. echo "run_id=$RUN_ID"
  132. echo "systemd_image=$SYSTEMD_IMAGE"
  133. echo "systemd_image_id=$IMAGE_ID"
  134. echo "new_archive=$NEW_ARCHIVE"
  135. echo "new_archive_sha256=$NEW_SHA"
  136. echo "previous_release_tag=v0.1.1"
  137. echo "previous_release_commit=7128a205a5cf70256bf6bb3cc87068b1d03e7fd4"
  138. echo "previous_archive=$OLD_ARCHIVE"
  139. echo "previous_archive_sha256=$OLD_SHA"
  140. echo "fresh_install=PASS"
  141. echo "same_version_reinstall=PASS"
  142. echo "purge_reinstall=PASS"
  143. echo "preexisting_identity_preservation=PASS"
  144. echo "previous_release_upgrade=PASS"
  145. echo "upgrade_from_failed_previous_install=PASS"
  146. echo "hardware_validation=NOT RUN"
  147. echo "com_validation=NOT RUN"
  148. echo "jtag_validation=NOT RUN"
  149. echo "real_thermal_performance=NOT RUN"
  150. echo "generated_at_utc=$(date -u +%Y-%m-%dT%H:%M:%SZ)"
  151. echo "log_sha256=$(sha256sum "$LOG" | awk '{print $1}')"
  152. } >"$RECEIPT"
  153. cat "$RECEIPT"
  154. echo "HTH_INSTALL_MATRIX_PASS"