From 6c7b6fdebe3fb5b5a7be21c13175e4851241473f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C4=8Cerm=C3=A1k?= Date: Thu, 20 Jun 2024 16:50:14 +0200 Subject: [PATCH] Generate version information for RAUC when rauc.db is empty (#3436) RAUC currently doesn't know the version of the booted slot when booted for the first time or after wiping the data partition. As a result `ha os info` is missing this information too. As there's no built-in mechanism for generating these data by RAUC itself, add a oneshot service that checks if the boot slot information is contained in the rauc.db and if not, then generate it. RAUC seems to cope quite well even with bogus data contained in rauc.db but in any case, a test has been added to check that everything works as expected. --- .../lib/systemd/system/raucdb-update.service | 12 ++++++ .../rootfs-overlay/usr/libexec/raucdb-update | 39 +++++++++++++++++++ tests/smoke_test/test_basic.py | 20 ++++++++-- 3 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 buildroot-external/rootfs-overlay/usr/lib/systemd/system/raucdb-update.service create mode 100755 buildroot-external/rootfs-overlay/usr/libexec/raucdb-update diff --git a/buildroot-external/rootfs-overlay/usr/lib/systemd/system/raucdb-update.service b/buildroot-external/rootfs-overlay/usr/lib/systemd/system/raucdb-update.service new file mode 100644 index 000000000..d38d50bca --- /dev/null +++ b/buildroot-external/rootfs-overlay/usr/lib/systemd/system/raucdb-update.service @@ -0,0 +1,12 @@ +[Unit] +Description=Ensure rauc.db contains version information +After=rauc.service +Before=hassos-supervisor.service +RequiresMountsFor=/mnt/data + +[Service] +Type=oneshot +ExecStart=/usr/libexec/raucdb-update + +[Install] +WantedBy=multi-user.target diff --git a/buildroot-external/rootfs-overlay/usr/libexec/raucdb-update b/buildroot-external/rootfs-overlay/usr/libexec/raucdb-update new file mode 100755 index 000000000..0bf04211a --- /dev/null +++ b/buildroot-external/rootfs-overlay/usr/libexec/raucdb-update @@ -0,0 +1,39 @@ +#!/bin/sh +# shellcheck disable=SC1091 + +set -e + +if grep -q 'slot\.boot\.0' /mnt/data/rauc.db; then + echo "[INFO] rauc.db already contains slot information" + exit 0 +fi + +echo "[INFO] Generating rauc.db from os-release data" + +eval "$(rauc status --output-format=shell)" + +if [ -z "${RAUC_SYSTEM_BOOTED_BOOTNAME}" ]; then + echo "[ERROR] RAUC_SYSTEM_BOOTED_BOOTNAME is empty" + exit 1 +fi + +CURRENT_SLOT_ID=$(test "${RAUC_SYSTEM_BOOTED_BOOTNAME}" = "A" && echo 0 || echo 1) + +. /etc/os-release + +cat >> /mnt/data/rauc.db <= 0 + + assert f"RAUC_SLOT_STATUS_BUNDLE_VERSION_{booted_idx + 1}='{expected_version}'" in rauc_status @pytest.mark.dependency(depends=["test_init"])