Created
July 18, 2016 09:58
-
-
Save akihiro/236f4d4d7b9f95f5742c5517675281c0 to your computer and use it in GitHub Desktop.
cryptsetup keyscript example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
target="${0##*/keyfile-}" | |
m= | |
cleanup() { | |
[ -n "$m" ] && umount "$m" 1>&2 | |
} | |
init() { | |
modprobe vfat | |
sleep 5 | |
mkdir -p /keydev 1>&2 | |
} | |
search() { | |
local dev= | |
for dev in /dev/disk/by-partlabel/efi-* ; do | |
if mount -t vfat -o ro,codepage=437,iocharset=utf8 "$dev" /keydev 1>&2; then | |
m="/keydev" | |
if [ -f "/keydev/${target}.key" ]; then | |
cat "/keydev/${target}.key" | |
return 0 | |
fi | |
umount "$m" 1>&2 | |
m= | |
fi | |
done | |
} | |
trap cleanup EXIT | |
init | |
search |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment