Adds prompt to bootstrap steps
This commit is contained in:
parent
9958a7fa0e
commit
0b08e06a6a
1 changed files with 50 additions and 12 deletions
|
|
@ -12,21 +12,64 @@ _repeat() {
|
||||||
for i in $range; do echo -n "${str}"; done
|
for i in $range; do echo -n "${str}"; done
|
||||||
}
|
}
|
||||||
|
|
||||||
display() {
|
_header() {
|
||||||
local value="$1"
|
local length="$1"
|
||||||
echo -n "/="
|
echo -n "/="
|
||||||
_repeat ${#value} "="
|
_repeat ${length} "="
|
||||||
echo "=\\"
|
echo "=\\"
|
||||||
|
}
|
||||||
|
_value() {
|
||||||
|
local value="$1"
|
||||||
echo -n "| "
|
echo -n "| "
|
||||||
echo -n ${value}
|
echo -n ${value}
|
||||||
echo " |"
|
echo " |"
|
||||||
|
}
|
||||||
|
_footer() {
|
||||||
|
local length="$1"
|
||||||
echo -n "\\="
|
echo -n "\\="
|
||||||
_repeat ${#value} "="
|
_repeat ${length} "="
|
||||||
echo "=/"
|
echo "=/"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
display() {
|
||||||
|
local value="$1"
|
||||||
|
_header ${#value}
|
||||||
|
_value ${value}
|
||||||
|
_footer ${#value}
|
||||||
|
}
|
||||||
|
|
||||||
|
runfile() {
|
||||||
|
local command="$1"
|
||||||
|
local prompt="Do you wish to run $command? [Yn] "
|
||||||
|
local display="Executing $command"
|
||||||
|
|
||||||
|
local promptLength=$((${#prompt} + 1))
|
||||||
|
local displayLength=${#display}
|
||||||
|
|
||||||
|
local maxWidth=$((promptLength > displayLength ? promptLength : displayLength))
|
||||||
|
|
||||||
|
_header ${maxWidth}
|
||||||
|
|
||||||
|
read -p "| $prompt" -n 1 -r
|
||||||
|
echo " |"
|
||||||
|
|
||||||
|
if [[ $REPLY =~ ^[Nn]$ ]]; then
|
||||||
|
_footer ${maxWidth}
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -n "| $display"
|
||||||
|
_repeat $((maxWidth - displayLength)) " "
|
||||||
|
echo " |"
|
||||||
|
|
||||||
|
_footer ${maxWidth}
|
||||||
|
|
||||||
|
if ! "$command"; then
|
||||||
|
echo "Error: bootstrap '$command' failed" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
# Directory to look for bootstrap executables in
|
# Directory to look for bootstrap executables in
|
||||||
|
|
@ -45,11 +88,6 @@ while IFS= read -r bootstrap; do
|
||||||
done < <(find -L "$BOOTSTRAP_D" -type f | sort)
|
done < <(find -L "$BOOTSTRAP_D" -type f | sort)
|
||||||
|
|
||||||
for bootstrap in "${bootstraps[@]}"; do
|
for bootstrap in "${bootstraps[@]}"; do
|
||||||
display "Executing $bootstrap"
|
runfile "$bootstrap"
|
||||||
|
|
||||||
if ! "$bootstrap"; then
|
|
||||||
echo "Error: bootstrap '$bootstrap' failed" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
display "Bootstrap completed"
|
display "Bootstrap completed"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue