clevis.in 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/bin/bash
  2. #
  3. # Copyright (c) 2017 Shawn Rose
  4. # Author: Shawn Rose <shawnandrewrose@gmail.com>
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. PREREQ="cryptroot"
  20. prereqs()
  21. {
  22. echo "$PREREQ"
  23. }
  24. case $1 in
  25. prereqs)
  26. prereqs
  27. exit 0
  28. ;;
  29. esac
  30. . @initramfstoolsdir@/hook-functions
  31. die() {
  32. code="$1"
  33. msg="$2"
  34. echo " (ERROR): $msg" >&2
  35. exit $1
  36. }
  37. find_binary() {
  38. bin_name="$1"
  39. resolved=$(which ${bin_name})
  40. [ -z "$resolved" ] && die 1 "Unable to find ${bin_name}"
  41. echo "$resolved"
  42. }
  43. if [ -n "${FORCE_CLEVIS}" ] && [ "${FORCE_CLEVIS}" != "n" ]; then
  44. for f in /sbin/cryptsetup /sbin/dmsetup /lib/cryptsetup/askpass; do
  45. if [ ! -e "${DESTDIR}${f}" ]; then
  46. die 2 "cryptsetup utility '$f' wasn't found in the generated ramdisk image. "
  47. fi
  48. done
  49. fi
  50. copy_exec @bindir@/clevis-decrypt-tang || die 1 "@bindir@/clevis-decrypt-tang not found"
  51. copy_exec @bindir@/clevis-decrypt-sss || die 1 "@bindir@/clevis-decrypt-sss not found"
  52. copy_exec @bindir@/clevis-decrypt || die 1 "@bindir@/clevis-decrypt not found"
  53. copy_exec @bindir@/clevis-luks-common-functions || die 1 "@bindir@/clevis-luks-common-functions not found"
  54. copy_exec @bindir@/clevis-luks-list || die 1 "@bindir@/clevis-luks-list not found"
  55. if [ -x @bindir@/clevis-decrypt-tpm2 ]; then
  56. copy_exec @bindir@/clevis-decrypt-tpm2 || die 1 "@bindir@/clevis-decrypt-tpm2 not found"
  57. tpm2_creatprimary_bin=$(find_binary "tpm2_createprimary")
  58. tpm2_unseal_bin=$(find_binary "tpm2_unseal")
  59. tpm2_load_bin=$(find_binary "tpm2_load")
  60. copy_exec "${tpm2_creatprimary_bin}" || die 1 "Unable to copy ${tpm2_creatprimary_bin}"
  61. copy_exec "${tpm2_unseal_bin}" || die 1 "Unable to copy ${tpm2_unseal_bin}"
  62. copy_exec "${tpm2_load_bin}" || die 1 "Unable to copy ${tpm2_load_bin}"
  63. for _LIBRARY in @libdir@/libtss2-tcti-device.so*; do
  64. if [ -e "${_LIBRARY}" ]; then
  65. copy_exec "${_LIBRARY}" || die 2 "Unable to copy ${_LIBRARY}"
  66. fi
  67. done
  68. fi
  69. luksmeta_bin=$(find_binary "luksmeta")
  70. jose_bin=$(find_binary "jose")
  71. copy_exec "${luksmeta_bin}" || die 2 "Unable to copy ${luksmeta_bin}"
  72. copy_exec "${jose_bin}" || die 2 "Unable to copy ${jose_bin}"
  73. copy_exec @bindir@/clevis || die 1 "@bindir@/clevis not found"
  74. curl_bin=$(find_binary "curl")
  75. awk_bin=$(find_binary "awk")
  76. bash_bin=$(find_binary "bash")
  77. copy_exec "${curl_bin}" || die 2 "Unable to copy ${curl_bin} to initrd image"
  78. copy_exec "${awk_bin}" || die 2 "Unable to copy ${awk_bin} to initrd image"
  79. copy_exec "${bash_bin}" || die 2 "Unable to copy ${bash_bin} to initrd image"