# HG changeset patch # User Miloslav Zezulka # Date 1502281537 -7200 # Node ID 873a1db68bca21f306091c372f3c109b812de617 # Parent f3db7c6a533ef4516b4161e2ca4d8d9703537072 Allow for selectable build skip of components. This allows for web-client-only builds, web-gateway-only builds, agent-only builds or a combination thereof. Reviewed-by: jerboaa, jkang Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2017-August/024492.html diff -r f3db7c6a533e -r 873a1db68bca thermostat-ng.sh --- a/thermostat-ng.sh Tue Aug 08 12:25:15 2017 +0200 +++ b/thermostat-ng.sh Wed Aug 09 14:25:37 2017 +0200 @@ -3,12 +3,17 @@ # Runs Thermostat.next() all-in-one locally # # Examples: -# -# Don't build agent/gateway from source, just run it: -# $ BUILD=false ./thermostat-ng +# +# Build everything and run thermostat: +# $ ./thermostat-ng -a OR +# $ ./thermostat-ng -b all # -# Build agent/gateway from source and run it: -# $ ./thermostat-ng +# Build only agent and run thermostat: +# $ ./thermostat-ng -b agent +# +# Run thermostat without any build: +# $ ./thermostat-ng -b none OR +# $ ./thermostat-ng -s # #set -xv #set -e @@ -73,7 +78,7 @@ # Start/Stop mongodb mongodb() { - local action="$1" + local action="$1" case $action in start) ;& # fall-through @@ -123,7 +128,7 @@ # Start/stop web-gateway web_gateway() { - local action="$1" + local action="$1" case $action in start) start_web_gateway @@ -141,7 +146,7 @@ local fail_msg="Failed to start agent" config_agent echo "Starting agent ..." - $AGENT_ROOT/distribution/target/image/bin/thermostat -J-Dthermostat.agent.verbose=true -Tbg "$AGENT_PID_FILE" > "$AGENT_LOG_FILE" 2>&1 + $AGENT_ROOT/distribution/target/image/bin/thermostat -J-Dthermostat.agent.verbose=true -Tbg "$AGENT_PID_FILE" > "$AGENT_LOG_FILE" 2>&1 check_success_msg $? $fail_msg wait_for_ready "Agent started" "$AGENT_LOG_FILE" check_success_msg $? $fail_msg @@ -156,7 +161,7 @@ # Start/stop agent agent() { - local action="$1" + local action="$1" case $action in start) start_agent @@ -181,7 +186,7 @@ error=$? popd check_success_msg $error "Failed to build $component" - else + else echo "Build of $dir is skipped." fi } @@ -215,7 +220,7 @@ cp $AGENT_ROOT/distribution/target/image/etc/examples/ssl.properties.example $AGENT_ROOT/distribution/target/image/etc/ssl.properties else sed sX\\\\X/Xg $AGENT_ROOT/distribution/target/image/etc/examples/ssl.properties.example >$AGENT_ROOT/distribution/target/image/etc/ssl.properties - fi + fi } @@ -291,16 +296,139 @@ mkdir -p "$LOG_DIR" "$PID_DIR" +PARTIAL_BUILD=false +WEB_GATEWAY=true +WEB_CLIENT=true +AGENT=true + +HELP_STRING="\nUSAGE: $0 [BUILD_OPTION] + -a + Build everything. No values are bound to this flag. + -b [module_names...]|all|none + Specify which modules should be built. In case the -b flag has more than one value, it should be specified as the last flag. + It is possible to specify more than one value via repetition of this flag, e.g. $0 -b agent -b web-client + -s + Skip build of all components and directly start Thermostat. No values are bound to this flag.\n\n" + +print_help() { + printf "$HELP_STRING" +} + +mark_everything_to_be_built() { + WEB_GATEWAY=true + WEB_CLIENT=true + AGENT=true +} + +mark_nothing_to_be_built() { + WEB_GATEWAY=false + WEB_CLIENT=false + AGENT=false +} + +# Check whether the component passed as the first argument of this function exists. +# "all" is also acceptable as a parameter, which results in the same behaviour as if all components were specified. +# Component name can also end with a forward slash (UNIX autocompletion support). +resolve_component_name() { + local component_name + component_name=$1 + case "${component_name}" in + web-gateway|web-gateway/) + WEB_GATEWAY=true + ;; + web-client|web-client/) + WEB_CLIENT=true + ;; + agent|agent/) + AGENT=true + ;; + none) + mark_nothing_to_be_built + ;; + all) + mark_everything_to_be_built + ;; + *) + echo "Component '${component_name}' does not exist." + print_help + exit 1 + esac +} + +build_all_requested_components() { + if [ "$WEB_GATEWAY" = "true" ]; then + build_web_gateway + fi + if [ "$WEB_CLIENT" = "true" ]; then + build_web_client; copy_web_client_to_web_gateway + fi + if [ "$AGENT" = "true" ]; then + build_agent + fi +} + +check_for_remaining_components() { + # Iterate through remaining arguments and consider them as component names + local remaining_args_count remaining_args + remaining_args_count=$1 + remaining_args=$2 + if [ "$PARTIAL_BUILD" = "true" ]; then + for comp in ${remaining_args}; do + resolve_component_name $comp + done + elif [ "$remaining_args_count" -ne "0" ]; then + print_help + exit 1 + fi +} + +parse_args() { + local OPTIND + OPTIND=1 + while getopts ":b:as" opt ; do + case "${opt}" in + a) + mark_everything_to_be_built + break + ;; + b) + if [ "$PARTIAL_BUILD" = "false" ]; then + # First occurence of -b flag, first assume no components are going to be built + # (by default, all components are going to be built if no flags are specified) + # and then resolve component names with $PARTIAL_BUILD=true afterwards. + mark_nothing_to_be_built + PARTIAL_BUILD=true + fi + resolve_component_name $OPTARG + ;; + s) + mark_nothing_to_be_built + break + ;; + :) + printf "\nOption '$OPTARG' requires parameters." + print_help + exit 1 + ;; + *) + printf "Unexpected option '$OPTARG'" + print_help + exit 1 + ;; + esac + done + shift $((OPTIND-1)) + #OPTIND is local + check_for_remaining_components $# $@ +} + +parse_args "$@" + # Be sure source tree looks OK. check_sources_sane -# Build the agent and web-gateway -build_agent -build_web_gateway -# Build the web client and copy the built distribution image into -# web-gateway's web-client folder for static serving of the web client. -build_web_client -copy_web_client_to_web_gateway +# Build all components that were requested in command line arguments. +build_all_requested_components trap stop_all INT