Skip to content

Instantly share code, notes, and snippets.

@kbhaines
Created August 11, 2018 14:39
Show Gist options
  • Save kbhaines/83a658508e7155afa6e412190c9ddaf7 to your computer and use it in GitHub Desktop.
Save kbhaines/83a658508e7155afa6e412190c9ddaf7 to your computer and use it in GitHub Desktop.
#!/bin/sh
if [ $# -ne 3 ];then
echo "Usage: $0 <mount|unmount> <crypt-volume> <target-name>"
exit 0
fi
ACTION=$1
SRC=$2
TARGET=$3
TARGET_PATH=/media/$TARGET
case $ACTION in
mount)
mkdir $TARGET_PATH
LOOP=`losetup --show --find $SRC`
tcplay --map=$TARGET --device=$LOOP
mount /dev/mapper/$TARGET $TARGET_PATH
;;
unmount)
umount $TARGET_PATH
sleep 1
dmsetup remove $TARGET
sleep 1
LOOP=`losetup -n --output NAME -j $SRC`
losetup -d $LOOP
rmdir $TARGET_PATH
;;
*) exit 1
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment