cat / goq
clone

turns a linux box into a private steam streaming appliance: plug in, tap your key, play from another computer

fix/website-download-wiring
goq / scripts / tests / bazzite-release-activation.sh
bazzite-release-activation.sh 6.7K executable
1#!/usr/bin/env bash2# The test sources production helpers dynamically, so ShellCheck cannot see3# their references to the fixture overrides and shared state variables.4# SC2317 is the equivalent diagnostic emitted by the ShellCheck release used5# on GitHub's Ubuntu runner for these indirectly invoked fixture functions.6# shellcheck disable=SC2034,SC2317,SC232978set -euo pipefail910script_dir="$(CDPATH='' cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"11repo_dir="$(CDPATH='' cd -- "$script_dir/../.." && pwd -P)"12temp_parent="${TMPDIR:-/tmp}"13temp_parent="${temp_parent%/}"14temp_root="$(mktemp -d "$temp_parent/sigil-release-activation.XXXXXX")"1516cleanup() {17 local status=$?18 trap - EXIT INT TERM HUP19 case "$temp_root" in20 "$temp_parent"/sigil-release-activation.??????) rm -rf -- "$temp_root" ;;21 esac22 exit "$status"23}24trap cleanup EXIT INT TERM HUP2526# Production targets GNU mv on Bazzite. Translate its atomic no-target-directory27# form to the equivalent operation for this macOS-hosted shell test.28mv() {29 if [[ "${1:-}" == -Tf && "${2:-}" == -- && "$#" -eq 4 ]]; then30 command mv -f -- "$3" "$4"31 else32 command mv "$@"33 fi34}3536extract_activation_helper() {37 local source_path="$1"38 local output_path="$2"39 sed -n \40 '/^# BEGIN release activation transaction helpers$/,/^# END release activation transaction helpers$/p' \41 "$source_path" | sed '1d;$d' >"$output_path"42 grep -Fq 'activate_release_links()' "$output_path"43}4445install_helper="$temp_root/install-activation.sh"46stage_helper="$temp_root/stage-activation.sh"47rollback_helper="$temp_root/rollback-activation.sh"48extract_activation_helper "$repo_dir/scripts/install-bazzite-package.sh" "$install_helper"49extract_activation_helper "$repo_dir/scripts/stage-bazzite-release.sh" "$stage_helper"50extract_activation_helper "$repo_dir/scripts/rollback-bazzite-release.sh" "$rollback_helper"51cmp "$install_helper" "$stage_helper"52cmp "$install_helper" "$rollback_helper"5354success_root="$temp_root/success"55install -d -m 0700 "$success_root"56(57 current_link="$success_root/current"58 previous_link="$success_root/previous"59 next_current="$success_root/.next-current"60 next_previous="$success_root/.next-previous"61 ln -s releases/old "$current_link"62 ln -s releases/older "$previous_link"63 ln -s releases/new "$next_current"64 ln -s releases/old "$next_previous"65 # shellcheck source=/dev/null66 source "$install_helper"67 snapshot_activation_links68 activate_release_links69 [[ "$(readlink "$current_link")" == releases/new ]]70 [[ "$(readlink "$previous_link")" == releases/old ]]71 restore_activation_links72 [[ "$(readlink "$current_link")" == releases/new ]]73 [[ "$(readlink "$previous_link")" == releases/old ]]74)7576reload_failure_root="$temp_root/reload-failure"77install -d -m 0700 "$reload_failure_root"78(79 current_link="$reload_failure_root/current"80 previous_link="$reload_failure_root/previous"81 next_current="$reload_failure_root/.next-current"82 next_previous="$reload_failure_root/.next-previous"83 ln -s releases/old "$current_link"84 ln -s releases/older "$previous_link"85 ln -s releases/new "$next_current"86 ln -s releases/old "$next_previous"87 # shellcheck source=/dev/null88 source "$install_helper"89 reload_calls=090 systemctl() {91 reload_calls=$((reload_calls + 1))92 [[ "$reload_calls" -gt 1 ]]93 }94 snapshot_activation_links95 activation_reload_service=true96 if activate_release_links; then97 printf 'FAIL: activation unexpectedly survived daemon-reload failure\n' >&298 exit 199 fi100 restore_activation_links101 [[ "$(readlink "$current_link")" == releases/old ]]102 [[ "$(readlink "$previous_link")" == releases/older ]]103 [[ "$reload_calls" -eq 2 ]]104)105106empty_root="$temp_root/empty"107install -d -m 0700 "$empty_root"108(109 current_link="$empty_root/current"110 previous_link="$empty_root/previous"111 next_current="$empty_root/.next-current"112 next_previous="$empty_root/.next-previous"113 ln -s releases/new "$next_current"114 # shellcheck source=/dev/null115 source "$install_helper"116 systemctl() { return 1; }117 snapshot_activation_links118 activation_reload_service=true119 if activate_release_links; then120 printf 'FAIL: first activation unexpectedly survived daemon-reload failure\n' >&2121 exit 1122 fi123 restore_activation_links124 [[ ! -e "$current_link" && ! -L "$current_link" ]]125 [[ ! -e "$previous_link" && ! -L "$previous_link" ]]126)127128guard_helper="$temp_root/package-managed-guard.sh"129sed -n \130 '/^# BEGIN package-managed activation guard$/,/^# END package-managed activation guard$/p' \131 "$repo_dir/scripts/stage-bazzite-release.sh" | sed '1d;$d' >"$guard_helper"132grep -Fq 'refuse_package_managed_activation()' "$guard_helper"133134guard_home="$temp_root/guard-home"135install_root="$guard_home/.local/libexec/sigil-spark"136service_link="$guard_home/.config/systemd/user/sigil-host.service"137install -d -m 0700 "$(dirname -- "$service_link")"138ln -s "$guard_home/unmanaged.service" "$service_link"139(140 HOME="$guard_home"141 # shellcheck source=/dev/null142 source "$guard_helper"143 die() {144 printf 'guard rejected: %s\n' "$*" >&2145 exit 1146 }147 refuse_package_managed_activation148)149150ln -sfn "$install_root/current/assets/sigil-host.service" "$service_link"151guard_log="$temp_root/guard.log"152if (153 HOME="$guard_home"154 # shellcheck source=/dev/null155 source "$guard_helper"156 die() {157 printf 'guard rejected: %s\n' "$*" >&2158 exit 1159 }160 refuse_package_managed_activation161) >"$guard_log" 2>&1; then162 printf 'FAIL: thin stager accepted a package-managed activation\n' >&2163 exit 1164fi165grep -Fq 'build the runtime package and use payload/stage-this-release.sh' "$guard_log"166167canonical_root="$temp_root/canonical-guard"168canonical_home="$canonical_root/var/home/tank"169install -d -m 0700 "$canonical_home"170ln -s var/home "$canonical_root/home"171spelled_home="$canonical_root/home/tank"172spelled_install_root="$spelled_home/.local/libexec/sigil-spark"173canonical_service_target="$canonical_home/.local/libexec/sigil-spark/current/assets/sigil-host.service"174canonical_service_link="$canonical_home/.config/systemd/user/sigil-host.service"175install -d -m 0700 "$(dirname -- "$canonical_service_target")" \176 "$(dirname -- "$canonical_service_link")"177printf '[Service]\n' >"$canonical_service_target"178ln -s "$canonical_service_target" "$canonical_service_link"179canonical_guard_log="$temp_root/canonical-guard.log"180if (181 HOME="$spelled_home"182 install_root="$spelled_install_root"183 # shellcheck source=/dev/null184 source "$guard_helper"185 die() {186 printf 'guard rejected: %s\n' "$*" >&2187 exit 1188 }189 refuse_package_managed_activation190) >"$canonical_guard_log" 2>&1; then191 printf 'FAIL: thin stager missed a canonically equivalent managed link\n' >&2192 exit 1193fi194grep -Fq 'build the runtime package and use payload/stage-this-release.sh' \195 "$canonical_guard_log"196197printf 'bazzite_release_activation_tests=ok\n'