Files
myscripts/mount_encrypt.sh
2016-06-09 00:41:48 +02:00

29 lines
604 B
Bash

#!/bin/bash
Device=$1
MountPoint=$2
MapName=$3
ContainerName="${MapName}foo"
red=`tput setaf 1`
green=`tput setaf 2`
reset=`tput sgr0`
CMD=("cryptsetup" "luksOpen" "$Device" "$ContainerName")
if ! "${CMD[@]}"; then
echo "${red} can't open Device $Device ${reset}"
exit 1
fi
sleep 3
vgchange -ay
sleep 3
CMD=("mount" "/dev/mapper/${MapName}" "$MountPoint")
if ! "${CMD[@]}"; then
lvchange -a n "/dev/mapper/${MapName}"
cryptsetup luksClose "$ContainerName"
echo "${red}mount of $Device to $MountPoint failed ${reset}"
exit 1
fi
echo "${green}success mount $Device to $MountPoint ${reset}"