crypt/open,close

This commit is contained in:
Marc Beninca 2025-03-30 20:18:20 +02:00
parent aa2ed7014b
commit 36a0479882
Signed by: marc.beninca
GPG key ID: 9C7613450C80C24F

View file

@ -50,23 +50,47 @@ rwx_crypt() {
crypt_mount="${mount_root}/${crypt_arg}" crypt_mount="${mount_root}/${crypt_arg}"
case "${action}" in case "${action}" in
"${action_open}") "${action_open}")
local nbd_device="$(rwx_crypt_device)" local device
echo "device: ${nbd_device}" if ! device="$(rwx_crypt_device)"; then
# TODO connect device rwx_log_error 4 "No device available"
# TODO open device fi
# TODO make mount directory # connect device
# TODO mount file system if ! qemu-nbd --connect "${device}" "${crypt_file}"; then
rwx_log_error 5 "Connection failure: ${device}"
fi
# open device
echo "${pass_phrase}" |
cryptsetup luksOpen "${device}" "${crypt_arg}"
# make mount directory
if ! mkdir --parents "${crypt_mount}"; then
rwx_log_error 7 "Making failure: ${crypt_mount}"
fi
# mount file system
if ! mount \
--options "autodefrag,compress-force=zstd" \
"${crypt_map}" "${crypt_mount}"; then
rwx_log_error 8 "Mounting failure: ${crypt_map}"
fi
;; ;;
"${action_close}") "${action_close}")
# TODO unmount file system # unmount file system
# TODO remove mount directory if ! umount "${crypt_mount}"; then
# TODO close device rwx_log_error 4 "Unmounting failure: ${crypt_mount}"
fi
# remove mount directory
if ! rmdir "${crypt_mount}"; then
rwx_log_error 5 "Removal failure: ${crypt_mount}"
fi
# close device
if ! cryptsetup luksClose "${crypt_arg}"; then
rwx_log_error 6 "Closing failure: ${crypt_arg}"
fi
# TODO disconnect device # TODO disconnect device
;; ;;
*) ;; *) ;;
esac esac
else else
rwx_log_error 3 "Not a file" rwx_log_error 3 "Not a file: ${crypt_file}"
fi fi
done done
;; ;;