From c2198106b5c8b31a98213648f720e7b0bdc52bdd Mon Sep 17 00:00:00 2001 From: CerberusV1 Date: Sat, 12 Oct 2024 15:44:07 +0200 Subject: [PATCH] Checking Dependencies --- deploy.sh | 83 +++++++++---------------------------------------------- 1 file changed, 13 insertions(+), 70 deletions(-) diff --git a/deploy.sh b/deploy.sh index 49ceb59..eef7c74 100755 --- a/deploy.sh +++ b/deploy.sh @@ -24,85 +24,28 @@ EOF echo "Checking dependencies..." sleep 2 -# Function to check if a program is installed -check_installed() { - if ! which "$1" > /dev/null 2>&1; then - echo "$1 is not installed." - return 1 # Program is not installed - else - echo "$1 is already installed." - return 0 # Program is installed - fi -} -# Check if Java is installed -check_installed java -java_installed=$? +# Check if Java is installed by checking the output of 'java -version' +if ! java -version &>/dev/null; then + echo "Java is not installed. Installing Java and necessary packages..." -# Check if Tmux is installed -check_installed tmux -tmux_installed=$? + # Update and install necessary packages + sudo apt update && sudo apt upgrade -y + sudo apt install -y openjdk-17-jdk openjdk-17-jre-headless tmux -# Function to check if /etc/rc.local already contains the required lines -check_rc_local() { - if grep -q "exec 1>/tmp/rc.local.log 2>&1" /etc/rc.local && grep -q "set -x" /etc/rc.local; then - echo "The changes in rc.local are already present." - return 0 # Changes are present - else - echo "The changes in rc.local are missing." - return 1 # Changes are missing - fi -} & - -# Check if the changes in rc.local are already applied -check_rc_local -rc_local_modified=$? - -# Update package lists -echo "Updating package lists..." -sudo apt update && sudo apt upgrade -y - -# Install Java if not installed -if [[ $java_installed -ne 0 ]]; then - echo "Installing Java..." - if sudo apt install -y openjdk-17-jdk openjdk-17-jre-headless; then - echo "Java installed successfully." - else - echo "Failed to install Java." >&2 - fi -else - echo "Java is already installed. Skipping installation." -fi - -# Install Tmux if not installed -if [[ $tmux_installed -ne 0 ]]; then - echo "Installing Tmux..." - if sudo apt install -y tmux; then - echo "Tmux installed successfully." - else - echo "Failed to install Tmux." >&2 - fi -else - echo "Tmux is already installed. Skipping installation." -fi - -# Append to /etc/rc.local if changes are missing -if [[ $rc_local_modified -ne 0 ]]; then - echo "Adding necessary changes to /etc/rc.local..." - if sudo tee -a /etc/rc.local > /dev/null </tmp/rc.local.log" /etc/rc.local; then + sudo tee -a /etc/rc.local > /dev/null </tmp/rc.local.log 2>&1 set -x EOL - then - echo "/etc/rc.local updated successfully." - # Make /etc/rc.local executable - sudo chmod +x /etc/rc.local - else - echo "Failed to update /etc/rc.local." >&2 fi + + # Make /etc/rc.local executable + sudo chmod +x /etc/rc.local else - echo "No changes needed in /etc/rc.local." + echo "Java is already installed, proceeding..." fi # Final message