#!/bin/bash function help() { printf "\n" printf "generateDockerfile [-h] [-t|b|d]\n" printf "\n" printf "Version name is mandatory.\n" printf "Available options:\n" printf "\t -h this message\n" printf "\t -t Test dockerfile\n" printf "\t -b Build dockerfile\n" printf "\t -d Debug dockerfile\n" printf "\n" } BUILD_VERSION=false TEST_VERSION=false DEBUG_VERSION=false VERSION_ACTIVE=0 while getopts ":hbtd" optname do case "$optname" in "h") OPTION_HELP=true ;; "b") # This version is the running environment STARTING_FILE="dockerfiles/build.dockerfile" VERSION_ACTIVE=$VERSION_ACTIVE+1 ;; "t") # This version is the unit-test only environment STARTING_FILE="dockerfiles/test.dockerfile" VERSION_ACTIVE=$VERSION_ACTIVE+1 ;; "d") # This version is a running environment with x-debugger included STARTING_FILE="dockerfiles/debug.dockerfile" VERSION_ACTIVE=$VERSION_ACTIVE+1 ;; ":") echo "No argument value for option $OPTARG" exit 1; ;; *) # Should not occur echo "Unknown error while processing options" ;; esac done if [[ $VERSION_ACTIVE -eq 0 ]]; then echo "Impossible to run script without chosing a version between debug, test and build"; exit 1; fi if [[ $VERSION_ACTIVE -gt 1 ]]; then echo "Invalid version requested, only one between -t -d and -b can be used, $VERSION_ACTIVE passed"; exit 1; fi my_dir="$(dirname "$0")" DIR_RETURN=`pwd` cd "$my_dir" source ../config # echo "sed -e 's/§ASDPHP_VERSION§/${ASDPHP_VERSION}/g'"; # echo "sed -e 's/§DEBUG_REMOTE_IP§/${DEBUG_REMOTE_IP}/g'"; # echo "sed -e 's/§PROJECT_BUILDNAME§/${PROJECT_BUILDNAME}/g'"; # echo "sed -e 's~§PROJECT_GROUP§~${PROJECT_GROUP}~g'"; # echo "sed -e 's/§DEBUG_REMOTE_PORT§/${DEBUG_REMOTE_PORT}/g'"; cat "$STARTING_FILE" | sed -e "s/§ASDPHP_VERSION§/${ASDPHP_VERSION}/g" | sed -e "s/§DEBUG_REMOTE_IP§/${DEBUG_REMOTE_IP}/g" | sed -e "s/§PROJECT_BUILDNAME§/${PROJECT_BUILDNAME}/g" | sed -e "s~§PROJECT_GROUP§~${PROJECT_GROUP}~g" | sed -e "s/§DEBUG_REMOTE_PORT§/${DEBUG_REMOTE_PORT}/g" \ > "$DIR_RETURN/Dockerfile" cd "$DIR_RETURN"