Skip to content

Instantly share code, notes, and snippets.

@fbatschi
Created July 16, 2015 21:09
Show Gist options
  • Save fbatschi/dffbc000734ec3747870 to your computer and use it in GitHub Desktop.
Save fbatschi/dffbc000734ec3747870 to your computer and use it in GitHub Desktop.
Bash Script to handle mounting/unmounting a truecrypt encrypted drive with tcplay
#!/bin/bash
losetup -f
while getopts “u” OPTION
do
case $OPTION in
u)
UMOUNT=1
;;
esac
done
if [ ! -n "$UMOUNT" ]; then
DISKS=`lsblk -d -n |grep disk`
echo "Available Disks:"
echo "$DISKS"
read -p "Which disk to attach? /dev/sd" input
fi
if [ ! -e /dev/mapper/tc ]; then
if [ ! -n "$UMOUNT" ]; then
echo "add dmcrypt mapping"
tcplay -m tc -d /dev/sd$input
fi
fi
if mount | grep /media/tc > /dev/null; then
echo "already mounted"
if [ -n "$UMOUNT" ]; then
echo -n unmount
umount /media/tc
echo " .... done "
fi
else
echo "not yet mounted"
if [ ! -n "$UMOUNT" ]; then
mount /dev/mapper/tc /media/tc
echo "now mounted"
fi
fi
if [ -e /dev/mapper/tc ]; then
echo "dmcrypt mapping exists"
if [ -n "$UMOUNT" ]; then
tcplay -u tc
echo "removed dmcrypt mapping"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment