diff --git a/.github/Readme.md b/.github/Readme.md index 204004d..04c32df 100644 --- a/.github/Readme.md +++ b/.github/Readme.md @@ -15,6 +15,7 @@ The commands for Java are platform independent. Therefore, it doesn't matter if - Linux ```bash dos2unix makefile.sh +chmod +x makefile.sh sudo sh makefile.sh ``` - Windows diff --git a/makefile.sh b/makefile.sh index 6851920..2917ac4 100644 --- a/makefile.sh +++ b/makefile.sh @@ -1,11 +1,34 @@ #!/bin/bash +# Function to print error message in red +print_error() { + echo -e "\e[91m$1\e[0m" +} + +# Function to prompt the user with [Y/n] and return true for Y, false for n +prompt_user() { + read -p "$1 [Y/n]: " response + case "$response" in + [yY]|"") return 0 ;; # Accept "Yes" if no input is given + *) print_error "Aborted. Exiting..."; exit 1 ;; + esac +} + # Check and install missing dependencies check_dependency() { if ! command -v "$1" &> /dev/null; then - echo "$1 is not installed. Installing..." - sudo apt-get update - sudo apt-get install -y "$1" + print_error "$1 is not installed." + if prompt_user "Do you want to install $1?"; then + sudo apt-get update + sudo apt-get install -y "$1" + if [ $? -eq 0 ]; then + echo "$1 has been successfully installed." + else + print_error "Failed to install $1. Please install it manually." + fi + else + print_error "Skipping installation of $1." + fi else echo "$1 is already installed." fi @@ -15,6 +38,7 @@ check_dependency "coreutils" check_dependency "default-jre" check_dependency "default-jdk" + # Compile the Java code and create the JAR archive compile_and_create_jar() { echo "Compiling the Java code..."