dmount/dumount.sh

59 lines
1.3 KiB
Bash
Executable file

#/bin/bash
Version=1.0.0
Usage="dumount.sh [PARAMETTER]
Umount a LVM on LUKS device. In case it was unplugged without being unmounted, use dmsetup tu force the deactivation of the lvm drive.
PARAMETER
-h, --help Print this help and exit
-v, --version Print the version of this program and exit
"
for i in $@; do
case "$i" in
"-h" | "--help")
echo "${Usage}"
exit 0
;;
"-v" | "--version")
echo "dmount.sh v.${Version}"
exit 0
;;
esac
done
MOUNTPOINT_cours=/home/primardj/cours
MOUNTPOINT_doc=/home/primardj/Documents
MOUNTPOINT_virt_machine=/home/primardj/virtual_machine
MOUNTPOINT_data=/home/primardj/data
remove_vgdevices() {
echo "force remove devices." >&2
doas dmsetup info --columns
echo "removing all cryptdata volumes" >&2
sleep 3
array=(/dev/mapper/cryptdata-*)
for i in ${array[@]}; do
echo "$i"
doas dmsetup remove "$i"
done
doas dmsetup remove cryptdata
}
echo locking device cryptdata
doas umount -R $MOUNTPOINT_cours
doas umount -R $MOUNTPOINT_doc
doas umount -R $MOUNTPOINT_virt_machine
doas umount -R $MOUNTPOINT_data
doas lvchange -a n cryptdata || remove_vgdevices
doas cryptsetup close cryptdata