dotfiles-linux/.local/bin/mount-luks-partition-dump.sh
2024-01-06 03:41:49 +00:00

31 lines
565 B
Bash
Executable File

#!/bin/sh
error() {
echo "error: $@"
exit 1
}
set -e
DUMP="$1"
MOUNTPOINT=/media/luks-dump
[ -d "$MOUNTPOINT" ] && error "$MOUNTPOINT already exists, you must delete it first"
[ $EUID -ne 0 ] && error "must be run as root"
[ -f "$DUMP" ] || error "'$DUMP' is not a file or is not readable"
DEVICE=$(losetup -f)
losetup $DEVICE "$DUMP"
cryptsetup luksOpen $DEVICE luks-dump
mkdir $MOUNTPOINT
mount /dev/mapper/luks-dump $MOUNTPOINT
echo "press enter when done..."
read
umount $MOUNTPOINT
rmdir $MOUNTPOINT
cryptsetup luksClose luks-dump
losetup -d $DEVICE