Skip to content

Instantly share code, notes, and snippets.

@teffalump
Last active December 14, 2015 10:49
Show Gist options
  • Save teffalump/5074951 to your computer and use it in GitHub Desktop.
Save teffalump/5074951 to your computer and use it in GitHub Desktop.
Took this from http://jasonwryan.com/blog/2013/01/10/truecrypt/. Change a little for non loopback and disk id.
#!/bin/bash
# manage truecrypt containers using tcplay
cryptdev="/dev/disk/by-id/usb-Ut165_USB2FlashStorage_19211326100935920031-0:0"
cryptmap=truecrypt
mountpt=/mnt/"$cryptmap"
# must be run as root
if [[ $EUID != 0 ]]; then
printf "%s\n" "You must be root to run this."
exit 1
fi
# unecrypt and mount container
if [[ "$1" == "open" ]]; then
# create mount directory if it doesn't exist
[[ -d "$mountpt" ]] || mkdir "$mountpt"
# map container
tcplay -m "$cryptmap" -d "$cryptdev" || (echo "mapping failed" && exit 1)
# mount options
mount /dev/mapper/"$cryptmap" "$mountpt"
# close and clean up…
elif [[ "$1" == "close" ]]; then
(umount "$mountpt" && rmdir "$mountpt" && dmsetup remove "$cryptmap" && dmsetup remove "$cryptmap.0") || printf "%s\n" "demapping failed"
else
printf "%s\n" "Options are open or close."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment