| 1 | #!/bin/sh |
| 2 | |
| 3 | set -e |
| 4 | |
| 5 | PREREQ="cryptroot" |
| 6 | |
| 7 | prereqs() |
| 8 | { |
| 9 | echo "$PREREQ" |
| 10 | } |
| 11 | |
| 12 | case "$1" in |
| 13 | prereqs) |
| 14 | prereqs |
| 15 | exit 0 |
| 16 | ;; |
| 17 | esac |
| 18 | |
| 19 | . /usr/share/initramfs-tools/hook-functions |
| 20 | . /lib/cryptsetup/functions |
| 21 | |
| 22 | if [ ! -x "$DESTDIR/lib/cryptsetup/scripts/decrypt_gnupg-sc" ] || [ ! -f "$TABFILE" ]; then |
| 23 | exit 0 |
| 24 | fi |
| 25 | |
| 26 | # Hooks for loading gnupg software and encrypted key into the initramfs |
| 27 | copy_keys() { |
| 28 | crypttab_parse_options |
| 29 | if [ "${CRYPTTAB_OPTION_keyscript-}" = "/lib/cryptsetup/scripts/decrypt_gnupg-sc" ]; then |
| 30 | if [ -f "$CRYPTTAB_KEY" ]; then |
| 31 | [ -f "$DESTDIR$CRYPTTAB_KEY" ] || copy_file keyfile "$CRYPTTAB_KEY" || RV=$? |
| 32 | else |
| 33 | cryptsetup_message "ERROR: Target $CRYPTTAB_NAME has a non-existing key file $CRYPTTAB_KEY" |
| 34 | RV=1 |
| 35 | fi |
| 36 | fi |
| 37 | } |
| 38 | |
| 39 | RV=0 |
| 40 | crypttab_foreach_entry copy_keys |
| 41 | |
| 42 | PUBRING="/etc/cryptsetup-initramfs/pubring.gpg" |
| 43 | if [ ! -f "$PUBRING" ]; then |
| 44 | cryptsetup_message "WARNING: $PUBRING: No such file" |
| 45 | else |
| 46 | [ -d "$DESTDIR/cryptroot/gnupghome" ] || mkdir -pm0700 "$DESTDIR/cryptroot/gnupghome" |
| 47 | # let gpg(1) create the keyring on the fly; we're not relying on its |
| 48 | # internals since it's the very same binary we're copying to the |
| 49 | # initramfs |
| 50 | /usr/bin/gpg --no-options --no-autostart --trust-model=always \ |
| 51 | --quiet --batch --no-tty --logger-file=/dev/null \ |
| 52 | --homedir="$DESTDIR/cryptroot/gnupghome" --import <"$PUBRING" |
| 53 | # make sure not to clutter the initramfs with backup keyrings |
| 54 | find "$DESTDIR/cryptroot" -name "*~" -type f -delete |
| 55 | fi |
| 56 | |
| 57 | copy_exec /usr/bin/gpg |
| 58 | copy_exec /usr/bin/gpg-agent |
| 59 | copy_exec /usr/lib/gnupg/scdaemon |
| 60 | copy_exec /usr/bin/gpgconf |
| 61 | copy_exec /usr/bin/gpg-connect-agent |
| 62 | |
| 63 | if [ ! -x "$DESTDIR/usr/bin/pinentry" ]; then |
| 64 | if [ -x "/usr/bin/pinentry-curses" ]; then |
| 65 | pinentry="/usr/bin/pinentry-curses" |
| 66 | elif [ -x "/usr/bin/pinentry-tty" ]; then |
| 67 | pinentry="/usr/bin/pinentry-tty" |
| 68 | else |
| 69 | cryptsetup_message "ERROR: missing required binary pinentry-curses or pinentry-tty" |
| 70 | RV=1 |
| 71 | fi |
| 72 | copy_exec "$pinentry" |
| 73 | ln -s "$pinentry" "$DESTDIR/usr/bin/pinentry" |
| 74 | fi |
| 75 | |
| 76 | # #1028202: ncurses-base: move terminfo files from /lib/terminfo to |
| 77 | # /usr/share/terminfo |
| 78 | for d in "/usr/share/terminfo" "/lib/terminfo"; do |
| 79 | if [ -f "$d/l/linux" ]; then |
| 80 | if [ ! -f "$DESTDIR$d/l/linux" ]; then |
| 81 | copy_file terminfo "$d/l/linux" || RV=$? |
| 82 | fi |
| 83 | break |
| 84 | fi |
| 85 | done |
| 86 | |
| 87 | exit $RV |