Use generic calcAndRun
This commit is contained in:
parent
bad19e05c2
commit
bcae0175ec
57
install.sh
57
install.sh
|
@ -333,61 +333,16 @@ networkConf() {
|
||||||
unset hostname
|
unset hostname
|
||||||
}
|
}
|
||||||
|
|
||||||
calcWidthDialog() {
|
calcAndRun() {
|
||||||
str=$1; count=1; found=false; option=1
|
|
||||||
for (( i = 0; i < ${#str}; i++ )); do
|
|
||||||
if [ "${str:$i:1}" = "\\" ] && [ "${str:$((i+1)):1}" = "n" ]; then
|
|
||||||
[ $count -ge $option ] && option=$count
|
|
||||||
found=true
|
|
||||||
count=-1
|
|
||||||
fi
|
|
||||||
((count++))
|
|
||||||
done
|
|
||||||
[ $option -ge $count ] && count=option
|
|
||||||
echo $((count+3))
|
|
||||||
}
|
|
||||||
|
|
||||||
calcHeightDialog() {
|
|
||||||
newlines=$(printf "$1" | grep -c $'\n')
|
|
||||||
chars=$(echo "$1" | wc -c)
|
|
||||||
height=$(echo "$chars" "$newlines" | awk '{
|
|
||||||
x = (($1 - $2 + ($2 * 60)) / 60)
|
|
||||||
printf "%d", (x == int(x)) ? x : int(x) + 1
|
|
||||||
}')
|
|
||||||
echo $((4+height))
|
|
||||||
}
|
|
||||||
|
|
||||||
calcWidthAndRun() {
|
|
||||||
argc="$#"; i=1
|
argc="$#"; i=1
|
||||||
for item in "$@"; do
|
for item in "$@"; do
|
||||||
if [ $i -eq $((argc-2)) ]; then
|
[ $i -eq $((argc-2)) ] && str="$item"
|
||||||
str="$item"
|
[ "$item" = "WIDTH" ] && { function="calcWidthDialog"; dimName="width"; }
|
||||||
break
|
[ "$item" = "HEIGHT" ] && { function="calcHeightDialog"; dimName="height"; }
|
||||||
fi
|
|
||||||
((i++))
|
((i++))
|
||||||
done
|
done
|
||||||
width=$(calcWidthDialog "$str")
|
dim=$($function "$str")
|
||||||
comm=$(echo "$@" | sed "s/WIDTH/$width/g")
|
comm="${*//${dimName^^}/$dim}"
|
||||||
if [[ $comm != *"3>&1 1>&2 2>&3" ]]; then
|
|
||||||
comm="${comm} 3>&1 1>&2 2>&3"
|
|
||||||
fi
|
|
||||||
commOutput=$(eval "$comm")
|
|
||||||
exitStatus=$?
|
|
||||||
[ -n "$commOutput" ] && echo "$commOutput"
|
|
||||||
return $exitStatus
|
|
||||||
}
|
|
||||||
|
|
||||||
calcHeightAndRun() {
|
|
||||||
argc="$#"; i=1
|
|
||||||
for item in "$@"; do
|
|
||||||
if [ $i -eq $((argc-2)) ]; then
|
|
||||||
str="$item"
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
((i++))
|
|
||||||
done
|
|
||||||
height=$(calcHeightDialog "$str")
|
|
||||||
comm=$(echo "$@" | sed "s/HEIGHT/$height/g")
|
|
||||||
if [[ $comm != *"3>&1 1>&2 2>&3" ]]; then
|
if [[ $comm != *"3>&1 1>&2 2>&3" ]]; then
|
||||||
comm="${comm} 3>&1 1>&2 2>&3"
|
comm="${comm} 3>&1 1>&2 2>&3"
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue