simplify while loops

This commit is contained in:
Tobias Powalowski 2024-06-04 15:09:43 +02:00
parent a861a15f59
commit 444d872139

View file

@ -767,10 +767,9 @@ _enter_luks_name() {
} }
_enter_luks_passphrase () { _enter_luks_passphrase () {
_LUKSPASSPHRASE=""
_LUKSPASS="" _LUKSPASS=""
_LUKSPASS2="" _LUKSPASS2=""
while [[ -z "${_LUKSPASSPHRASE}" ]]; do while true; do
while [[ -z "${_LUKSPASS}" ]]; do while [[ -z "${_LUKSPASS}" ]]; do
_dialog --no-cancel --insecure --passwordbox "Enter passphrase for luks encrypted device ${_LUKSDEV}:" 8 70 2>"${_ANSWER}" || return 1 _dialog --no-cancel --insecure --passwordbox "Enter passphrase for luks encrypted device ${_LUKSDEV}:" 8 70 2>"${_ANSWER}" || return 1
_LUKSPASS=$(cat "${_ANSWER}") _LUKSPASS=$(cat "${_ANSWER}")
@ -783,10 +782,10 @@ _enter_luks_passphrase () {
_LUKSPASSPHRASE=${_LUKSPASS} _LUKSPASSPHRASE=${_LUKSPASS}
echo "${_LUKSPASSPHRASE}" > "/tmp/passphrase-${_LUKSDEV}" echo "${_LUKSPASSPHRASE}" > "/tmp/passphrase-${_LUKSDEV}"
_LUKSPASSPHRASE="/tmp/passphrase-${_LUKSDEV}" _LUKSPASSPHRASE="/tmp/passphrase-${_LUKSDEV}"
break
else else
_dialog --no-mouse --infobox "Passphrases didn't match, please enter again." 0 0 _dialog --no-mouse --infobox "Passphrases didn't match, please enter again." 0 0
sleep 3 sleep 3
_LUKSPASSPHRASE=""
_LUKSPASS="" _LUKSPASS=""
_LUKSPASS2="" _LUKSPASS2=""
fi fi
@ -795,17 +794,15 @@ _enter_luks_passphrase () {
_opening_luks() { _opening_luks() {
_dialog --no-mouse --infobox "Opening encrypted ${_DEV}..." 0 0 _dialog --no-mouse --infobox "Opening encrypted ${_DEV}..." 0 0
_LUKSOPEN_SUCCESS="" while true; do
while [[ -z "${_LUKSOPEN_SUCCESS}" ]]; do cryptsetup luksOpen "${_DEV}" "${_LUKSDEV}" <"${_LUKSPASSPHRASE}" >"${_LOG}" && break
cryptsetup luksOpen "${_DEV}" "${_LUKSDEV}" <"${_LUKSPASSPHRASE}" >"${_LOG}" && _LUKSOPEN_SUCCESS=1 _dialog --no-mouse --infobox "Error: Passphrase didn't match, please enter again" 0 0
if [[ -z "${_LUKSOPEN_SUCCESS}" ]]; then
_dialog --no-mouse --infobox "Error: Passphrase didn't match, please enter again." 0 0
sleep 5 sleep 5
_enter_luks_passphrase || return 1 _enter_luks_passphrase || return 1
fi
done done
_dialog --yesno "Would you like to save the passphrase of luks device in /etc/$(basename "${_LUKSPASSPHRASE}")?\nName:${_LUKSDEV}" 0 0 || _LUKSPASSPHRASE="ASK" if _dialog --yesno "Would you like to save the passphrase of luks device in /etc/$(basename "${_LUKSPASSPHRASE}")?\nName:${_LUKSDEV}" 0 0; then
echo "${_LUKSDEV}" "${_DEV}" "/etc/$(basename "${_LUKSPASSPHRASE}")" >> /tmp/.crypttab echo "${_LUKSDEV}" "${_DEV}" "/etc/$(basename "${_LUKSPASSPHRASE}")" >> /tmp/.crypttab
fi
} }
_helpluks() _helpluks()
@ -815,9 +812,7 @@ _dialog --msgbox "$(cat /usr/lib/archboot/installer/help/luks.txt)" 0 0
_createluks() _createluks()
{ {
_NAME_SCHEME_PARAMETER_RUN="" while true; do
_LUKSFINISH=""
while [[ "${_LUKSFINISH}" != "DONE" ]]; do
_activate_special_devices _activate_special_devices
_dialog --no-mouse --infobox "Scanning blockdevices... This may need some time." 3 60 _dialog --no-mouse --infobox "Scanning blockdevices... This may need some time." 3 60
# Remove all crypt devices with children # Remove all crypt devices with children
@ -845,7 +840,7 @@ _createluks()
### TODO: offer more options for encrypt! ### TODO: offer more options for encrypt!
### defaults are used only ### defaults are used only
# final step ask if everything is ok? # final step ask if everything is ok?
_dialog --yesno "Would you like to encrypt luks device below?\nName:${_LUKSDEV}\nDevice:${_DEV}\n" 0 0 && _LUKSFINISH="DONE" _dialog --yesno "Would you like to encrypt luks device below?\nName:${_LUKSDEV}\nDevice:${_DEV}\n" 0 0 && break
done done
_enter_luks_passphrase || return 1 _enter_luks_passphrase || return 1
_umountall _umountall