download_and_compile.sh: prompt when building 'next' and logfile not already present
This ensures that users building 'next' have seen the message that warns about possible instability and are aware of the other options (--lts for the latest Long Term Support release, -s for the latest release). The default answer is to continue. If --non-interactive has been given, the prompt is skipped and download_and_compile.sh proceeds as usual. This commit also adds _yes_no_prompt() which makes more sense than _yes_no_quit_prompt() here, since the 'no' answer implies that the user wants to quit.
This commit is contained in:
parent
fdf98d0ef3
commit
3bce994ea8
1 changed files with 68 additions and 0 deletions
|
@ -97,6 +97,54 @@ function _logOutput(){
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Return code is 0 for 'yes' and 1 for 'no'.
|
||||||
|
function _yes_no_prompt(){
|
||||||
|
local prompt="$1"
|
||||||
|
local default="$2"
|
||||||
|
local choices res answer
|
||||||
|
|
||||||
|
case "$default" in
|
||||||
|
[yY]) choices='Y/n' ;;
|
||||||
|
[nN]) choices='y/N' ;;
|
||||||
|
"")
|
||||||
|
if [[ "$INTERACTIVE_MODE" -eq 0 ]]; then
|
||||||
|
_printLog "Non-interactive mode requested, but found a question with" \
|
||||||
|
"no default answer;"
|
||||||
|
_printLog "this can't work, aborting."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
choices='y/n'
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
_printLog \
|
||||||
|
"Invalid default choice for _yes_no_prompt(): this is a bug in the"
|
||||||
|
"script, aborting."
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
if [[ "$INTERACTIVE_MODE" -eq 0 ]]; then
|
||||||
|
answer="$default"
|
||||||
|
else
|
||||||
|
read -r -p "$prompt [$choices] " answer
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "$answer" ]]; then
|
||||||
|
answer="$default"
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$answer" in
|
||||||
|
[yY]) res=0; break ;;
|
||||||
|
[nN]) res=1; break ;;
|
||||||
|
*) ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
return $res
|
||||||
|
}
|
||||||
|
|
||||||
|
# Return code is 0 for 'yes', 1 for 'no' and 2 for 'quit'.
|
||||||
function _yes_no_quit_prompt(){
|
function _yes_no_quit_prompt(){
|
||||||
local prompt="$1"
|
local prompt="$1"
|
||||||
local default="$2"
|
local default="$2"
|
||||||
|
@ -538,6 +586,11 @@ CBD="$PWD"
|
||||||
LOGFILE="$CBD/compilation_log.txt"
|
LOGFILE="$CBD/compilation_log.txt"
|
||||||
INTERACTIVE_MODE=1
|
INTERACTIVE_MODE=1
|
||||||
|
|
||||||
|
declare -i logfile_was_already_present_when_starting=0
|
||||||
|
if [[ -f "$LOGFILE" ]]; then
|
||||||
|
logfile_was_already_present_when_starting=1
|
||||||
|
fi
|
||||||
|
|
||||||
# Available values for WHATTOBUILD and WHATTOBUILDALL:
|
# Available values for WHATTOBUILD and WHATTOBUILDALL:
|
||||||
declare -a WHATTOBUILD_AVAIL=(
|
declare -a WHATTOBUILD_AVAIL=(
|
||||||
'CMAKE' 'PLIB' 'OPENRTI' 'OSG' 'SIMGEAR' 'FGFS' 'DATA' 'FGRUN' 'FGO' 'FGX'
|
'CMAKE' 'PLIB' 'OPENRTI' 'OSG' 'SIMGEAR' 'FGFS' 'DATA' 'FGRUN' 'FGO' 'FGX'
|
||||||
|
@ -901,6 +954,21 @@ and DATA components, but other components may be affected as well. Use
|
||||||
'--component-branch COMPONENT=BRANCH' (without the quotes) if you want to
|
'--component-branch COMPONENT=BRANCH' (without the quotes) if you want to
|
||||||
override the defaults (i.e., manually choose the branches for particular
|
override the defaults (i.e., manually choose the branches for particular
|
||||||
components)."
|
components)."
|
||||||
|
|
||||||
|
# Make sure users building 'next' are aware of the possible consequences. :-)
|
||||||
|
if [[ "$SELECTED_SUITE" = "next" && \
|
||||||
|
$logfile_was_already_present_when_starting -eq 0 ]]; then
|
||||||
|
set +e
|
||||||
|
_printLog
|
||||||
|
_yes_no_prompt "Are you sure you want to continue?" y; prompt_res=$?
|
||||||
|
set -e
|
||||||
|
if [[ $prompt_res -eq 1 ]]; then
|
||||||
|
_printLog "Aborting as requested."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
unset -v prompt_res
|
||||||
|
fi
|
||||||
|
|
||||||
_printLog
|
_printLog
|
||||||
_printLog "Branch used for each component:"
|
_printLog "Branch used for each component:"
|
||||||
_printLog
|
_printLog
|
||||||
|
|
Loading…
Reference in a new issue