Add dynamic width calculation

This commit is contained in:
Santiago Lo Coco 2021-12-27 19:46:22 -03:00
parent 00540a534d
commit 89930c09a3
1 changed files with 12 additions and 6 deletions

View File

@ -98,7 +98,7 @@ mountPart() {
} }
installPackage() { installPackage() {
whiptail --infobox "Installing '$1'." 7 40 calcWidthAndRun "whiptail --infobox "Installing '$1'." 7 WIDTH"
case ${2} in case ${2} in
Y) Y)
if [ -z $username ]; then if [ -z $username ]; then
@ -183,15 +183,20 @@ networkConf() {
unset hostname unset hostname
} }
calcWidthAndRun() {
width=$(echo "$@" | grep -oP '(?<=").*?(?=")' | wc -c)
echo $(eval $(echo "$@" | sed "s/WIDTH/$((${width}+8))/g"))
}
askForPassword() { askForPassword() {
password=$(whiptail --passwordbox "Now, enter the password for ${1}." 8 40 3>&1 1>&2 2>&3) password=$(calcWidthAndRun "whiptail --passwordbox \"Now, enter the password for ${1}.\" 8 WIDTH 3>&1 1>&2 2>&3")
exitIfCancel "You must enter a password." "${2}" exitIfCancel "You must enter a password." "${2}"
passwordRep=$(whiptail --passwordbox "Reenter password." 8 30 3>&1 1>&2 2>&3) passwordRep=$(calcWidthAndRun "whiptail --passwordbox \"Reenter password.\" 8 WIDTH 3>&1 1>&2 2>&3")
exitIfCancel "You must enter a password." "${2}" exitIfCancel "You must enter a password." "${2}"
while ! [ "$password" = "$passwordRep" ]; do while ! [ "$password" = "$passwordRep" ]; do
password=$(whiptail --passwordbox "Passwords do not match! Please enter the password again." 8 65 3>&1 1>&2 2>&3) password=$(calcWidthAndRun "whiptail --passwordbox \"Passwords do not match! Please enter the password again.\" 8 WIDTH 3>&1 1>&2 2>&3")
exitIfCancel "You must enter a password." "${2}" exitIfCancel "You must enter a password." "${2}"
passwordRep=$(whiptail --passwordbox "Reenter password." 8 30 3>&1 1>&2 2>&3) passwordRep=$(calcWidthAndRun "whiptail --passwordbox \"Reenter password.\" 8 WIDTH 3>&1 1>&2 2>&3")
exitIfCancel "You must enter a password." "${2}" exitIfCancel "You must enter a password." "${2}"
done done
unset passwordRep unset passwordRep
@ -318,4 +323,5 @@ runScript() {
done done
} }
runScript # runScript
askForPassword