summaryrefslogtreecommitdiff
path: root/system_files
diff options
context:
space:
mode:
authortranch <tranch.xiao@gmail.com>2026-07-15 14:04:06 +0800
committertranch <tranch.xiao@gmail.com>2026-07-15 14:05:38 +0800
commit3590672ec3f45b8df3820d65fc0946dc760292ec (patch)
tree77124dc136489d9d8de6ad76171e969678b393a6 /system_files
parent44279a34ed21056fda257b9d53a0a24e449c0fe9 (diff)
downloadAeroCore-OS-3590672ec3f45b8df3820d65fc0946dc760292ec.tar.gz
AeroCore-OS-3590672ec3f45b8df3820d65fc0946dc760292ec.zip
Integrate Instruments release seed
Download and verify the selected release during image builds. Bootstrap it once into the first graphical user's XDG directories.
Diffstat (limited to 'system_files')
-rw-r--r--system_files/usr/lib/systemd/system/aerocore-instruments-setup.service18
-rwxr-xr-xsystem_files/usr/libexec/aerocore-instruments-setup123
2 files changed, 141 insertions, 0 deletions
diff --git a/system_files/usr/lib/systemd/system/aerocore-instruments-setup.service b/system_files/usr/lib/systemd/system/aerocore-instruments-setup.service
new file mode 100644
index 0000000..0c9cc45
--- /dev/null
+++ b/system_files/usr/lib/systemd/system/aerocore-instruments-setup.service
@@ -0,0 +1,18 @@
+[Unit]
+Description=Configure AeroCore Booster for the graphical user
+Documentation=https://github.com/AeroCore-IO/instruments-ng
+After=systemd-user-sessions.service display-manager.service
+Wants=systemd-user-sessions.service
+ConditionPathExists=/usr/share/aerocore-booster-release/install.sh
+ConditionPathExists=!/var/lib/aerocore/instruments-bootstrap-complete
+
+[Service]
+Type=oneshot
+Environment=AEROCORE_INSTRUMENTS_SETUP_WAIT_SECONDS=180
+ExecStart=/usr/libexec/aerocore-instruments-setup
+Restart=on-failure
+RestartSec=15
+TimeoutStartSec=360
+
+[Install]
+WantedBy=multi-user.target
diff --git a/system_files/usr/libexec/aerocore-instruments-setup b/system_files/usr/libexec/aerocore-instruments-setup
new file mode 100755
index 0000000..cdbe8cd
--- /dev/null
+++ b/system_files/usr/libexec/aerocore-instruments-setup
@@ -0,0 +1,123 @@
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+: "${AEROCORE_INSTRUMENTS_SETUP_WAIT_SECONDS:=180}"
+
+seed_root="/usr/share/aerocore-booster-release"
+state_dir="/var/lib/aerocore"
+identity_file="$state_dir/instruments-user"
+complete_marker="$state_dir/instruments-bootstrap-complete"
+attempt_marker="$state_dir/instruments-bootstrap-attempted"
+
+find_graphical_user() {
+ local requested_uid="${1:-}"
+ local active seat session state type uid user
+
+ while read -r session _; do
+ [[ -n "$session" ]] || continue
+ uid="$(loginctl show-session "$session" --property=User --value 2>/dev/null || true)"
+ if [[ ! "$uid" =~ ^[0-9]+$ ]] || ((uid < 1000)); then
+ continue
+ fi
+ [[ -z "$requested_uid" || "$uid" == "$requested_uid" ]] || continue
+
+ active="$(loginctl show-session "$session" --property=Active --value 2>/dev/null || true)"
+ state="$(loginctl show-session "$session" --property=State --value 2>/dev/null || true)"
+ type="$(loginctl show-session "$session" --property=Type --value 2>/dev/null || true)"
+ seat="$(loginctl show-session "$session" --property=Seat --value 2>/dev/null || true)"
+ [[ "$active" == "yes" || "$state" == "active" || "$state" == "online" ]] || continue
+
+ user="$(getent passwd "$uid" | cut -d: -f1)"
+ [[ -n "$user" && "$user" != "root" ]] || continue
+ if [[ "$type" == "x11" || "$type" == "wayland" ]]; then
+ printf '%s\n' "$user"
+ return 0
+ fi
+ if [[ "$seat" == "seat0" ]] && pgrep -u "$uid" -x steam >/dev/null 2>&1; then
+ printf '%s\n' "$user"
+ return 0
+ fi
+ done < <(loginctl list-sessions --no-legend --no-pager 2>/dev/null || true)
+
+ return 1
+}
+
+if [[ -f "$complete_marker" ]]; then
+ echo "AeroCore Booster user bootstrap is already complete"
+ exit 0
+fi
+
+configured_uid=""
+if [[ -f "$identity_file" ]]; then
+ configured_uid="$(awk -F= '$1 == "uid" { print $2; exit }' "$identity_file")"
+ if [[ ! "$configured_uid" =~ ^[0-9]+$ ]] ||
+ ! getent passwd "$configured_uid" >/dev/null 2>&1; then
+ configured_uid=""
+ fi
+fi
+
+deadline=$((SECONDS + AEROCORE_INSTRUMENTS_SETUP_WAIT_SECONDS))
+desktop_user=""
+while ((SECONDS < deadline)); do
+ desktop_user="$(find_graphical_user "$configured_uid" || true)"
+ [[ -n "$desktop_user" ]] && break
+ sleep 2
+done
+
+if [[ -z "$desktop_user" ]]; then
+ echo "No active graphical user found within ${AEROCORE_INSTRUMENTS_SETUP_WAIT_SECONDS}s" >&2
+ exit 1
+fi
+
+desktop_uid="$(id -u "$desktop_user")"
+desktop_group="$(id -gn "$desktop_user")"
+desktop_home="$(getent passwd "$desktop_user" | cut -d: -f6)"
+if [[ -z "$desktop_home" || ! -d "$desktop_home" ]]; then
+ echo "Home directory is unavailable for $desktop_user: $desktop_home" >&2
+ exit 1
+fi
+
+install -d -m 0755 "$state_dir"
+printf 'user=%s\nuid=%s\n' "$desktop_user" "$desktop_uid" >"$identity_file"
+chmod 0644 "$identity_file"
+
+existing_install=0
+for installed_path in \
+ "$desktop_home/.local/share/aerocore-booster/manifest.yaml" \
+ "$desktop_home/.local/share/aerocore-booster/appimage/AppRun" \
+ "$desktop_home/.local/share/aerocore-booster/aerocore-booster" \
+ "$desktop_home/.local/share/instruments-ng/manifest.yaml" \
+ "$desktop_home/.local/share/instruments-ng/appimage/AppRun" \
+ "$desktop_home/.local/share/instruments-ng/instruments-ng"; do
+ if [[ -e "$installed_path" ]]; then
+ existing_install=1
+ break
+ fi
+done
+
+if [[ "$existing_install" == "0" || -f "$attempt_marker" ]]; then
+ touch "$attempt_marker"
+ HOME="$desktop_home" \
+ AEROCORE_INSTRUMENTS_USER="$desktop_user" \
+ AEROCORE_INSTRUMENTS_GROUP="$desktop_group" \
+ AEROCORE_INSTRUMENTS_UID="$desktop_uid" \
+ AEROCORE_INSTRUMENTS_HOME="$desktop_home" \
+ bash "$seed_root/install.sh" install
+else
+ echo "Existing Instruments installation found for $desktop_user; preserving it"
+fi
+
+cat >"$complete_marker" <<EOF
+user=$desktop_user
+uid=$desktop_uid
+seed_release=$(awk -F= '$1 == "RELEASE_TAG" { print $2; exit }' "$seed_root/image-release")
+EOF
+chmod 0644 "$complete_marker"
+rm -f "$attempt_marker"
+
+# Bootstrap is deliberately one-shot. Independent updates and uninstalls are
+# owned by the user-space Instruments installer after this point.
+systemctl disable aerocore-instruments-setup.service >/dev/null 2>&1 || true
+
+echo "AeroCore Booster user bootstrap completed for $desktop_user (uid $desktop_uid)"