Skip to content

Instantly share code, notes, and snippets.

@ilovezfs
Created January 31, 2014 11:51
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 ilovezfs/8730681 to your computer and use it in GitHub Desktop.
Save ilovezfs/8730681 to your computer and use it in GitHub Desktop.
openLUKS from prometheanfire
openLUKS() {
read -s -p "Password: " password
local RETRY_COUNT=3
echo ""
while [ $RETRY_COUNT -ne 0 ]; do
RETRY_COUNT=$(( RETRY_COUNT - 1 ))
for disk in a b c d e f g h i j k l m n o p q r s t u v w x y z; do
if [ -b /dev/sd${disk}2 ]; then
echo -n ${password} | gpg -q -d --no-tty --passphrase-fd 0 /mnt/key/decrypt.gpg | cryptsetup -q --key-file=- luksOpen /dev/sd${disk}2 crypt${disk}2
STATUS=$?
if [ $STATUS -ne 0 ]; then
echo "exit code was $STATUS"
echo 'bad password'
read -s -p "Password: " password
break
else
RETRY_COUNT=0
fi
else
echo "no disk named /dev/sd${disk}2"
fi
done
done
unset password
umount /mnt/key
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment