Files
pyMCDPS/deploy.sh

147 lines
3.7 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-12 13:38:26 +02:00
2024-10-11 19:50:01 +02:00
# --------------------------------------------------------
# Checking Dependencies
# --------------------------------------------------------
2024-10-12 13:38:26 +02:00
2024-10-12 13:08:09 +02:00
echo "Checking dependencies..."
2024-10-12 13:38:26 +02:00
sleep 5
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
2024-10-12 13:38:26 +02:00
echo "$1 will be installed..."
2024-10-12 13:06:04 +02:00
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
2024-10-12 13:38:26 +02:00
echo "rc.local is already configured"
2024-10-12 13:06:04 +02:00
return 0
else
2024-10-12 13:38:26 +02:00
echo "rc.local not configured"
2024-10-12 13:06:04 +02:00
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
2024-10-12 13:11:00 +02:00
echo "Some required programs or rc.local modifications are missing. Installing..."
2024-10-12 13:06:04 +02:00
2024-10-12 13:11:00 +02:00
# Update and install the necessary packages
sudo apt update && sudo apt upgrade -y
2024-10-12 13:06:04 +02:00
2024-10-12 13:11:00 +02:00
if [[ $java_installed -ne 0 ]]; then
sudo apt install -y openjdk-17-jdk openjdk-17-jre-headless
fi
2024-10-12 13:06:04 +02:00
2024-10-12 13:11:00 +02:00
if [[ $tmux_installed -ne 0 ]]; then
sudo apt install -y tmux
fi
2024-10-12 13:06:04 +02:00
2024-10-12 13:11:00 +02:00
# 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:11:00 +02:00
# Make /etc/rc.local executable
sudo chmod +x /etc/rc.local
2024-10-12 13:06:04 +02:00
fi
2024-10-11 20:57:44 +02:00
else
2024-10-12 13:38:26 +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
2024-10-12 13:38:26 +02:00
sleep 2
# --------------------------------------------------------
# Installation Directories
# --------------------------------------------------------
echo "Give your server a name. Under the ~/servername you can later"
echo "find all server files and the management script."
2024-10-12 13:40:08 +02:00
echo 'Use "-" or "_" as name seperator!'
2024-10-12 13:38:26 +02:00
read -p "Servername: " name
working_dir="$HOME/$name"
management_dir="$HOME/$name/management"
2024-10-12 13:42:05 +02:00
management_logs="$HOME/$name/management/installation_logs"
2024-10-12 13:38:26 +02:00
server_dir="$HOME/$name/server"
echo "Creating directories"
mkdir $working_dir
mkdir $management_dir
mkdir $management_logs
2024-10-12 14:02:08 +02:00
mkdir $server_dir
# --------------------------------------------------------
# Modloader Selection
# --------------------------------------------------------
echo What Modloader should be used?
modloader=("Forge" "Fabric")
select opt in "${modloader[@]}"
do
case $opt in
"Forge")
break
;;
"Fabric")
echo "Fabric is not supported yet"
exit 1
break
;;
*)
echo "Invalid selection"
;;
esac
done
# --------------------------------------------------------
# Select MC-Version
# --------------------------------------------------------
echo "Give the minecraft and forge version in following format:"
echo "mc.version-forge.version e.g.: 1.20.1-47.3.0"
read -p "Version: " version
echo $version # Logging output