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}"
|
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
|
||||||
;;
|
;;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue