2022-11-30 15:25:57 +01:00
# This script installs and runs the project.
2022-12-12 16:49:14 +01:00
# It also sets the "max-heap-size", depending on the machine's memory.
2022-11-30 15:25:57 +01:00
# 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
2021-06-22 04:58:07 +02:00
2023-01-20 00:59:26 +01:00
justRun = 0
avoidReInstallingPublicationsRetriever = 0
2021-06-22 04:58:07 +02:00
2021-09-09 15:28:58 +02:00
if [ [ $# -eq 1 ] ] ; then
2023-01-20 00:59:26 +01:00
justRun = $1
elif [ [ $# -eq 2 ] ] ; then
justRun = $1
avoidReInstallingPublicationsRetriever = $2
elif [ [ $# -gt 2 ] ] ; then
echo -e " Wrong number of arguments given: ${# } (more than 2)\nPlease execute it like: script.sh <justRun: 0 | 1> <avoidReInstallingPublicationsRetriever: 0 | 1> " ; exit 2
2021-09-09 15:28:58 +02:00
fi
2021-06-22 04:58:07 +02:00
2023-04-22 05:44:04 +02:00
gradleVersion = "8.1.1"
2021-06-22 04:58:07 +02:00
2023-01-20 00:59:26 +01:00
if [ [ justRun -eq 0 ] ] ; then
2021-06-22 04:58:07 +02:00
2023-01-20 00:59:26 +01:00
if [ [ avoidReInstallingPublicationsRetriever -eq 1 ] ] ; then
if [ [ ! -f ./libs/publications_retriever-1.0-SNAPSHOT.jar ] ] ; then
2023-01-27 13:27:57 +01:00
echo -e "\n\nThe required \"PublicationsRetriever\" software has not been installed yet, thus the script will override the user-defined value of \"avoidReInstallingPublicationsRetriever\" to FALSE..\n\n"
2023-01-20 00:59:26 +01:00
avoidReInstallingPublicationsRetriever = 0; # In case the jar-file does not exists, then make sure we follow the normal procedure, independently from what the user requested.
fi
2021-09-22 16:06:30 +02:00
fi
2023-01-20 00:59:26 +01:00
if [ [ avoidReInstallingPublicationsRetriever -eq 0 ] ] ; then
2021-06-22 04:58:07 +02:00
2023-01-20 00:59:26 +01:00
if [ ! -d libs ] ; then
mkdir libs || handle_error "The directory \"libs\" could not be created! Exiting.." 3
fi
cd libs || exit 4
git clone https://github.com/LSmyrnaios/PublicationsRetriever.git # We assume there is no previously source-code here, if so, it will be overwritten.
# Keep a backup of the previous JAR file, if it exists.
if [ -f ./publications_retriever-1.0-SNAPSHOT.jar ] ; then
mv ./publications_retriever-1.0-SNAPSHOT.jar ./publications_retriever-1.0-SNAPSHOT_BACKUP.jar
fi
2021-08-05 14:09:28 +02:00
2023-01-20 00:59:26 +01:00
cd PublicationsRetriever && sudo apt install -y maven && mvn clean install
2021-09-09 15:28:58 +02:00
2023-01-20 00:59:26 +01:00
# Copy the created JAR file to the top libs directory.
cp target/publications_retriever-1.0-SNAPSHOT.jar ../publications_retriever-1.0-SNAPSHOT.jar
2021-09-09 15:28:58 +02:00
2023-01-20 00:59:26 +01:00
# Delete the directory with the source-code.
cd ../ && rm -rf PublicationsRetriever
2021-09-09 15:28:58 +02:00
2023-01-20 00:59:26 +01:00
# Clean, (re)build and run the project.
cd ../
fi
2021-09-09 15:28:58 +02:00
2023-02-15 15:18:33 +01:00
# Install the specified Gradle-build-tool version, if it does not exist.
2021-10-11 10:19:52 +02:00
if [ [ ! -d /opt/gradle/gradle-${ gradleVersion } ] ] ; then
wget https://services.gradle.org/distributions/gradle-${ gradleVersion } -bin.zip
2021-10-11 12:27:40 +02:00
echo -e "\nAsking for sudo, in order to install 'gradle'..\n"
2021-10-11 10:19:52 +02:00
sudo mkdir /opt/gradle
sudo apt install -y unzip && sudo unzip -d /opt/gradle gradle-${ gradleVersion } -bin.zip
#ls /opt/gradle/gradle-${gradleVersion} # For debugging installation
fi
2021-08-05 14:09:28 +02:00
2022-01-21 14:19:52 +01:00
export PATH = /opt/gradle/gradle-${ gradleVersion } /bin:$PATH
2021-08-05 14:09:28 +02:00
2021-12-16 01:04:05 +01:00
# Update the max-heap-size based on the machine's physical memory.
machine_memory_mb = $( grep MemTotal /proc/meminfo | awk '{print $2}' | xargs -I { } echo "scale=4; {}/1024" | bc) # It returns the size in MB.
2021-12-17 07:24:09 +01:00
max_heap_size_mb = $( echo " ( $machine_memory_mb - 896)/1 " | bc) # Leave 896 MB to the system (the "()/1" is used to take the floor value).
2021-12-16 01:04:05 +01:00
# Now, we replace the "-Xmx" parameter inside the "./build.gradle" file, with "-Xmx${max_heap_size}m"
echo -e " \n\nThe max-heap-size (-Xmx) will be set to: ${ max_heap_size_mb } m\n\n "
sed -i " s/'-Xmx[0-9]\+[gm]'/'-Xmx ${ max_heap_size_mb } m'/g " ./build.gradle
2021-09-09 15:28:58 +02:00
gradle wrapper --gradle-version= ${ gradleVersion } --distribution-type= bin
2021-08-05 14:09:28 +02:00
2021-09-09 15:28:58 +02:00
#gradle tasks # For debugging installation
#gradle -v # For debugging installation
2021-09-02 17:35:47 +02:00
2022-02-22 12:29:02 +01:00
gradle clean build
2021-09-09 15:28:58 +02:00
else
2022-01-21 14:19:52 +01:00
export PATH = /opt/gradle/gradle-${ gradleVersion } /bin:$PATH # Make sure the gradle is still accessible (it usually isn't without the "export").
2021-09-09 15:28:58 +02:00
fi
2021-09-02 17:35:47 +02:00
2021-08-05 14:09:28 +02:00
gradle bootRun