From 2c60f7f0f48f00ffa69a51d087744b833c683f3c Mon Sep 17 00:00:00 2001 From: Matheus Albino Brunhara Date: Fri, 29 Nov 2024 10:04:49 -0300 Subject: [PATCH] Adds miseRun.sh script --- scripts/shell/job/gp/miseRun.sh | 107 ++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100755 scripts/shell/job/gp/miseRun.sh diff --git a/scripts/shell/job/gp/miseRun.sh b/scripts/shell/job/gp/miseRun.sh new file mode 100755 index 0000000..dfd95de --- /dev/null +++ b/scripts/shell/job/gp/miseRun.sh @@ -0,0 +1,107 @@ +#!/bin/env bash + +set -e + +show_help() { + echo "Usage: $(basename $0) [--preset|-p] [--executable|-e] [--dry-run|-d]" + echo "Options:" + echo " --help | -h (Optional) Display help information on how to use this script" + echo " --preset | -p (Optional) Disables interactive preset selection and runs it" + echo " --executable | -e (Optional) Changes the default executable filename of the selected preset" + echo " --dry-run | -d (Optional) The script will only show the command it would run" +} + +SELECTED_PRESET="" +EXECUTABLE_FILENAME="" +SHOULD_DRY_RUN=false + +while [ "$#" -gt 0 ]; do + case "$1" in + --help | -h) + show_help + exit + ;; + --preset | -p) + SELECTED_PRESET="$2" + shift 2 + ;; + --executable | -e) + EXECUTABLE_FILENAME="$2" + shift 2 + ;; + --dry-run | -d) + SHOULD_DRY_RUN=true + shift + ;; + *) shift ;; + esac +done + +MISE_TOOLS=() + +MISE_TOOL_JAVA_8="adoptopenjdk-8.0.322+6" +MISE_TOOL_JAVA_11="adoptopenjdk-11.0.25+9" +MISE_TOOL_MAVEN_3_3_3="3.3.3" +MISE_TOOL_MAVEN_3_9_9="3.9.9" + +FILENAME_GP_DEBUGPORTS="debugports-01.sh" +FILENAME_GEOSERVER="runstandalone.sh" + +list_presets() { + echo "Choose one of the presets:" + echo " 1. Run GP with Java 8" + echo " 2. Run GeoServer with Java 8" + echo " 3. Run GeoServer with Java 11" + echo " 4. Run Maven 3.3.3 with Java 8" + echo " 4. Run Maven 3.8.4 with Java 11" +} + +read_preset_input() { + read -s -n 1 SELECTED_PRESET +} + +set_executable_filename_if_it_is_null() { + [[ -z "$EXECUTABLE_FILENAME" ]] && EXECUTABLE_FILENAME="$1" +} + +select_preset_by_input() { + case "$SELECTED_PRESET" in + "1") + # [[ -z "$EXECUTABLE_FILENAME" ]] && EXECUTABLE_FILENAME="$FILENAME_GP_DEBUGPORTS" + set_executable_filename_if_it_is_null "$FILENAME_GP_DEBUGPORTS" + MISE_TOOLS=("java$MISE_TOOL_JAVA_8") + ;; + "2") + set_executable_filename_if_it_is_null "$FILENAME_GP_DEBUGPORTS" + MISE_TOOLS=("java$MISE_TOOL_JAVA_11") + ;; + "3") + set_executable_filename_if_it_is_null "$FILENAME_GEOSERVER" + MISE_TOOLS=("java$MISE_TOOL_JAVA_8" "maven@$MISE_TOOL_MAVEN_3_3_3") + ;; + "4") + set_executable_filename_if_it_is_null "$FILENAME_GEOSERVER" + MISE_TOOLS=("java$MISE_TOOL_JAVA_11" "maven@$MISE_TOOL_MAVEN_3_9_9") + ;; + esac +} + +if [ -z "$SELECTED_PRESET" ]; then + list_presets + read_preset_input +fi + +while [ -z "$SELECTED_PRESET" ]; do + list_presets + read_preset_input +done + +select_preset_by_input + +COMMAND_TO_RUN=("mise" "run" "${MISE_TOOLS[@]}" "--" "$EXECUTABLE_FILENAME") + +[[ "$SHOULD_DRY_RUN" == true ]] && COMMAND_TO_RUN=("echo" "${COMMAND_TO_RUN[@]}") + +echo -e "\n" + +eval "${COMMAND_TO_RUN[@]}"