forked from mirrored-repos/manjaro-tools
[miso_loop_mnt] find loop devices by path; https://gitlab.manjaro.org/tools/development-tools/manjaro-tools/issues/309
This commit is contained in:
parent
6569d444cc
commit
ac9e91cf52
1 changed files with 45 additions and 2 deletions
|
@ -1,9 +1,50 @@
|
|||
# vim: set ft=sh:
|
||||
|
||||
find_dev_by_path () {
|
||||
local path="${1}"
|
||||
local tmp_mnt=/tmp_mnt
|
||||
local _mnt
|
||||
local a d
|
||||
local device
|
||||
|
||||
[[ "$path" ]] || return 1
|
||||
|
||||
mkdir -p "${tmp_mnt}"
|
||||
|
||||
for a in 1 2 3; do
|
||||
for d in $(awk '{ print "/dev/"$4 }' /proc/partitions); do
|
||||
|
||||
# If the device is already mounted, it shouldn't be
|
||||
# unmounted after the check.
|
||||
|
||||
grep -q "^$d " /proc/mounts && {
|
||||
_mnt=$(grep "^$d " /proc/mounts | cut -d ' ' -f 2)
|
||||
unmount=
|
||||
} || {
|
||||
mount -r -t auto "${d}" "${tmp_mnt}" 2> /dev/null || continue
|
||||
_mnt="${tmp_mnt}"
|
||||
unmount=true
|
||||
}
|
||||
|
||||
# File exists in $d. Save $d on $device.
|
||||
|
||||
[[ -f "${_mnt}/${path}" ]] && device="${d}"
|
||||
[[ "${unmount}" ]] && umount "${tmp_mnt}" 2> /dev/null || true
|
||||
[[ "${device}" ]] && {
|
||||
echo "${device}"
|
||||
return
|
||||
}
|
||||
|
||||
done
|
||||
sleep 1
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
run_hook () {
|
||||
[[ -n "${img_label}" ]] && img_dev="/dev/disk/by-label/${img_label}"
|
||||
[[ -z "${img_flags}" ]] && img_flags="defaults"
|
||||
if [[ -n "${img_dev}" && -n "${img_loop}" ]]; then
|
||||
if [[ "${img_loop}" ]]; then
|
||||
img_dev=$(find_dev_by_path "${img_loop}")
|
||||
mount_handler="miso_loop_mount_handler"
|
||||
fi
|
||||
}
|
||||
|
@ -31,5 +72,7 @@ miso_loop_mount_handler () {
|
|||
if [[ "${copytoram}" == "y" ]]; then
|
||||
losetup -d ${_dev_loop} 2>/dev/null
|
||||
umount /run/miso/img_dev
|
||||
else
|
||||
echo $(readlink -f ${img_dev}) >> /run/miso/used_block_devices
|
||||
fi
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue