diff --git a/installAndRun.sh b/installAndRun.sh index 5f6216f..0bd57d8 100755 --- a/installAndRun.sh +++ b/installAndRun.sh @@ -10,12 +10,16 @@ handle_error () { # 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 -justInstall=0 +justRun=0 +avoidReInstallingPublicationsRetriever=0 if [[ $# -eq 1 ]]; then - justInstall=$1 -elif [[ $# -gt 1 ]]; then - echo -e "Wrong number of arguments given: ${#}\nPlease execute it like: script.sh "; exit 2 + 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 "; exit 2 fi # Check of the "inputData.txt" file exist, if not, ask to fill it. @@ -46,31 +50,39 @@ fi gradleVersion="7.6" -if [[ justInstall -eq 0 ]]; then +if [[ justRun -eq 0 ]]; then - if [ ! -d libs ]; then - mkdir libs || handle_error "The directory \"libs\" could not be created! Exiting.." 3 + if [[ avoidReInstallingPublicationsRetriever -eq 1 ]]; then + if [[ ! -f ./libs/publications_retriever-1.0-SNAPSHOT.jar ]]; then + 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 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. + if [[ avoidReInstallingPublicationsRetriever -eq 0 ]]; then - # 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 + 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 + + cd PublicationsRetriever && sudo apt install -y maven && mvn clean install + + # 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 + + # Clean, (re)build and run the project. + cd ../ fi - cd PublicationsRetriever && sudo apt install -y maven && mvn clean install - - # 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 - - # Clean, (re)build and run the project. - cd ../ - if [[ ! -d /opt/gradle/gradle-${gradleVersion} ]]; then wget https://services.gradle.org/distributions/gradle-${gradleVersion}-bin.zip echo -e "\nAsking for sudo, in order to install 'gradle'..\n"