crypt/open,close
This commit is contained in:
parent
aa2ed7014b
commit
36a0479882
1 changed files with 34 additions and 10 deletions
|
@ -50,23 +50,47 @@ rwx_crypt() {
|
|||
crypt_mount="${mount_root}/${crypt_arg}"
|
||||
case "${action}" in
|
||||
"${action_open}")
|
||||
local nbd_device="$(rwx_crypt_device)"
|
||||
echo "device: ${nbd_device}"
|
||||
# TODO connect device
|
||||
# TODO open device
|
||||
# TODO make mount directory
|
||||
# TODO mount file system
|
||||
local device
|
||||
if ! device="$(rwx_crypt_device)"; then
|
||||
rwx_log_error 4 "No device available"
|
||||
fi
|
||||
# connect device
|
||||
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}")
|
||||
# TODO unmount file system
|
||||
# TODO remove mount directory
|
||||
# TODO close device
|
||||
# unmount file system
|
||||
if ! umount "${crypt_mount}"; then
|
||||
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
|
||||
;;
|
||||
*) ;;
|
||||
esac
|
||||
else
|
||||
rwx_log_error 3 "Not a file"
|
||||
rwx_log_error 3 "Not a file: ${crypt_file}"
|
||||
fi
|
||||
done
|
||||
;;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue