dotfiles/bin/lmount

42 lines
659 B
Plaintext
Raw Normal View History

2018-06-09 19:18:47 +02:00
#!/bin/bash
#: lmount
#: open + mount luks encrypted storage
#:
set -e
set -o pipefail
set -x
device=$1
target=$2
main() {
if (( $# != 2 )); then
echo "Must be called with 2 args!"
echo " $0 $device $target"
exit 1
fi
if [ "$EUID" -ne 0 ]
then echo "Must be run as root!"
exit 1
fi
luksname=$(basename ${target})
if [ ! -d "${target}" ]; then
mkdir -p ${target}
fi
echo "Opening ${device} as ${luksname}"
sudo cryptsetup open ${device} ${luksname}
echo " ... mounting to ${target}"
sudo mount /dev/mapper/${luksname} ${target}
echo "done..."
}
main $@