2022-12-01 13:56:52 +01:00
# 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
2022-11-16 15:20:58 +01:00
2022-11-17 14:01:27 +01:00
if [ [ $# -gt 1 ] ] ; then
2022-12-01 13:56:52 +01:00
echo -e " Wrong number of arguments given: ${# } \nPlease execute it like: installAndRun.sh <1 | 2 | 0 (optional)> " ; exit 2
2022-11-16 15:20:58 +01:00
fi
2022-12-01 13:56:52 +01:00
justOneTask = 0
2022-11-16 15:20:58 +01:00
2022-11-17 14:01:27 +01:00
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.
2022-12-01 13:56:52 +01:00
echo -e " Invalid, non-numeric argument given: ${ 1 } \nPlease execute it like: installAndRun.sh <1 | 2 | 0 (optional)> " ; exit 3
2022-11-16 15:20:58 +01:00
fi
2022-12-01 13:56:52 +01:00
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
2022-11-16 15:20:58 +01:00
fi
2022-11-17 14:01:27 +01:00
2022-12-01 13:56:52 +01:00
justOneTask = $1 # Assign <1>, <2> or <0>
2022-11-17 14:01:27 +01:00
fi
dnet_repo = ~/.m2/repository-dnet45
settings_file = settings-dnet45.xml
2022-12-01 13:56:52 +01:00
if [ [ justOneTask -eq 1 ] ] ; then
2022-11-17 14:01:27 +01:00
if [ ! -f ${ dnet_repo } "/" ${ settings_file } ] ; then
2022-12-01 13:56:52 +01:00
echo -e " The file \" ${ dnet_repo } / ${ settings_file } \" does not exist! Exiting.. " ; exit 5
2022-11-16 15:20:58 +01:00
fi
2022-11-17 14:01:27 +01:00
else
if [ ! -d ${ dnet_repo } ] ; then
2022-12-01 13:56:52 +01:00
mkdir ${ dnet_repo } || exit 6
2022-11-17 14:01:27 +01:00
echo " Created the \"dnet_repo\": ${ dnet_repo } "
fi
if [ ! -f ${ dnet_repo } "/" ${ settings_file } ] ; then
2022-12-01 13:56:52 +01:00
cp ${ settings_file } ${ dnet_repo } "/" ${ settings_file } || handle_error " The file \" ${ settings_file } \" could not be copied in directory \" ${ dnet_repo } \"! Exiting.. " 7
2022-11-17 14:01:27 +01:00
echo " Copied the \"settings_file\" to: ${ dnet_repo } / ${ settings_file } "
fi
2022-12-01 13:56:52 +01:00
mvn clean install -s ${ dnet_repo } "/" ${ settings_file } || handle_error "The project could not be built. Exiting.." 8
2022-11-16 15:20:58 +01:00
fi
2022-12-01 13:56:52 +01:00
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