Created
April 10, 2016 02:59
-
-
Save 0x1F602/a9db67131080a2c277a50b7a36661287 to your computer and use it in GitHub Desktop.
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 | |
COMMAND=$1 | |
FILENAME=$2 | |
FILESIZE=$3 | |
usage() { | |
echo "Usage: ./simpleluks.sh command [args ...]" | |
echo " ./simpleluks.sh create some_name size_in_GB" | |
echo " ./simpleluks.sh open some_name" | |
echo " ./simpleluks.sh close some_name" | |
} | |
# No command? Show help | |
if [ "$#" -lt 2 ]; then | |
usage | |
else | |
# Accept command | |
echo "Command: $COMMAND" | |
if [ "$COMMAND" = "create" ]; then | |
if [ "$#" -lt 3 ]; then | |
usage | |
exit | |
fi | |
# create | |
# Accept filename, size of file in gigabytes, filesystem | |
echo "Writing zeroes into $FILENAME" | |
sudo dd if=/dev/zero bs=1G count="$FILESIZE" of="$FILENAME" | |
echo "Preparing $FILENAME for LUKS" | |
sudo cryptsetup luksFormat "$FILENAME" | |
echo "Opening $FILENAME with LUKS" | |
sudo cryptsetup luksOpen "$FILENAME" "$FILENAME" | |
echo "Writing ext4 filesystem to $FILENAME" | |
sudo mkfs.ext4 "/dev/mapper/$FILENAME" | |
echo "Creating $HOME/cryptoluks/$FILENAME" | |
mkdir -p "$HOME/cryptoluks/$FILENAME" | |
echo "Mounting $filename to $HOME/cryptoluks/$FILENAME" | |
sudo mount -t ext4 "/dev/mapper/$FILENAME" "$HOME/cryptoluks/$FILENAME" | |
echo "Done!" | |
echo "You may want to run sudo chown $USER -R $HOME/cryptoluks/$FILENAME" | |
elif [ "$COMMAND" = "open" ]; then | |
# open | |
sudo cryptsetup luksOpen "$FILENAME" "$FILENAME" | |
mkdir -p "$HOME/cryptoluks/$FILENAME" | |
sudo mount -t ext4 "/dev/mapper/$FILENAME" "$HOME/cryptoluks/$FILENAME" | |
echo "Mounted $FILENAME to $HOME/cryptoluks/$FILENAME" | |
elif [ "$COMMAND" = "close" ]; then | |
# close | |
sudo umount "$HOME/cryptoluks/$FILENAME" \ | |
&& sudo cryptsetup luksClose "$FILENAME" \ | |
&& rm -r "$HOME/cryptoluks/$FILENAME" | |
echo "Unmounted and closed $FILENAME" | |
else | |
usage | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment