Debian Codegraph @

debian/tests/machine-id

raw
1 #!/bin/sh
2 set -eu
3
4 # Regression test for https://bugs.debian.org/1040790
5
6 mode="${1-}"
7
8 export LC_ALL=C.UTF-8
9 fail=
10 set -x
11
12 # dbus-daemon.deb provides a machine ID
13 ls -l /etc/machine-id /var/lib/dbus/machine-id || :
14 head /etc/machine-id /var/lib/dbus/machine-id || :
15 uuid="$(dbus-uuidgen --get)"
16 test -n "$uuid" || fail=yes
17 # The machine ID consists of 32 lower-case hex digits (and the file
18 # also has a newline)
19 test "$uuid" = "$(perl -pe 'print "wrong: " unless /\A[a-z0-9]{32}\n\z/' /var/lib/dbus/machine-id)" || fail=yes
20
21 # Intentionally not asserting that /etc/machine-id matches
22 # /var/lib/dbus/machine-id: if the test container has both dbus and
23 # systemd, and it was generated with a version of dbus that has #1040790,
24 # then that assertion could fail.
25
26 # If there is a systemd machine ID, installing dbus-daemon should
27 # make the D-Bus machine ID be the same as it.
28 # Unfortunately nothing currently guarantees that a Debian
29 # system will have a machine ID, so this has to be conditional. (See
30 # also #745876, #783716).
31 if [ -e /etc/machine-id ] || [ "$mode" = with-systemd ]; then
32 rm -f /var/lib/dbus/machine-id
33 # This is for its side-effect of running the postinst, emulating
34 # a fresh installation
35 dpkg-reconfigure -fnoninteractive -pcritical dbus-daemon
36 ls -l /etc/machine-id /var/lib/dbus/machine-id || :
37 head /etc/machine-id /var/lib/dbus/machine-id || :
38 uuid="$(dbus-uuidgen --get)"
39 test -n "$uuid" || fail=yes
40 test "$uuid" = "$(perl -pe 'print "wrong: " unless /\A[a-z0-9]{32}\n\z/' /var/lib/dbus/machine-id)" || fail=yes
41 test "$uuid" = "$(perl -pe 'print "wrong: " unless /\A[a-z0-9]{32}\n\z/' /etc/machine-id)" || fail=yes
42 fi
43
44 # Similarly, if there is a D-Bus machine ID but no systemd machine ID
45 # (for example if dbus-daemon happened to be installed before systemd),
46 # then we expect systemd-machine-id-setup to copy ours.
47 if [ "$mode" = with-systemd ]; then
48 rm -f /etc/machine-id
49 systemd-machine-id-setup
50 ls -l /etc/machine-id /var/lib/dbus/machine-id || :
51 head /etc/machine-id /var/lib/dbus/machine-id || :
52 uuid="$(dbus-uuidgen --get)"
53 test -n "$uuid" || fail=yes
54 test "$uuid" = "$(perl -pe 'print "wrong: " unless /\A[a-z0-9]{32}\n\z/' /var/lib/dbus/machine-id)" || fail=yes
55 test "$uuid" = "$(perl -pe 'print "wrong: " unless /\A[a-z0-9]{32}\n\z/' /etc/machine-id)" || fail=yes
56 fi
57
58 test -z "$fail"
59
60 # vim:set sw=4 sts=4 et: