chamesle

chamesle.org: the site of Chamesle, a small Linux distribution
git clone https://github.com/tortr-rs/chamesle
Log | Files | Refs | README

blue-screen (2441B)


      1 #!/bin/sh
      2 # blue-screen [REASON]: the blue screen, for when the system can't finish starting. dinit runs it as its recovery
      3 # service; without a reason it names the services that failed. any key gives a command line (sulogin asks for
      4 # root's password, or lets you straight in when root is locked, as it is with sudo)
      5 reason=$1
      6 # what failed, from dinit's log (/usr/lib/chamesle/init keeps one): by now dinit has stopped everything and closed
      7 # its socket, so dinitctl can't say. the services whose own command failed, else the ones that couldn't start
      8 if [ -z "$reason" ] && [ -f /run/dinit.log ]; then
      9     failed=$(sed -n 's/.*[Ss]ervice \([^ ]*\) command failed.*/\1/p' /run/dinit.log | sort -u | tr '\n' ' ')
     10     [ -n "$failed" ] || failed=$(sed -n 's/.*service \([^ ]*\) failed to start.*/\1/p' /run/dinit.log |
     11         grep -vx boot | sort -u | tr '\n' ' ')
     12     [ -n "$failed" ] && reason="What failed: ${failed% }"
     13 fi
     14 if [ -z "$reason" ] && command -v dinitctl >/dev/null; then
     15     failed=$(dinitctl list 2>/dev/null | sed -n 's/^[[][^]]*X[^]]*[]] *\([^ ]*\).*/\1/p' | tr '\n' ' ')
     16     [ -n "$failed" ] && reason="What failed: ${failed% }"
     17 fi
     18 # the boot screen may be gone already, it goes when the desktop starts. udev has been stopped too, so plymouth
     19 # looks for the screen itself (or it falls back to text), and it needs a moment before it takes messages
     20 if ! plymouth --ping 2>/dev/null; then
     21     mkdir -p /run/plymouth
     22     plymouthd --mode=boot --tty=/dev/tty1 --kernel-command-line="$(cat /proc/cmdline) splash plymouth.ignore-udev" \
     23         2>/dev/null && plymouth show-splash && sleep 2
     24 fi
     25 if plymouth --ping 2>/dev/null; then
     26     plymouth display-message --text=chamesle-error
     27     [ -n "$reason" ] && plymouth display-message --text="$reason"
     28     plymouth watch-keystroke >/dev/null 2>&1
     29     # all the way gone, or it takes the console with it as sulogin starts
     30     plymouth quit
     31     i=0
     32     while plymouth --ping 2>/dev/null && [ $i -lt 50 ]; do
     33         sleep 0.1
     34         i=$((i + 1))
     35     done
     36 fi
     37 # the same in text, for the command line, or if there's no screen to draw on
     38 clear 2>/dev/null
     39 echo
     40 echo ":( Chamesle couldn't finish starting."
     41 [ -n "$reason" ] && echo "   $reason"
     42 echo
     43 echo "   'dinitctl list' shows what's running and what failed, logs are in /var/log and /run/dinit.log."
     44 echo "   Typing 'reboot' restarts. In the boot menu you can pick a snapshot from before the last update."
     45 echo
     46 exec sulogin --force