Files
pyMCDPS/deploy.sh

93 lines
2.5 KiB
Bash
Raw Normal View History

2024-10-11 18:12:24 +02:00
#!/bin/bash
2024-10-11 20:40:56 +02:00
2024-10-11 18:12:24 +02:00
# Script in strict mode
2024-10-11 20:46:15 +02:00
set -eu
2024-10-11 18:12:24 +02:00
# --------------------------------------------------------------------------
# Imports
# --------------------------------------------------------------------------
# Beginning Of the Script by cerberus
cat <<EOF
__ __ ____ ____ ____
| \/ / ___|| _ \/ ___|
| |\/| \___ \| | | \___ \\
| | | |___) | |_| |___) |
|_| |_|____/|____/|____/
EOF
2024-10-11 19:50:01 +02:00
# --------------------------------------------------------
# Checking Dependencies
# --------------------------------------------------------
2024-10-12 13:08:09 +02:00
echo "Checking dependencies..."
2024-10-12 13:06:04 +02:00
# 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
else
echo "$1 is already installed."
return 0
fi
}
# Check if Java is installed
check_installed java
java_installed=$?
# Check if Tmux is installed
check_installed tmux
tmux_installed=$?
# 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
else
echo "The changes in rc.local are missing."
return 1
fi
}
# Check if the changes in rc.local are already applied
check_rc_local
rc_local_modified=$?
# If Java or Tmux is not installed, or rc.local is not modified, install/modify
if [[ $java_installed -ne 0 || $tmux_installed -ne 0 || $rc_local_modified -ne 0 ]]; then
read -p "Java, Tmux, or rc.local changes are missing. Do you want to install the required programs/make changes now? (y/n): " answer
if [[ "$answer" = "y" ]]; then
# Update and install the packages
sudo apt update && sudo apt upgrade -y
if [[ $java_installed -ne 0 ]]; then
sudo apt install -y openjdk-17-jdk openjdk-17-jre-headless
fi
if [[ $tmux_installed -ne 0 ]]; then
sudo apt install -y tmux
fi
# Only append to rc.local if changes are missing
if [[ $rc_local_modified -ne 0 ]]; then
sudo tee -a /etc/rc.local > /dev/null <<EOL
2024-10-11 20:57:44 +02:00
#!/bin/bash
exec 1>/tmp/rc.local.log 2>&1
set -x
EOL
2024-10-12 13:06:04 +02:00
# Make /etc/rc.local executable
sudo chmod +x /etc/rc.local
fi
2024-10-11 20:57:44 +02:00
2024-10-12 13:06:04 +02:00
else
echo "Installation/changes aborted. Exiting script."
exit 1
fi
2024-10-11 20:57:44 +02:00
else
2024-10-12 13:06:04 +02:00
echo "All required programs are already installed and rc.local is configured. Proceeding with installation..."
2024-10-11 20:57:44 +02:00
fi