Skip to content

Instantly share code, notes, and snippets.

@blubberdiblub
Created October 29, 2012 16:18
Show Gist options
  • Save blubberdiblub/3974586 to your computer and use it in GitHub Desktop.
Save blubberdiblub/3974586 to your computer and use it in GitHub Desktop.
cryptsetup key script that reads the key from a USB stick and failing that prompts the user
#!/bin/sh
DEVICE='/dev/disk/by-label/NIELS'
WAIT=10
MOUNTP='/tmp/cryptkey'
FSTYPE=vfat
FSOPTS='uid=0,gid=0,codepage=850,iocharset=iso8859-1,utf8'
FSPATH='niels'
rc=1
while [ ! -e "$DEVICE" ] && [ "0$WAIT" -gt 0 ]
do
WAIT=$(( WAIT - 1 ))
sleep 1
done
while umount -- "$DEVICE" >/dev/null 2>&1 ; do : ; done
[ -d "$MOUNTP" ] || mkdir -- "$MOUNTP" >/dev/null 2>&1 || true
mount -r -t $FSTYPE -o "$FSOPTS" -- "$DEVICE" "$MOUNTP" >/dev/null 2>&1 && cat -- "$MOUNTP/$FSPATH/$1" 2>/dev/null && rc=0
umount -- "$MOUNTP" >/dev/null 2>&1 || true
[ "0$rc" -ne 0 ] && exec /lib/cryptsetup/askpass "Enter passphrase: "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment