2021-06-22 04:58:07 +02:00
cd " ${ 0 %/* } " || ( echo "Could not chdir to this script's dir!" && exit ) # Change the working directory to the script's directory, when running from other location.
2021-09-09 15:28:58 +02:00
justInstall = 0
2021-06-22 04:58:07 +02:00
2021-09-09 15:28:58 +02:00
if [ [ $# -eq 1 ] ] ; then
justInstall = $1
elif [ [ $# -gt 1 ] ] ; then
echo -e " Wrong number of arguments given: ${# } \nPlease execute it like: script.sh <justInstall: 0 | 1> " ; exit 1
fi
2021-06-22 04:58:07 +02:00
2021-09-22 15:36:48 +02:00
# Check of the "inputData.txt" file exist, if not, ask to fill it.
inputDataFile = "inputData.txt"
if [ [ ! -f $inputDataFile ] ] ; then
echo -e " The file \" $inputDataFile \" does not exist. Going to create it..\n "
echo "Give the ID of this worker:"
read -r workerId
2021-12-06 23:52:40 +01:00
echo -e "\nGive the max-assignments-limit-per-batch for the Worker to handle: "
read -r maxAssignmentsLimitPerBatch
2021-12-31 02:51:58 +01:00
echo -e "\nGive the max-assignments-batches to handle before restart: "
read -r maxAssignmentsBatchesToHandleBeforeRestart
2021-09-22 15:36:48 +02:00
echo -e "\nGive the baseUrl of the controller (e.g.: http://IP:PORT/api/):"
read -r controllerBaseUrl
touch $inputDataFile
2021-12-31 02:51:58 +01:00
echo " $workerId , $maxAssignmentsLimitPerBatch , $maxAssignmentsBatchesToHandleBeforeRestart , $controllerBaseUrl " >> $inputDataFile
2021-09-22 16:06:30 +02:00
echo -e "\n\n"
2021-09-22 15:36:48 +02:00
fi
2022-02-18 19:02:34 +01:00
gradleVersion = "7.4"
2021-06-22 04:58:07 +02:00
2021-09-09 15:28:58 +02:00
if [ [ justInstall -eq 0 ] ] ; then
2021-06-22 04:58:07 +02:00
2021-09-22 16:06:30 +02:00
if [ ! -d libs ] ; then
mkdir libs || ( echo -e "The directory \"libs\" could not be created! Exiting.." && exit 2)
fi
cd libs || exit 3
2021-09-09 15:28:58 +02:00
git clone https://github.com/LSmyrnaios/PublicationsRetriever.git # We assume there is no previously source-code here, if so, it will be overwritten.
2021-06-22 04:58:07 +02:00
2021-09-09 15:28:58 +02:00
# Keep a backup of the existing JAR file.
mv ./publications_retriever-1.0-SNAPSHOT.jar ./publications_retriever-1.0-SNAPSHOT_BACKUP.jar
2021-08-05 14:09:28 +02:00
2021-11-30 00:02:06 +01:00
cd PublicationsRetriever && sudo apt install -y maven && mvn clean install
2021-09-09 15:28:58 +02: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
# Delete the directory with the source-code.
cd ../ && rm -rf PublicationsRetriever
2021-11-30 05:57:51 +01:00
# Clean, (re)build and run the project.
2021-09-09 15:28:58 +02:00
cd ../
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
2021-09-09 15:28:58 +02:00
gradle clean
gradle build
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