Commit cf2e4f5bf42520863cc61534f69a4389c85c5ffb Parent: b5fe9a0fb6e3cc0fd16349654debf5c026f5cc15 Author: mcol <mcol@posteo.net> Date: 2020-10-12 21:32:34 +0100 Committer: mcol <mcol@posteo.net> Committed: 2020-10-12 21:32:34 +0100 Wrap the encrypt hook to simplify usage and control cursor position This changes the way mkinitcpio-welcome is used. By replacing the encrypt hook, the old poscursor hook is unnecessary as everything can be contained in one 'welcome' hook. The encrypt hook's build and run_hook functions are executed directly by this hook. This makes it easier to control the position of the cursor and any messages printed by the decryption step.
readme.rst Modified
@@ -1,32 +1,35 @@ mkinitcpio-welcome ================== -Two hooks for mkinitcpio_ that draw out the word "Welcome" in big letters early -during the boot process. A box is drawn underneath for inputting the password -during the 'encrypt' hook and printing the output of the 'fsck' hook. +A mkinitcpio_ hook that draws out the word "Welcome" in big letters early +during the boot process and accepts input for disk decryption. A box is drawn +underneath for inputting the password and printing the output of the 'fsck' +hook. -Please email me with any issues, questions or comments @ mcol at posteo.net +The hook wraps and replaces the encrypt hook so that it can have greater +control over the cursor and any printed messages. + +It works very well with Evan Purkhiser's `mkinitcpio-colors`_. Usage ----- -1. Copy the contents of `hooks` into `/etc/initcpio/hooks` -#. Copy the contents of `install` into `/etc/initcpio/install` -#. Add the `welcome` hook to `/etc/mkinitcpio.conf` before the `encrypt` hook -#. Add the `poscursor` hook to `/etc/mkinitcpio.conf` after the `encrypt` hook - but before the `fsck` hook -#. Optionally configure the colours to use in `/etc/vconsole.conf`: +0. Ensure that you can successfully use the `encrypt` hook without first. +1. Copy `hooks/welcome` into `/etc/initcpio/hooks`. +2. Copy `install/welcome` into `/etc/initcpio/install`. +3. Add the `welcome` hook to `/etc/mkinitcpio.conf` replacing the `encrypt` hook. +4. Optionally configure the colours to use in `/etc/vconsole.conf`: .. code-block:: sh WELCOME_BG=0 # background WELCOME_FG=5 # foreground ("Welcome") - WELCOME_IN=6 # input box + WELCOME_IN=6 # input box frame where the number is 0-15 corresponding to the 16 defined console colours. -Works very well with Evan Purkhiser's `mkinitcpio-colors`_. +5. Rebuild the initramfs image with `mkinitcpio`. Contact
install/welcome Modified
@@ -2,32 +2,39 @@ build() { ( - WELCOME_FG=5 - WELCOME_BG=0 - WELCOME_IN=4 + test -s /etc/vconsole.conf && . /etc/vconsole.conf - [[ -s /etc/vconsole.conf ]] && . /etc/vconsole.conf - - is_int() { test "$1" -ge 0 -a "$1" -le 15; } - is_int $WELCOME_FG || exit 1 - is_int $WELCOME_BG || exit 1 - is_int $WELCOME_IN || exit 1 + is_valid() { test "$1" -ge 0 -a "$1" -le 15; } + is_valid ${WELCOME_FG:-5} || WELCOME_FG=5 + is_valid ${WELCOME_BG:-0} || WELCOME_BG=0 + is_valid ${WELCOME_IN:-4} || WELCOME_IN=4 echo "WELCOME_FG=$WELCOME_FG" >> "$BUILDROOT/welcome" echo "WELCOME_BG=$WELCOME_BG" >> "$BUILDROOT/welcome" echo "WELCOME_IN=$WELCOME_IN" >> "$BUILDROOT/welcome" + ) - ) || { - echo "welcome: /etc/vconsole.conf configuration error" - exit 1 - } + add_file "/usr/lib/initcpio/hooks/encrypt" "/welcome-decrypt" 755 add_runscript + + # This is pretty ugly but we want the 'build' function in the encrypt hook + # and we want it called from a file called 'welcome' as it calls + # 'add_runscript' which reads the filename. + TMP=`mktemp -d` + cp /usr/lib/initcpio/install/encrypt $TMP/welcome + sed -i 's/build()/_&/' $TMP/welcome + echo _build >> $TMP/welcome + . $TMP/welcome + rm -r $TMP } help() { cat <<HELPEOF -Prints the word "Welcome" in large letters and draws a box around the input for -the encrypt hook and output of the fsck hook. +This hook displays "Welcome" while waiting for input for disk decryption. It +depends on (and uses) the build function from the standard encrypt hook to +ensure that everything is set up correctly for decryption, but instead of using +the encrypt hook's own boot script, a custom one is specified by the user in +/etc/initcpio/welcome-decrypt HELPEOF }
install/poscursor Deleted
@@ -1,11 +0,0 @@ -#!/bin/bash - -build() { - add_runscript -} - -help() { - cat <<HELPEOF -Moves the cursor the second line of the input box to position fsck output -HELPEOF -}
hooks/welcome Modified
@@ -1,7 +1,7 @@ #!/usr/bin/ash -draw_welcome() { +run_hook() { # user-defined colours . /welcome we="\x1b[48;5;${WELCOME_FG}m" @@ -16,7 +16,7 @@ fill="\033[K" # fill to end of line # draw "Welcome" - echo -e "$b14\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill" + echo -e "\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill" echo -e " $s$e$fill" echo -e " $p $p $p$fill" echo -e " $p $p $p$fill" @@ -38,16 +38,11 @@ echo -e "$fill\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill" echo -e "$fill\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill\n$fill" - # move cursor into inpux box + # decrypt echo -ne "\x1b[32;81H" -} - - -run_hook() { - if [ -e /welcome ] - then - draw_welcome - else - msg "/welcome not found despite added hook." - fi + ( + . /welcome-decrypt + run_hook + ) + echo -ne "\x1b[33;81H" }
hooks/poscursor Deleted
@@ -1,7 +0,0 @@ -#!/usr/bin/ash - - -run_hook() { - # Reposition cursor to second line of input box for the output of fsck - echo -ne "\x1b[33;81H" -}