From 83c77670aba3f07b909f86a3e9f810d72790c9ee Mon Sep 17 00:00:00 2001 From: LSmyrnaios Date: Thu, 17 Nov 2022 15:01:27 +0200 Subject: [PATCH] Improve the "installAndRun.sh" script: - Add the "java -jar" run command. - Add more sanity checks for cmd-args. - Code polishing. --- installAndRun.sh | 47 ++++++++++++++++++++++++++++++++--------------- pom.xml | 3 ++- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/installAndRun.sh b/installAndRun.sh index c0f7b46..b92bd10 100755 --- a/installAndRun.sh +++ b/installAndRun.sh @@ -1,26 +1,43 @@ 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 - justRun=$1 -elif [[ $# -gt 1 ]]; then - echo -e "Wrong number of arguments given: ${#}\nPlease execute it like: script.sh "; exit 1 +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 -if [[ justRun -eq 0 ]]; then +dnet_repo=~/.m2/repository-dnet45 +settings_file=settings-dnet45.xml - if [ ! -d ~/.m2/repository-dnet45/ ]; then - mkdir ~/.m2/repository-dnet45/ || (echo -e "The directory \"~/.m2/repository-dnet45/\" could not be created! Exiting.." && exit 2) - fi - - if [ ! -f ~/.m2/repository-dnet45/settings-dnet45.xml ]; then - cp ./settings-dnet45.xml ~/.m2/repository-dnet45/ || (echo -e "The file \"settings-dnet45.xml\" could not be copied in directory \"~/.m2/repository-dnet45\"! Exiting.." && exit 3) - fi -else - if [ ! -f ~/.m2/repository-dnet45/settings-dnet45.xml ]; then +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 -mvn clean install -s ~/.m2/repository-dnet45/settings-dnet45.xml +java -jar ./target/uoa-repository-manager-service.jar diff --git a/pom.xml b/pom.xml index e30cd3e..c79de24 100644 --- a/pom.xml +++ b/pom.xml @@ -450,7 +450,8 @@ --> - + + org.springframework.boot spring-boot-maven-plugin