Disk : Add funlock, fmount and funmount.
This commit is contained in:
parent
0a6bd62f8a
commit
1eb2a9ff79
|
@ -13,40 +13,58 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
# Unlock encrypted disk file.
|
# Unlock encrypted disk file.
|
||||||
# Usage: funlock <FILE> <DIR>
|
# Usage: funlock <FILE>
|
||||||
function funlock() {
|
function funlock() {
|
||||||
if [[ "''${UID}" != 0 ]]; then
|
|
||||||
_error "Must be root."
|
|
||||||
return 2
|
|
||||||
fi
|
|
||||||
|
|
||||||
local file="''${1}"
|
local file="''${1}"
|
||||||
local dir="''${2}"
|
|
||||||
|
|
||||||
if [[ "''${dir}" = "" ]]; then
|
if [[ "''${file}" = "" ]]; then
|
||||||
help funlock
|
help funlock
|
||||||
return 2
|
return 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local name=$(parse_alnum "''${file##*/}")
|
local name=$(parse_alnum "''${file##*/}")
|
||||||
cryptsetup open "''${file}" "''${name}"
|
|
||||||
mount "/dev/mapper/''${name}" "''${dir}"
|
local loop=$(udisksctl loop-setup --no-user-interaction --file "''${file}")
|
||||||
|
loop="''${loop##* }"; loop="''${loop%.}"
|
||||||
|
|
||||||
|
local decrypted=$(udisksctl unlock --block-device "''${loop}")
|
||||||
|
decrypted="''${decrypted##* }"; decrypted="''${decrypted%.}"
|
||||||
|
|
||||||
|
local mount=$(udisksctl mount --no-user-interaction --block-device "''${decrypted}")
|
||||||
|
mount="''${mount#* at }"
|
||||||
|
|
||||||
|
cd "''${mount}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Unlock encrypted disk file.
|
# Mount file.
|
||||||
# Usage: unlock <FILE>
|
# Usage: fmount <FILE>
|
||||||
# function unlock() {
|
function fmount() {
|
||||||
# _filter() {
|
local file="''${1}"
|
||||||
# sed -e "s/.*\ a[st]\ //" -e "s/\.$//"
|
if [[ "''${file}" = "" ]]; then
|
||||||
# }
|
help fmount
|
||||||
# local file="''${1}"
|
return 2
|
||||||
# local name=$(parse_alnum ''${file} | _filter)
|
fi
|
||||||
# local loop=$(udisksctl loop-setup -f "''${file}" | _filter)
|
|
||||||
# local unlock=$(udisksctl unlock -b "''${loop}" | _filter)
|
|
||||||
# local mount=$(udisksctl mount -b "''${unlock}" | _filter)
|
|
||||||
|
|
||||||
# [ -L "./''${name}" ] || ln -s "''${mount}" "./''${name}"
|
local loop=$(udisksctl loop-setup --no-user-interaction --file "''${file}")
|
||||||
# cd "''${mount}"
|
loop="''${loop##* }"; loop="''${loop%.}"
|
||||||
# }
|
|
||||||
|
local mount=$(udisksctl mount --no-user-interaction --block-device "''${loop}")
|
||||||
|
mount="''${mount#* at }"
|
||||||
|
|
||||||
|
cd "''${mount}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Unmount file.
|
||||||
|
# Usage: fumount <LOOPDEVICE>
|
||||||
|
function fumount() {
|
||||||
|
local loop="''${1}"
|
||||||
|
if [[ "''${loop}" = "" ]]; then
|
||||||
|
help fumount
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
udisksctl unmount --no-user-interaction --block-device "''${loop}"
|
||||||
|
udisksctl loop-delete --no-user-interaction --block-device "''${loop}"
|
||||||
|
}
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue