mirror of
https://github.com/CerberusV1/minecraft_deploy.git
synced 2026-01-13 11:24:04 +01:00
Checking Dependencies
This commit is contained in:
81
deploy.sh
81
deploy.sh
@@ -24,85 +24,28 @@ EOF
|
|||||||
|
|
||||||
echo "Checking dependencies..."
|
echo "Checking dependencies..."
|
||||||
sleep 2
|
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 if Java is installed by checking the output of 'java -version'
|
||||||
check_installed java
|
if ! java -version &>/dev/null; then
|
||||||
java_installed=$?
|
echo "Java is not installed. Installing Java and necessary packages..."
|
||||||
|
|
||||||
# Check if Tmux is installed
|
# Update and install necessary packages
|
||||||
check_installed tmux
|
sudo apt update && sudo apt upgrade -y
|
||||||
tmux_installed=$?
|
sudo apt install -y openjdk-17-jdk openjdk-17-jre-headless tmux
|
||||||
|
|
||||||
# Function to check if /etc/rc.local already contains the required lines
|
# Add necessary commands to /etc/rc.local if not already present
|
||||||
check_rc_local() {
|
if ! grep -q "exec 1>/tmp/rc.local.log" /etc/rc.local; then
|
||||||
if grep -q "exec 1>/tmp/rc.local.log 2>&1" /etc/rc.local && grep -q "set -x" /etc/rc.local; then
|
sudo tee -a /etc/rc.local > /dev/null <<EOL
|
||||||
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 <<EOL
|
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
exec 1>/tmp/rc.local.log 2>&1
|
exec 1>/tmp/rc.local.log 2>&1
|
||||||
set -x
|
set -x
|
||||||
EOL
|
EOL
|
||||||
then
|
fi
|
||||||
echo "/etc/rc.local updated successfully."
|
|
||||||
# Make /etc/rc.local executable
|
# Make /etc/rc.local executable
|
||||||
sudo chmod +x /etc/rc.local
|
sudo chmod +x /etc/rc.local
|
||||||
else
|
|
||||||
echo "Failed to update /etc/rc.local." >&2
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
echo "No changes needed in /etc/rc.local."
|
echo "Java is already installed, proceeding..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Final message
|
# Final message
|
||||||
|
|||||||
Reference in New Issue
Block a user