Skip to content

Commit

Permalink
[scenario] Make sure scenario is valid
Browse files Browse the repository at this point in the history
  • Loading branch information
goldyfruit committed Apr 18, 2024
1 parent 87b6f57 commit 3c1f1c9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions utils/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions utils/scenario.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,21 @@ 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"
done < <(
"$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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 3c1f1c9

Please sign in to comment.