Add timestamps to xtrace output in initramfs scripts
[tails.git] / config / chroot_local-includes / usr / share / initramfs-tools / scripts / init-bottom / early_patch
blob48f1f09f39777d4c014c69a52c65679fafffd0fa
1 #!/bin/sh
3 # Enable xtrace with timestamp
4 export PS4='$(date "+%H:%M:%S.%3N") '
5 set -x
7 PREREQS=""
9 prereqs() { echo "$PREREQS"; }
11 case "$1" in
12 prereqs)
13 prereqs
14 exit 0
16 esac
18 set -eu
20 option="$(tr ' ' '\n' < /proc/cmdline | grep '^early_patch\b')"
22 [ -n "$option" ] || exit 0
24 . /scripts/functions
26 MOUNTPOINT=/root/mnt
28 run() {
29 for mod in fscache 9pnet 9pnet_virtio 9p; do
30 modprobe -vvv -d /root/ $mod
31 done
33 mkdir -p "$MOUNTPOINT"
34 mount -t 9p src "$MOUNTPOINT"
35 "${MOUNTPOINT}/hook" /root
37 # early_patch=umount will umount the filesystem immediately after running the hook
38 # this is needed to have early_patch in the test suite.
39 # In fact, qemu cannot do snapshots while this is mounted
40 if echo "$option" | grep -qw umount; then
41 umount "$MOUNTPOINT"
45 spawn_shell() {
46 # Make plymouth write the log to /root/var/log/boot.log
47 /bin/plymouth update-root-fs --new-root-dir=/root --read-write
48 # Stop plymouth, so that the user can see the shell
49 /bin/plymouth quit || true
51 # Disable xtrace to make the following output more readable
52 set +x
53 echo -e >&2 "\nThe early_patch hook failed. Spawning a shell to allow debugging..."
54 echo >&2 "The log is in /root/var/log/boot.log"
55 echo >&2 "Press Ctrl-D to continue booting."
57 # Call panic from /usr/share/initramfs-tools/scripts/functions to
58 # spawn a shell. Note that panic does not work if set -e is active.
59 . /scripts/functions
60 panic
63 # This is necessary to have `set -e` work in the `run` function, see
64 # https://stackoverflow.com/a/11092989/2804197
65 set +e
66 (set -e; run); ret=$?
68 if [ "$ret" -ne 0 ]; then
69 spawn_shell