simplify while loops

This commit is contained in:
Tobias Powalowski 2024-06-04 14:47:03 +02:00
parent 02f190c906
commit a861a15f59

View file

@ -624,10 +624,8 @@ _findvg()
_createvg() _createvg()
{ {
_VGFINISH="" while true; do
while [[ "${_VGFINISH}" != "> DONE" ]]; do
: >/tmp/.pvs : >/tmp/.pvs
_VGDEV=""
_PVS=$(_findpv) _PVS=$(_findpv)
# break if all devices are in use # break if all devices are in use
if [[ -z "${_PVS}" ]]; then if [[ -z "${_PVS}" ]]; then
@ -651,7 +649,7 @@ _createvg()
_dialog --no-cancel --menu "Select Physical Volume ${_PVNUMBER} for ${_VGDEV}:" 13 50 10 ${_PVS} 2>"${_ANSWER}" || return 1 _dialog --no-cancel --menu "Select Physical Volume ${_PVNUMBER} for ${_VGDEV}:" 13 50 10 ${_PVS} 2>"${_ANSWER}" || return 1
_PV=$(cat "${_ANSWER}") _PV=$(cat "${_ANSWER}")
echo "${_PV}" >>/tmp/.pvs echo "${_PV}" >>/tmp/.pvs
while [[ "${_PVS}" != "DONE" ]]; do while [[ "${_PVS}" != "> DONE" ]]; do
_PVNUMBER=$((_PVNUMBER + 1)) _PVNUMBER=$((_PVNUMBER + 1))
# clean loop from used partition and options # clean loop from used partition and options
_PVS="${_PVS//$(${_LSBLK} NAME,SIZE -d "${_DEV}" 2>"${_NO_LOG}")/}" _PVS="${_PVS//$(${_LSBLK} NAME,SIZE -d "${_DEV}" 2>"${_NO_LOG}")/}"
@ -664,7 +662,7 @@ _createvg()
echo "${_PV}" >>/tmp/.pvs echo "${_PV}" >>/tmp/.pvs
done done
# final step ask if everything is ok? # final step ask if everything is ok?
_dialog --yesno "Would you like to create Volume Group like this?\n\n${_VGDEV}\n\nPhysical Volumes:\n$(sed -e 's#$#\\n#g' /tmp/.pvs)" 0 0 && _VGFINISH="DONE" _dialog --yesno "Would you like to create Volume Group like this?\n\n${_VGDEV}\n\nPhysical Volumes:\n$(sed -e 's#$#\\n#g' /tmp/.pvs)" 0 0 && break
done done
_PV="$(echo -n "$(cat /tmp/.pvs)")" _PV="$(echo -n "$(cat /tmp/.pvs)")"
_umountall _umountall
@ -680,10 +678,7 @@ _createvg()
_createlv() _createlv()
{ {
_LVFINISH="" while true; do
while [[ "${_LVFINISH}" != "DONE" ]]; do
_LVDEV=""
_LV_SIZE_SET=""
_LVS=$(_findvg) _LVS=$(_findvg)
# break if all devices are in use # break if all devices are in use
if [[ -z "${_LVS}" ]]; then if [[ -z "${_LVS}" ]]; then
@ -704,26 +699,28 @@ _createlv()
_LVDEV="" _LVDEV=""
fi fi
done done
while [[ -z "${_LV_SIZE_SET}" ]]; do while true; do
_LV_ALL="" _LV_ALL=""
_dialog --no-cancel --inputbox "Enter the size (M/MiB) of your Logical Volume,\nMinimum value is > 0.\n\nVolume space left: $(vgs -o vg_free --noheading --units M "${_LV}")\n\nIf you enter no value, all free space left will be used." 12 65 "" 2>"${_ANSWER}" || return 1 _dialog --no-cancel --inputbox "Enter the size (M/MiB) of your Logical Volume,\nMinimum value is > 0.\n\nVolume space left: $(vgs -o vg_free --noheading --units M "${_LV}")\n\nIf you enter no value, all free space left will be used." 12 65 "" 2>"${_ANSWER}" || return 1
_LV_SIZE=$(cat "${_ANSWER}") _LV_SIZE=$(cat "${_ANSWER}")
if [[ -z "${_LV_SIZE}" ]]; then if [[ -z "${_LV_SIZE}" ]]; then
_LV_ALL=1 _LV_ALL=1
_LV_SIZE_SET=1 break
elif [[ "${_LV_SIZE}" == 0 ]]; then elif [[ "${_LV_SIZE}" == 0 ]]; then
_dialog --msgbox "ERROR: You have entered a invalid size, please enter again." 0 0 _dialog --msgbox "ERROR: You have entered a invalid size, please enter again." 0 0
else else
if [[ "${_LV_SIZE}" -ge "$(vgs -o vg_free --noheading --units M | sed -e 's#m##g')" ]]; then if [[ "${_LV_SIZE}" -ge "$(vgs -o vg_free --noheading --units M | sed -e 's#m##g')" ]]; then
_dialog --msgbox "ERROR: You have entered a too large size, please enter again." 0 0 _dialog --msgbox "ERROR: You have entered a too large size, please enter again." 0 0
else else
_LV_SIZE_SET=1 break
fi fi
fi fi
done done
#Contiguous doesn't work with +100%FREE #Contiguous doesn't work with +100%FREE
_LV_CONTIGUOUS="" _LV_CONTIGUOUS=""
[[ -z "${_LV_ALL}" ]] && _dialog --defaultno --yesno "Would you like to create Logical Volume as a contiguous partition, that means that your space doesn't get partitioned over one or more disks nor over non-contiguous physical extents.\n(usefull for swap space etc.)?" 0 0 && _LV_CONTIGUOUS=1 if [[ -z "${_LV_ALL}" ]]; then
_dialog --defaultno --yesno "Would you like to create Logical Volume as a contiguous partition, that means that your space doesn't get partitioned over one or more disks nor over non-contiguous physical extents.\n(usefull for swap space etc.)?" 0 0 && _LV_CONTIGUOUS=1
fi
if [[ -n "${_LV_CONTIGUOUS}" ]]; then if [[ -n "${_LV_CONTIGUOUS}" ]]; then
_CONTIGUOUS=yes _CONTIGUOUS=yes
_LV_EXTRA="-W y -C y -y" _LV_EXTRA="-W y -C y -y"
@ -733,7 +730,7 @@ _createlv()
fi fi
[[ -z "${_LV_SIZE}" ]] && _LV_SIZE="All free space left" [[ -z "${_LV_SIZE}" ]] && _LV_SIZE="All free space left"
# final step ask if everything is ok? # final step ask if everything is ok?
_dialog --yesno "Would you like to create Logical Volume ${_LVDEV} like this?\nVolume Group: ${_LV}\nVolume Size: ${_LV_SIZE}\nContiguous Volume: ${_CONTIGUOUS}" 0 0 && _LVFINISH="DONE" _dialog --yesno "Would you like to create Logical Volume ${_LVDEV} like this?\nVolume Group: ${_LV}\nVolume Size: ${_LV_SIZE}\nContiguous Volume: ${_CONTIGUOUS}" 0 0 && break
done done
_umountall _umountall
if [[ -n "${_LV_ALL}" ]]; then if [[ -n "${_LV_ALL}" ]]; then