crypt/device
This commit is contained in:
parent
f4f1aeaccf
commit
aa2ed7014b
1 changed files with 26 additions and 18 deletions
|
@ -2,9 +2,30 @@ _rwx_cmd_cs() { rwx_crypt "${@}"; }
|
||||||
|
|
||||||
RWX_CRYPT_ROOT="${HOME}/home/crypt"
|
RWX_CRYPT_ROOT="${HOME}/home/crypt"
|
||||||
|
|
||||||
|
rwx_crypt_device() {
|
||||||
|
local device size
|
||||||
|
local index=0
|
||||||
|
while [ -z "${device}" ]; do
|
||||||
|
device="/dev/nbd${index}"
|
||||||
|
if [ -b "${device}" ]; then
|
||||||
|
size="$(cat /sys/block/nbd"${index}/size")"
|
||||||
|
[ "${size}" -eq 0 ] ||
|
||||||
|
device=""
|
||||||
|
else
|
||||||
|
device=""
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
index=$((index + 1))
|
||||||
|
done
|
||||||
|
if [ -n "${device}" ]; then
|
||||||
|
echo "${device}"
|
||||||
|
else
|
||||||
|
rwx_log_error 1 "No device available"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
rwx_crypt() {
|
rwx_crypt() {
|
||||||
local action="${1}"
|
local action="${1}"
|
||||||
shift
|
|
||||||
local action_close="close"
|
local action_close="close"
|
||||||
local action_open="open"
|
local action_open="open"
|
||||||
local mapper="/dev/mapper"
|
local mapper="/dev/mapper"
|
||||||
|
@ -12,6 +33,7 @@ rwx_crypt() {
|
||||||
local crypt_arg crypt_file crypt_map crypt_mount pass_phrase
|
local crypt_arg crypt_file crypt_map crypt_mount pass_phrase
|
||||||
case "${action}" in
|
case "${action}" in
|
||||||
"${action_close}" | "${action_open}")
|
"${action_close}" | "${action_open}")
|
||||||
|
shift
|
||||||
local user_id
|
local user_id
|
||||||
user_id="$(id --user)"
|
user_id="$(id --user)"
|
||||||
[ "${user_id}" -eq 0 ] ||
|
[ "${user_id}" -eq 0 ] ||
|
||||||
|
@ -22,34 +44,20 @@ rwx_crypt() {
|
||||||
pass_phrase="$(rwx_read_passphrase)"
|
pass_phrase="$(rwx_read_passphrase)"
|
||||||
for crypt_arg in "${@}"; do
|
for crypt_arg in "${@}"; do
|
||||||
rwx_log_info
|
rwx_log_info
|
||||||
crypt_file="${RWX_CRYPT_ROOT}/${crypt_arg}"
|
crypt_file="${RWX_CRYPT_ROOT}/${crypt_arg}.qcow2"
|
||||||
if [ -f "${crypt_file}" ]; then
|
if [ -f "${crypt_file}" ]; then
|
||||||
crypt_map="${mapper}/${crypt_arg}"
|
crypt_map="${mapper}/${crypt_arg}"
|
||||||
crypt_mount="${mount_root}/${crypt_arg}"
|
crypt_mount="${mount_root}/${crypt_arg}"
|
||||||
case "${action}" in
|
case "${action}" in
|
||||||
"${action_open}")
|
"${action_open}")
|
||||||
rwx_log_info "OPEN"
|
local nbd_device="$(rwx_crypt_device)"
|
||||||
local nbd_device nbd_size
|
echo "device: ${nbd_device}"
|
||||||
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 connect device
|
||||||
# TODO open device
|
# TODO open device
|
||||||
echo "${pass_phrase}"
|
|
||||||
# TODO make mount directory
|
# TODO make mount directory
|
||||||
# TODO mount file system
|
# TODO mount file system
|
||||||
;;
|
;;
|
||||||
"${action_close}")
|
"${action_close}")
|
||||||
rwx_log_info "CLOSE"
|
|
||||||
# TODO unmount file system
|
# TODO unmount file system
|
||||||
# TODO remove mount directory
|
# TODO remove mount directory
|
||||||
# TODO close device
|
# TODO close device
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue