forked from dynerose/Remote-unlock-native-ZFS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
crypt_unlock.sh
50 lines (41 loc) · 1.17 KB
/
crypt_unlock.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/sh
# /usr/share/initramfs-tools/hooks/crypt_unlock.sh
PREREQ="dropbear"
prereqs() {
echo "$PREREQ"
}
case "$1" in
prereqs)
prereqs
exit 0
;;
esac
. "${CONFDIR}/initramfs.conf"
. /usr/share/initramfs-tools/hook-functions
if [ "${DROPBEAR}" != "n" ] && [ -r "/etc/zfs" ] ; then
cat > "${DESTDIR}/bin/unlock" << EOF
#!/bin/sh
if PATH=/lib/unlock:/bin:/sbin /scripts/local-top/cryptroot; then
kill `ps | grep zfs | grep -v "grep" | awk '{print $1}'`
/sbin/zfs load-key -a
# rpool/root
# your zpool name and root zfs name and the mountpoint
mount -o zfsutil -t zfs rpool/root /
kill `ps | grep plymouth | grep -v "grep" | awk '{print $1}'`
kill `ps | grep cryptroot | grep -v "grep" | awk '{print $1}'`
# following line kill the remote shell right after the passphrase has been entered.
kill -9 `ps | grep "\-sh" | grep -v "grep" | awk '{print $1}'`
exit 0
fi
exit 1
EOF
chmod 755 "${DESTDIR}/bin/unlock"
mkdir -p "${DESTDIR}/lib/unlock"
cat > "${DESTDIR}/lib/unlock/plymouth" << EOF
#!/bin/sh
[ "$1" == "--ping" ] && exit 1
/bin/plymouth "$@"
EOF
chmod 755 "${DESTDIR}/lib/unlock/plymouth"
echo To unlock root-partition run "unlock" >> ${DESTDIR}/etc/motd
fi