From f4f1aeaccff2253721a474438fff37213d566a54 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sun, 30 Mar 2025 16:45:48 +0200 Subject: [PATCH] cs/device --- sh/cryptsetup.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/sh/cryptsetup.sh b/sh/cryptsetup.sh index 0f2629c..b7da532 100644 --- a/sh/cryptsetup.sh +++ b/sh/cryptsetup.sh @@ -29,7 +29,19 @@ rwx_crypt() { case "${action}" in "${action_open}") rwx_log_info "OPEN" - # TODO find next available device + local nbd_device nbd_size + local nbd_index=0 + while [ -z "${nbd_device}" ]; do + if [ -f "/dev/nbd${nbd_index}" ]; then + nbd_size="$(cat /sys/block/nbd"${nbd_index}/size")" + [ "${nbd_size}" -eq 0 ] && + nbd_device="/dev/nbd${nbd_index}" + fi + nbd_index=$((nbd_index + 1)) + done + [ -z "${nbd_device}" ] && + rwx_log_error 4 "No device available" + rwx_log_info "device: ${nbd_device}" # TODO connect device # TODO open device echo "${pass_phrase}"