# This script can create the local "dnet-repository" and copy the "settings-dnet.xml" file there. # It also builds the project, using the aforementioned settings file. # Then it can run the project locally. # By giving different options, the user can either install and run locally, just install or just run the project. # For error-handling, we cannot use the "set -e" since: it has problems https://mywiki.wooledge.org/BashFAQ/105 # So we have our own function, for use when a single command fails. handle_error () { echo -e "$1"; exit $2 } # Change the working directory to the script's directory, when running from another location. cd "${0%/*}" || handle_error "Could not change-dir to this script's dir!" 1 if [[ $# -gt 1 ]]; then echo -e "Wrong number of arguments given: ${#}\nPlease execute it like: installAndRun.sh <1 | 2 | 0 (optional)> "; exit 2 fi justOneTask=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 | 2 | 0 (optional)>"; exit 3 fi if [[ $1 -lt 0 || $1 -gt 2 ]]; then # If the 1st argument does NOT equal to < 0 >, < 1 > or < 2 >. echo -e "Invalid argument given: ${1}\nPlease execute it like: installAndRun.sh <1 | 2 | 0 (optional)>"; exit 4 fi justOneTask=$1 # Assign <1>, <2> or <0> fi dnet_repo=~/.m2/repository-dnet45 settings_file=settings-dnet45.xml if [[ justOneTask -eq 1 ]]; then if [ ! -f ${dnet_repo}"/"${settings_file} ]; then echo -e "The file \"${dnet_repo}/${settings_file}\" does not exist! Exiting.."; exit 5 fi else if [ ! -d ${dnet_repo} ]; then mkdir ${dnet_repo} || exit 6 echo "Created the \"dnet_repo\": ${dnet_repo}" fi if [ ! -f ${dnet_repo}"/"${settings_file} ]; then cp ${settings_file} ${dnet_repo}"/"${settings_file} || handle_error "The file \"${settings_file}\" could not be copied in directory \"${dnet_repo}\"! Exiting.." 7 echo "Copied the \"settings_file\" to: ${dnet_repo}/${settings_file}" fi mvn clean install -s ${dnet_repo}"/"${settings_file} || handle_error "The project could not be built. Exiting.." 8 fi if [[ justOneTask -ne 2 ]]; then # If we do NOT want to "justInstall". java -jar ./target/uoa-repository-manager-service.jar || handle_error "The project failed to execute or its execution was interrupted. Exiting.." 9 fi