Added luks-wrapper script

This commit is contained in:
114465 2024-05-16 22:33:44 -04:00
parent 6a6c696850
commit 45c7bee4ed
3 changed files with 144 additions and 0 deletions

15
luks-wrapper/LICENSE Normal file
View File

@ -0,0 +1,15 @@
ISC License
Copyright (c) 2024 114465
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.

7
luks-wrapper/README.md Normal file
View File

@ -0,0 +1,7 @@
# ALPHA
Please don't use this for anything too important, I still have so much to test and fix in this project
# What is this?
This is a script to create and use luks container files

122
luks-wrapper/luks-wrapper.sh Executable file
View File

@ -0,0 +1,122 @@
#!/bin/bash
version="Early Development 0.0.1a\nPublic"
man() {
echo -e "Usage: sudo ./luks-wrapper [-c /path/to/containerfile] [-u /path/to/containerfile] [-l /path/to/mountpoint] [-d /path/to/containerfile] [-ud /path/to/containerfile /path/to/header]\n\nOPTIONS:\n-c, --create: Makes LUKS container\n-u, --unlock: Unlocks and mounts a contaner file\n-l, --lock: Locks and unmounts a unlocked contaner\n-d, --detach: Detach the header of a container\n-ud, --unlockdetached: Unlock a container that has a detached header\n-V, --version: Prints script version\n-h, --help: Prints this help page\n\n$version\n"
}
create() {
size=$(whiptail --inputbox "Size of container? ex. 5G" 8 39 1G --title "Create container file" 3>&1 1>&2 2>&3)
case $? in
0) truncate -s $size $1;;
1) whiptail --title "Canceled" --msgbox "Cancel was selected" 8 39; exit 0;;
esac
path=$(losetup -f --show $1 | head -n 1)
cryptsetup luksFormat $path
name=$(whiptail --inputbox "Name? Make sure this name is not an already in /dev/mapper." 8 39 TEMP --title "Temporary Name" 3>&1 1>&2 2>&3)
fs=$(whiptail --title "Container Filesystem" --radiolist "Select a filesystem." 15 39 8 "ext4" "" ON "ext3" "" OFF "xfs" "" OFF "fat" "" OFF "f2fs" "" OFF "btrfs" "" OFF "exfat" "" OFF "ntfs" "" OFF 3>&1 1>&2 2>&3)
clear
cryptsetup luksOpen $path $name
mkfs.$fs /dev/mapper/$name
cryptsetup close $name
whiptail --title "Container made!" --msgbox "Enjoy!" 8 39
exit 0
}
unlock() {
path=$(losetup -f --show $1 | head -n 1)
name=$(whiptail --inputbox "Name? Make sure this name is not an already in /dev/mapper." 8 39 TEMP --title "Temporary Name" 3>&1 1>&2 2>&3)
case $? in
1) exit 0;;
esac
mount=$(whiptail --inputbox "Mount point? Where would you like to mount your container?" 8 39 /mnt --title "Mount Point" 3>&1 1>&2 2>&3)
case $? in
1) exit 0;;
esac
clear
cryptsetup luksOpen $path $name
mount /dev/mapper/$name $mount
}
lock() {
umount $1
name=$(whiptail --inputbox "What is the name of the container?" 8 39 TEMP --title "Name" 3>&1 1>&2 2>&3)
case $? in
1) exit 0;;
esac
loop=$(whiptail --inputbox "What is the loop the container is mounted to?" 8 39 loop0 --title "loop" 3>&1 1>&2 2>&3)
case $? in
1) exit 0;;
esac
cryptsetup close $name
losetup -d $loop
}
detach() {
path=$(losetup -f --show $1 | head -n 1)
backup=$(whiptail --inputbox "Where would you like the header to be located?" 8 39 ~/Header.bak --title "Backup Location" 3>&1 1>&2 2>&3)
cryptsetup luksHeaderBackup $path --header-backup-file $backup
offset=$(cryptsetup luksDump $path | head -n 13 | tail -n 1 | sed 's/.*: //' | sed 's/\s.*$//')
dd if=/dev/zero of=$path bs=$offset count=1
losetup -d $path
}
unlockdetached() {
path=$(losetup -f --show $1 | head -n 1)
name=$(whiptail --inputbox "Name? Make sure this name is not an already in
/dev/mapper." 8 39 TEMP --title "Temporary Name" 3>&1 1>&2 2>&3)
mount=$(whiptail --inputbox "Mount point? Where would you like to mount yo
ur container?" 8 39 /mnt --title "Mount Point" 3>&1 1>&2 2>&3)
clear
cryptsetup luksOpen $path $name --header=$2
mount /dev/mapper/$name $mount
}
case "$EUID" in
0)
case $1 in
-c|--create)
case $# in
2) create $2;;
*) echo "Incorrect number of arguments, see -h for help"; exit 1;;
esac;;
-u|--unlock)
case $# in
2) unlock $2;;
*) echo "Incorrect number of arguments, see -h for help"; exit 1;;
esac;;
-l|--lock)
case $# in
2) lock $2;;
*) echo "Incorrect number of arguments, see -h for help"; exit 1;;
esac;;
-d|--detach)
case $# in
2) detach $2;;
*) echo "Incorrect number of arguments, see -h for help"; exit 1;;
esac;;
-ud|--unlockdetached)
case $# in
3) unlockdetached $2 $3;;
*) echo "Incorrect number of arguments, see -h for help"; exit 1;;
esac;;
-V|--version) echo -e $version;;
-h|--help) man;;
"") man;;
*) echo "Unknown argument $1, use -h for help"; exit 1;;
esac;;
*)
case $1 in
-V|--version) echo -e $version;;
-h|--help) man;;
"") man;;
*) echo "Script needs to be run as root"; exit 2;;
esac;;
esac