|
| 1 | +#!/bin/bash |
| 2 | +# vim: set tabstop=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80: |
| 3 | +# |
| 4 | +# Copyright (c) 2024 Red Hat, Inc. |
| 5 | +# Author: Oldřich Jedlička <[email protected]> |
| 6 | +# |
| 7 | +# This program is free software: you can redistribute it and/or modify |
| 8 | +# it under the terms of the GNU General Public License as published by |
| 9 | +# the Free Software Foundation, either version 3 of the License, or |
| 10 | +# (at your option) any later version. |
| 11 | +# |
| 12 | +# This program is distributed in the hope that it will be useful, |
| 13 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | +# GNU General Public License for more details. |
| 16 | +# |
| 17 | +# You should have received a copy of the GNU General Public License |
| 18 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | +# |
| 20 | + |
| 21 | +check() { |
| 22 | + require_binaries clevis-decrypt-tpm1 tpm_version tpm_unsealdata tcsd stdbuf || return 1 |
| 23 | + if [[ $hostonly ]]; then |
| 24 | + [ -d /var/lib/tpm ] || return 1 |
| 25 | + else |
| 26 | + [ -f /usr/share/trousers/system.data.auth ] || \ |
| 27 | + [ -f /var/lib/tpm/system.data.auth ] || \ |
| 28 | + return 1 |
| 29 | + fi |
| 30 | + return 0 |
| 31 | +} |
| 32 | + |
| 33 | +depends() { |
| 34 | + echo clevis network |
| 35 | + return 0 |
| 36 | +} |
| 37 | + |
| 38 | +install() { |
| 39 | + if dracut_module_included "systemd"; then |
| 40 | + inst "$systemdsystemunitdir/tcsd.service" |
| 41 | + inst "$moddir/clevis-tcsd.conf" "$systemdsystemunitdir/tcsd.service.d/clevis-tcsd.conf" |
| 42 | + else |
| 43 | + inst_hook cleanup 60 "$moddir/clevis-hook.sh" |
| 44 | + inst_multiple \ |
| 45 | + awk chmod chown mkfifo mktemp ip ps stdbuf \ |
| 46 | + @libexecdir@/clevis-luks-tpm1-functions |
| 47 | + if [ -f /usr/libexec/coreutils/libstdbuf.so ]; then |
| 48 | + inst_multiple /usr/libexec/coreutils/libstdbuf.so* |
| 49 | + else |
| 50 | + inst_libdir_file 'coreutils/libstdbuf.so*' |
| 51 | + fi |
| 52 | + fi |
| 53 | + |
| 54 | + inst_multiple \ |
| 55 | + clevis-decrypt-tpm1 \ |
| 56 | + tcsd \ |
| 57 | + tpm_version \ |
| 58 | + tpm_unsealdata |
| 59 | + |
| 60 | + inst_rules 60-tpm-udev.rules |
| 61 | + |
| 62 | + if ! [[ $hostonly ]] || ! dracut_module_included "systemd"; then |
| 63 | + # /etc/hosts is installed only in host-only mode with systemd, so |
| 64 | + # we need to create our own in order to get tpm tools working. |
| 65 | + # The localhost entry is required by tpm tools. |
| 66 | + if [ ! -f "$initdir/etc/hosts" ]; then |
| 67 | + echo "127.0.0.1 localhost" >> "$initdir/etc/hosts" |
| 68 | + echo "::1 localhost ip6-localhost ip6-loopback" >> "$initdir/etc/hosts" |
| 69 | + echo "ff02::1 ip6-allnodes" >> "$initdir/etc/hosts" |
| 70 | + echo "ff02::2 ip6-allrouters" >> "$initdir/etc/hosts" |
| 71 | + fi |
| 72 | + fi |
| 73 | + |
| 74 | + if [[ $hostonly ]]; then |
| 75 | + inst /etc/tcsd.conf |
| 76 | + inst_multiple /var/lib/tpm/* |
| 77 | + else |
| 78 | + inst_dir /etc |
| 79 | + touch "$initdir/etc/tcsd.conf" |
| 80 | + chmod 0640 "$initdir/etc/tcsd.conf" |
| 81 | + chown root:tss "$initdir/etc/tcsd.conf" |
| 82 | + |
| 83 | + inst_dir /var/lib/tpm |
| 84 | + if [ -f /usr/share/trousers/system.data.auth ]; then |
| 85 | + inst /usr/share/trousers/system.data.auth /var/lib/tpm/system.data |
| 86 | + else |
| 87 | + inst /var/lib/tpm/system.data.auth /var/lib/tpm/system.data |
| 88 | + fi |
| 89 | + fi |
| 90 | + |
| 91 | + chown -R tss:tss "$initdir/var/lib/tpm" |
| 92 | + chmod -R u=rwX,go= "$initdir/var/lib/tpm" |
| 93 | +} |
| 94 | + |
| 95 | +installkernel() { |
| 96 | + hostonly='' instmods '=drivers/char/tpm' |
| 97 | +} |
0 commit comments