pmaports/main/postmarketos-mkinitfs-hook-maximum-attention/00-maximum-attention.sh
Caleb Connolly 57744b984e
postmarketos-initramfs: export logs on boot failure (MR 4646)
Currently, when postmarketOS fails to boot up, retrieving any
information necessary to root cause the issue is non-trivial, requiring
building a custom initramfs with debug-shell enabled and then manually
copying out data.

Let's improve the situation by exporting logs automatically on boot
failure. This is safer than just exposing a root shell but still
provides a whole lot of useful info that should make duplicating and
triaging issues much easier for developers.

This commit implements the functionality and includes some generally
useful data. We then generate a README and expose files for each command/log
as well as an archive that can be easily attached to a GitLab issue.

To help with triaging, also record the version of the postmarketos-initramfs
package and hash the init.sh and init_functions.sh files.

For testing purposes, you can trigger the log recovery mode on-time by
creating an empty file named ".pmos_export_logs" in the /boot partition.

Signed-off-by: Caleb Connolly <caleb@connolly.tech>
2024-01-05 17:29:45 +00:00

56 lines
1.1 KiB
Bash

#!/bin/sh
. ./init_functions.sh
BLINK_INTERVAL=2 # seconds
VIBRATION_DURATION=400 #ms
VIBRATION_INTERVAL=2 #s
find_leds() {
find /sys -name "max_brightness" | xargs -I{} dirname {}
}
find_vibrator() {
echo /sys/class/timed_output/vibrator
}
# blink_leds takes a list of LEDs as parameters,
# it iterates over every LED, and changes their value,
# alternating between max_brightness and 0 every BLINK_INTERVAL
blink_leds() {
state=false # false = off, true=on
while true; do
for led in $@; do
if [ "$state" = true ]; then
cat $led/max_brightness > $led/brightness
else
echo 0 > $led/brightness
fi
echo blinking LED: $led
done
sleep ${BLINK_INTERVAL}s
if [ "$state" = true ]; then
state=false
else
state=true
fi
done
}
# vibrate_loop vibrates each VIBRATION_INTERVAL for VIBRATION_DURATION
# it takes a timed_device path to the vibrator as $1
vibrate_loop() {
if [ ! -f $1/enable ]; then
return;
fi
while true; do
echo $VIBRATION_DURATION > $1/enable
sleep ${VIBRATION_INTERVAL}s
done
}
blink_leds $(find_leds) &
vibrate_loop $(find_vibrator) &
fail_halt_boot