cd "${0%/*}" || (echo "Could not change-dir to this script's dir!" && exit) # Change the working directory to the script's directory, when running from other location. if [[ $# -gt 1 ]]; then echo -e "Wrong number of arguments given: ${#}\nPlease execute it like: installAndRun.sh <1 | 0 (optional)>"; exit 1 fi justRun=0 if [[ $# -eq 1 ]]; then # If we have just 1 argument. numbers_re='^[0-9]+$' if ! [[ $1 =~ $numbers_re ]]; then # If the first argument is not numeric. echo -e "Invalid, non-numeric argument given: ${1}\nPlease execute it like: installAndRun.sh <1 | 0 (optional)>"; exit 2 fi if [[ $1 -ne 0 && $1 -ne 1 ]]; then # If the 1st argument does NOT equal to < 0 > or < 1 >. echo -e "Invalid argument given: ${1}\nPlease execute it like: installAndRun.sh <1 | 0 (optional)>"; exit 3 fi justRun=$1 # Assign <1> or <0> fi dnet_repo=~/.m2/repository-dnet45 settings_file=settings-dnet45.xml if [[ justRun -eq 1 ]]; then if [ ! -f ${dnet_repo}"/"${settings_file} ]; then echo -e "The file \"~/.m2/repository-dnet45/settings-dnet45.xml\" does not exist! Exiting.." && exit 4 fi else if [ ! -d ${dnet_repo} ]; then mkdir ${dnet_repo} || (echo -e "The directory \"~/.m2/repository-dnet45/\" could not be created! Exiting.." && exit 5) echo "Created the \"dnet_repo\": ${dnet_repo}" fi if [ ! -f ${dnet_repo}"/"${settings_file} ]; then cp ${settings_file} ${dnet_repo}"/"${settings_file} || (echo -e "The file \"settings-dnet45.xml\" could not be copied in directory \"~/.m2/repository-dnet45\"! Exiting.." && exit 6) echo "Copied the \"settings_file\" to: ${dnet_repo}/${settings_file}" fi mvn clean install -s ${dnet_repo}"/"${settings_file} fi java -jar ./target/uoa-repository-manager-service.jar