Created
September 28, 2017 12:42
-
-
Save tosyu/5a042577230a469ca40ad9fc99ebe0df to your computer and use it in GitHub Desktop.
mcrypt volumes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
LOSETUP=$(which losetup) | |
SUDO=$(which sudo) | |
MOUNT=$(which mount) | |
CRYPTSETUP=$(which cryptsetup) | |
FILE=$(realpath $1) | |
FILENAME=$(basename $1) | |
if [ ! -f "$FILE" ]; then | |
echo "ERROR $FILE does not exist" | |
exit 1 | |
fi | |
$SUDO $LOSETUP -f $FILE | |
if [ $? -ne 0 ]; then | |
echo "could not find loop device" | |
exit 1 | |
fi | |
DEVICE=$($LOSETUP -j $FILE | cut -f1 -d:) | |
$SUDO $CRYPTSETUP --type luks open $DEVICE $FILENAME | |
if [ $? -ne 0 ]; then | |
echo "could not decrypt device" | |
exit 1 | |
fi | |
rm -rf $FILENAME-volume | |
mkdir $FILENAME-volume | |
$SUDO $MOUNT /dev/mapper/$FILENAME $FILENAME-volume | |
if [ $? -ne 0 ]; then | |
echo "could not mount device" | |
exit 1 | |
fi | |
USER=$(whoami) | |
$SUDO chown $USER:$(id -g -n $UID) $FILENAME-volume | |
if [ $? -ne 0 ]; then | |
echo "could not change access rights" | |
exit 1 | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
LOSETUP=$(which losetup) | |
SUDO=$(which sudo) | |
UMOUNT=$(which umount) | |
CRYPTSETUP=$(which cryptsetup) | |
FILE=$(realpath $1) | |
FILENAME=$(basename $1) | |
DEVICE=$($LOSETUP -j $FILE | cut -f1 -d:) | |
if [ ! -f "$FILE" ]; then | |
echo "ERROR $FILE does not exist" | |
exit 1 | |
fi | |
$SUDO $UMOUNT /dev/mapper/$FILENAME | |
if [ $? -ne 0 ]; then | |
echo "could not unmount the device" | |
exit 1 | |
fi | |
$SUDO $CRYPTSETUP close $FILENAME | |
if [ $? -ne 0 ]; then | |
echo "could not close crypt volume" | |
exit 1 | |
fi | |
$SUDO $LOSETUP -d $DEVICE | |
if [ $? -ne 0 ]; then | |
echo "could not detach loop device" | |
exit 1 | |
fi | |
rm -rf $FILENAME-volume | |
if [ $? -ne 0 ]; then | |
echo "could not remove volume directory" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment