1#!/usr/bin/env bash 2# SPDX-License-Identifier: LGPL-2.1-or-later 3set -eux 4set -o pipefail 5 6function setup_root { 7 local _root="$1" 8 mkdir -p "$_root" 9 mount -t tmpfs tmpfs "$_root" 10 mkdir -p "$_root/etc" "$_root/run" 11} 12 13function check { 14 printf "Expected\n" 15 cat "$1" 16 printf "\nGot\n" 17 cat "$2" 18 cmp "$1" "$2" 19} 20 21r="$(pwd)/overwrite-broken-machine-id" 22setup_root "$r" 23systemd-machine-id-setup --print --root "$r" 24echo abc >>"$r/etc/machine-id" 25id="$(systemd-machine-id-setup --print --root "$r")" 26echo "$id" >expected 27check expected "$r/etc/machine-id" 28 29r="$PWD/transient-machine-id" 30setup_root "$r" 31systemd-machine-id-setup --print --root "$r" 32echo abc >>"$r/etc/machine-id" 33mount -o remount,ro "$r" 34mount -t tmpfs tmpfs "$r/run" 35transient_id="$(systemd-machine-id-setup --print --root "$r")" 36mount -o remount,rw "$r" 37commited_id="$(systemd-machine-id-setup --print --commit --root "$r")" 38[[ "$transient_id" = "$commited_id" ]] 39check "$r/etc/machine-id" "$r/run/machine-id" 40