Tidy the script startup code
This commit is contained in:
+64
-25
@@ -1096,17 +1096,25 @@ fi
|
|||||||
function and_all_subsequent_stages() {
|
function and_all_subsequent_stages() {
|
||||||
# if exactly two arguments were specified on the command line, and the first is a stage title,
|
# if exactly two arguments were specified on the command line, and the first is a stage title,
|
||||||
# then perform all stages subsequent to the specified stage, otherwise do nothing.
|
# then perform all stages subsequent to the specified stage, otherwise do nothing.
|
||||||
# first_argument is already sanitized so it's safe (though incorrect) to use as a regex (for brevity)
|
if [[ ${#specified_arguments[@]} == 2 ]]; then
|
||||||
first_argument=${specified_arguments%% *}
|
local stage
|
||||||
last_argument=${specified_arguments##* }
|
local first_argument=${specified_arguments[0]}
|
||||||
[[ "${first_argument} ${last_argument}" = "${specified_arguments}" ]] && \
|
local run=n
|
||||||
[[ "${stages}" =~ "${first_argument}" ]] && \
|
|
||||||
for stage in ${stages##*${first_argument}}; do ${stage}; done
|
for stage in "${stages[@]}"; do
|
||||||
|
[[ $run == n ]] || "$stage"
|
||||||
|
|
||||||
|
if [[ $stage == "$first_argument" ]]; then
|
||||||
|
# Run all subsequent stages.
|
||||||
|
run=y
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function documentation() {
|
function documentation() {
|
||||||
low_contrast_stages=""
|
low_contrast_stages=""
|
||||||
for stage in ${stages}; do
|
for stage in "${stages[@]}"; do
|
||||||
low_contrast_stages="${low_contrast_stages}"' '"${low_contrast_color}${stage}${default_color}"$'\n'
|
low_contrast_stages="${low_contrast_stages}"' '"${low_contrast_color}${stage}${default_color}"$'\n'
|
||||||
done
|
done
|
||||||
echo -ne "\n ${highlight_color}NAME${default_color}
|
echo -ne "\n ${highlight_color}NAME${default_color}
|
||||||
@@ -1685,7 +1693,7 @@ function prompt_delete_y_n() {
|
|||||||
|
|
||||||
# command-line argument processing
|
# command-line argument processing
|
||||||
check_shell
|
check_shell
|
||||||
stages='
|
stages=(
|
||||||
check_gnu_coreutils_prefix
|
check_gnu_coreutils_prefix
|
||||||
set_variables
|
set_variables
|
||||||
welcome
|
welcome
|
||||||
@@ -1703,27 +1711,58 @@ stages='
|
|||||||
create_target_virtual_disk
|
create_target_virtual_disk
|
||||||
populate_macos_target_disk
|
populate_macos_target_disk
|
||||||
prompt_delete_temporary_files
|
prompt_delete_temporary_files
|
||||||
'
|
)
|
||||||
[[ -z "${1}" ]] && for stage in ${stages}; do ${stage}; done && exit
|
|
||||||
[[ "${1}" = "documentation" ]] && documentation && exit
|
if [[ $# == 0 ]]; then
|
||||||
valid_arguments=(${stages//$'[\r\n]'/ } check_shell troubleshoot documentation and_all_subsequent_stages)
|
for stage in "${stages[@]}"; do
|
||||||
specified_arguments="$@" # this variable is used in the function "and_all_subsequent_stages"
|
"$stage"
|
||||||
for specified_arg in "$@"; do
|
|
||||||
there_is_a_match=""
|
|
||||||
# doing matching the long way to prevent delimiter confusion
|
|
||||||
for valid_arg in "${valid_arguments[@]}"; do
|
|
||||||
[[ "${valid_arg}" = "${specified_arg}" ]] && there_is_a_match="true" && break
|
|
||||||
done
|
done
|
||||||
if [[ -z "${there_is_a_match}" ]]; then
|
|
||||||
echo -e "\nOne or more specified arguments is not recognized."
|
exit
|
||||||
echo -e "\nRecognized stages:\n${stages}"
|
fi
|
||||||
echo -e "Other recognized arguments:\n\n check_shell\n documentation\n troubleshoot\n and_all_subsequent_stages"
|
|
||||||
echo -e "\nView documentation by entering the following command:"
|
if [[ $1 == documentation ]]; then
|
||||||
would_you_like_to_know_less
|
documentation
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
other_commands=(
|
||||||
|
check_shell
|
||||||
|
troubleshoot
|
||||||
|
documentation
|
||||||
|
and_all_subsequent_stages
|
||||||
|
)
|
||||||
|
|
||||||
|
specified_arguments=("$@") # this variable is used in the function "and_all_subsequent_stages"
|
||||||
|
for specified_arg; do
|
||||||
|
there_is_a_match=n
|
||||||
|
for valid_arg in "${stages[@]}" "${other_commands[@]}"; do
|
||||||
|
if [[ $valid_arg == "$specified_arg" ]]; then
|
||||||
|
there_is_a_match=y
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ $there_is_a_match == n ]]; then
|
||||||
|
cat <<EOF
|
||||||
|
|
||||||
|
One or more specified arguments is not recognized.
|
||||||
|
|
||||||
|
Recognized stages:
|
||||||
|
$(printf ' %s\n' "${stages[@]}")
|
||||||
|
|
||||||
|
Other recognized arguments:
|
||||||
|
$(printf ' %s\n' "${other_commands[@]}")
|
||||||
|
|
||||||
|
View documentation by entering the following command:
|
||||||
|
$(would_you_like_to_know_less)
|
||||||
|
|
||||||
|
EOF
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
check_gnu_coreutils_prefix
|
check_gnu_coreutils_prefix
|
||||||
set_variables
|
set_variables
|
||||||
check_dependencies
|
check_dependencies
|
||||||
for argument in "$@"; do ${argument}; done
|
for argument; do "${argument}"; done
|
||||||
|
|||||||
Reference in New Issue
Block a user