| 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_opensc" ] || [ ! -f "$TABFILE" ]; then |
| 23 | exit 0 |
| 24 | fi |
| 25 | |
| 26 | # Hooks for loading smartcard reading software into the initramfs |
| 27 | copy_keys() { |
| 28 | crypttab_parse_options |
| 29 | if [ "${CRYPTTAB_OPTION_keyscript-}" = "/lib/cryptsetup/scripts/decrypt_opensc" ]; 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 | # Install directories needed by smartcard reading daemon, command, and |
| 43 | # key-script |
| 44 | mkdir -p -- "$DESTDIR/etc/opensc" "$DESTDIR/usr/lib/pcsc" "$DESTDIR/var/run" "$DESTDIR/tmp" |
| 45 | |
| 46 | # Install pcscd daemon, drivers, conf file |
| 47 | copy_exec /usr/sbin/pcscd |
| 48 | |
| 49 | cp -rt "$DESTDIR/usr/lib" /usr/lib/pcsc |
| 50 | cp -t "$DESTDIR/etc" /etc/reader.conf || true |
| 51 | cp -t "$DESTDIR/etc" /etc/libccid_Info.plist |
| 52 | |
| 53 | for so in $(ldconfig -p | sed -nr 's/^\s*(libusb-[0-9.-]+|libpcsclite)\.so\.[0-9]+\s.*=>\s*//p'); do |
| 54 | copy_exec "$so" |
| 55 | done |
| 56 | |
| 57 | # Install opensc commands and conf file |
| 58 | copy_exec /usr/bin/opensc-tool |
| 59 | copy_exec /usr/bin/pkcs15-crypt |
| 60 | cp -t "$DESTDIR/etc/opensc" /etc/opensc/opensc.conf |
| 61 | |
| 62 | exit $RV |