merge dmount.sh with dmount

This commit is contained in:
primardj 2024-01-23 13:51:55 +00:00
parent 98c98e9ed3
commit 42671a7e52

51
dmount
View file

@ -1,7 +1,7 @@
#!/usr/bin/bash
Version=1.1.0
Version="1.1.0"
Usage="dmount PARAMETER
Script which permit to mount/unmount an LVM on LUKS using dmcrypt, doas and fstab.
@ -14,3 +14,52 @@ PARAMETRES
-u, --umount Unmount cryptdata
-r, --recover Permit to recover from a state where the ssd where hot unplug to an unplug state.
"
force_remove_vgdevice() {
echo "force remove vg cryptdata"
doas dmsetup info --columns
doas dmsetup remove /dev/mapper/cryptdata-*
doas dmsetup remove /dev/mapper/cryptdata
}
mount_lvm_on_luks() {
echo "unlocking device cryptdata"
doas rc-service dmcrypt restart
doas vgchange -a y cryptdata
doas mount -a
}
umount_lvm_on_luks() {
echo "locking device cryptdata"
doas umount -R /home/primardj || echo "Error, can't umount devices" >&2 && exit 0
doas lvchange -a n cryptdata || force_remove_vgdevice
doas cryptsetup close cryptdata
}
for i in "$@"; do
case "$i" in
"-h" | "--help")
echo "${Usage}"
exit 0
;;
"-v" | "--version")
echo "dmount v.${Version}"
exit 0
;;
"-m" | "--mount")
mount_lvm_on_luks
exit 0
;;
"-u" | "--umount")
umount_lvm_on_luks
exit 0
;;
"-r" | "--recover")
force_remove_vgdevice
exit 0
;;
esac
done