From 3c1f1c9edbffa07051de6928c67d13f3f233c0ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Trellu?= Date: Thu, 18 Apr 2024 19:08:42 -0400 Subject: [PATCH] [scenario] Make sure scenario is valid --- utils/common.sh | 6 ++++++ utils/scenario.sh | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/utils/common.sh b/utils/common.sh index 4f7a114..3653415 100644 --- a/utils/common.sh +++ b/utils/common.sh @@ -298,6 +298,12 @@ function detect_scenario() { # shellcheck source=scenario.sh source utils/scenario.sh + # Check scenario status + if [ -n "$SCENARIO_NOT_SUPPORTED" ]; then + echo "scenario not supported" &>>"$LOG_FILE" + on_error + fi + export SCENARIO_FOUND="true" if [ -f "$YQ_BINARY_PATH" ]; then diff --git a/utils/scenario.sh b/utils/scenario.sh index 8e34fed..4756a70 100644 --- a/utils/scenario.sh +++ b/utils/scenario.sh @@ -19,6 +19,7 @@ if [ -f "$SCENARIO_PATH" ]; then done < <( "$YQ_BINARY_PATH" '.features | to_entries | map([.key, .value] | join("=")) | .[]' "$SCENARIO_PATH" ) + # Read all the hivemind options while IFS="=" read -r key_hivemind value_hivemind; do hivemind["$key_hivemind"]="$value_hivemind" @@ -26,6 +27,13 @@ if [ -f "$SCENARIO_PATH" ]; then "$YQ_BINARY_PATH" '.hivemind | to_entries | map([.key, .value] | join("=")) | .[]' "$SCENARIO_PATH" ) + # Make sure the scenario file is not empty + if [ -z "${!options[*]}" ]; then + export SCENARIO_NOT_SUPPORTED="true" + elif [ "${#options[@]}" -lt 7 ]; then + export SCENARIO_NOT_SUPPORTED="true" + fi + # Loop over each options and features for option in "${!options[@]}"; do # Ensure the option is supported by the installer @@ -63,6 +71,9 @@ if [ -f "$SCENARIO_PATH" ]; then [ "${features[$feature]}" == "true" ] && FEATURE_GUI="true" || FEATURE_GUI="false" export FEATURE_GUI ;; + *) + export SCENARIO_NOT_SUPPORTED="true" + ;; esac fi done @@ -84,6 +95,9 @@ if [ -f "$SCENARIO_PATH" ]; then password) [ -n "${hivemind[$hivemind_option]}" ] && export SATELLITE_PASSWORD="${hivemind[$hivemind_option]}" ;; + *) + export SCENARIO_NOT_SUPPORTED="true" + ;; esac fi done @@ -92,6 +106,9 @@ if [ -f "$SCENARIO_PATH" ]; then [ "${options[$option]}" == "true" ] && SHARE_TELEMETRY="true" || SHARE_TELEMETRY="false" export SHARE_TELEMETRY ;; + *) + export SCENARIO_NOT_SUPPORTED="true" + ;; esac fi done