Skip to content

Instantly share code, notes, and snippets.

@akihiro
Created July 18, 2016 09:58
Show Gist options
  • Save akihiro/236f4d4d7b9f95f5742c5517675281c0 to your computer and use it in GitHub Desktop.
Save akihiro/236f4d4d7b9f95f5742c5517675281c0 to your computer and use it in GitHub Desktop.
cryptsetup keyscript example
#!/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