Skip to content

Instantly share code, notes, and snippets.

@ryancdotorg
Created July 14, 2016 18:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryancdotorg/56961c9382fc972982c5310b19d5114f to your computer and use it in GitHub Desktop.
Save ryancdotorg/56961c9382fc972982c5310b19d5114f to your computer and use it in GitHub Desktop.
#!/bin/sh
umask 077
TMPDIR=`mktemp -d /dev/shm/luks.XXXXXXXX`
if [ -d $TMPDIR ]
then
openssl rand -engine rdrand -base64 64 | tr -d '\n' > $TMPDIR/key
cryptsetup -i 10 -s 128 -d $TMPDIR/key luksFormat $1
if [ $? -eq 0 ]
then
UUID=`cryptsetup luksUUID $1`
mv $TMPDIR/key /keys/$UUID.dat
rmdir $TMPDIR
cryptsetup --header-backup-file /keys/header-backups/$UUID.hdr luksHeaderBackup $1
if [ -n "$2" ]
then
echo "$2_`echo $UUID | cut -c 1-4`" UUID=$UUID none luks,keyscript=/usr/local/sbin/luks_keychain >> /etc/crypttab
else
echo "`echo $UUID | cut -c 1-8`" UUID=$UUID none luks,keyscript=/usr/local/sbin/luks_keychain >> /etc/crypttab
fi
echo UUID: $UUID
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment