Skip to content

Instantly share code, notes, and snippets.

@ochebotar
Forked from fbatschi/tcmount
Created May 27, 2021 12:13
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 ochebotar/c7a13309898fa02d924de19a47fb3da0 to your computer and use it in GitHub Desktop.
Save ochebotar/c7a13309898fa02d924de19a47fb3da0 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