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 14:07:39 +02:00
|
|
|
sleep 2
|
2024-10-12 13:06:04 +02:00
|
|
|
# Function to check if a program is installed
|
2024-10-12 14:47:01 +02:00
|
|
|
check_installed() {
|
|
|
|
|
if ! which "$1" > /dev/null 2>&1; then
|
2024-10-12 15:18:48 +02:00
|
|
|
echo "$1 is not installed."
|
|
|
|
|
return 1 # Program is not installed
|
2024-10-12 14:47:01 +02:00
|
|
|
else
|
|
|
|
|
echo "$1 is already installed."
|
2024-10-12 15:18:48 +02:00
|
|
|
return 0 # Program is installed
|
2024-10-12 14:47:01 +02:00
|
|
|
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 15:18:48 +02:00
|
|
|
echo "The changes in rc.local are already present."
|
|
|
|
|
return 0 # Changes are present
|
2024-10-12 14:47:01 +02:00
|
|
|
else
|
2024-10-12 15:18:48 +02:00
|
|
|
echo "The changes in rc.local are missing."
|
|
|
|
|
return 1 # Changes are missing
|
2024-10-12 14:47:01 +02:00
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Check if the changes in rc.local are already applied
|
|
|
|
|
check_rc_local
|
|
|
|
|
rc_local_modified=$?
|
|
|
|
|
|
2024-10-12 15:09:08 +02:00
|
|
|
# Update package lists
|
2024-10-12 15:18:48 +02:00
|
|
|
echo "Updating package lists..."
|
2024-10-12 15:09:08 +02:00
|
|
|
sudo apt update && sudo apt upgrade -y
|
2024-10-12 14:47:01 +02:00
|
|
|
|
2024-10-12 15:09:08 +02:00
|
|
|
# Install Java if not installed
|
|
|
|
|
if [[ $java_installed -ne 0 ]]; then
|
|
|
|
|
echo "Installing Java..."
|
2024-10-12 15:24:09 +02:00
|
|
|
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
|
2024-10-12 15:18:48 +02:00
|
|
|
else
|
|
|
|
|
echo "Java is already installed. Skipping installation."
|
2024-10-12 15:09:08 +02:00
|
|
|
fi
|
2024-10-12 14:47:01 +02:00
|
|
|
|
2024-10-12 15:09:08 +02:00
|
|
|
# Install Tmux if not installed
|
|
|
|
|
if [[ $tmux_installed -ne 0 ]]; then
|
|
|
|
|
echo "Installing Tmux..."
|
2024-10-12 15:24:09 +02:00
|
|
|
if sudo apt install -y tmux; then
|
|
|
|
|
echo "Tmux installed successfully."
|
|
|
|
|
else
|
|
|
|
|
echo "Failed to install Tmux." >&2
|
|
|
|
|
fi
|
2024-10-12 15:18:48 +02:00
|
|
|
else
|
|
|
|
|
echo "Tmux is already installed. Skipping installation."
|
2024-10-12 15:09:08 +02:00
|
|
|
fi
|
2024-10-12 14:47:01 +02:00
|
|
|
|
2024-10-12 15:09:08 +02:00
|
|
|
# Append to /etc/rc.local if changes are missing
|
|
|
|
|
if [[ $rc_local_modified -ne 0 ]]; then
|
|
|
|
|
echo "Adding necessary changes to /etc/rc.local..."
|
2024-10-12 15:24:09 +02:00
|
|
|
if sudo tee -a /etc/rc.local > /dev/null <<EOL
|
2024-10-12 14:47:01 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
exec 1>/tmp/rc.local.log 2>&1
|
|
|
|
|
set -x
|
|
|
|
|
EOL
|
2024-10-12 15:24:09 +02:00
|
|
|
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
|
2024-10-12 15:18:48 +02:00
|
|
|
else
|
|
|
|
|
echo "No changes needed in /etc/rc.local."
|
2024-10-12 14:47:01 +02:00
|
|
|
fi
|
2024-10-12 15:09:08 +02:00
|
|
|
|
2024-10-12 15:24:09 +02:00
|
|
|
# Final message
|
2024-10-12 15:09:08 +02:00
|
|
|
echo "All required programs are already installed and rc.local is configured. Proceeding with installation..."
|
2024-10-12 15:24:09 +02:00
|
|
|
|
2024-10-12 14:47:01 +02:00
|
|
|
sleep 2
|
2024-10-12 13:38:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
# --------------------------------------------------------
|
|
|
|
|
# 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
|
|
|
|
|
|
2024-10-12 14:09:57 +02:00
|
|
|
# echo $version # Logging output
|
|
|
|
|
# sleep 1
|
|
|
|
|
|
2024-10-12 14:05:34 +02:00
|
|
|
# Building installer download URL
|
|
|
|
|
URL="https://maven.minecraftforge.net/net/minecraftforge/forge/${version}/forge-${version}-installer.jar"
|
2024-10-12 14:09:57 +02:00
|
|
|
# echo $URL # Logging output
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# --------------------------------------------------------
|
|
|
|
|
# Downloading Installer
|
|
|
|
|
# --------------------------------------------------------
|
2024-10-12 14:05:34 +02:00
|
|
|
|
2024-10-12 14:13:07 +02:00
|
|
|
echo "Downloading Installer..."
|
2024-10-12 14:42:38 +02:00
|
|
|
wget -P $server_dir "$URL" -o "$management_logs/wget.log" & # no output for wget
|
2024-10-12 14:09:57 +02:00
|
|
|
PID=$!
|
|
|
|
|
(
|
|
|
|
|
while kill -0 $PID 2> /dev/null; do
|
|
|
|
|
echo "Downloading....."
|
|
|
|
|
sleep 1
|
|
|
|
|
done
|
|
|
|
|
echo "Download finished."
|
2024-10-12 14:28:23 +02:00
|
|
|
) &
|
2024-10-12 14:42:38 +02:00
|
|
|
wait $PID
|
|
|
|
|
sleep 2
|
2024-10-12 14:26:07 +02:00
|
|
|
|
|
|
|
|
# --------------------------------------------------------
|
|
|
|
|
# Installing Server
|
|
|
|
|
# --------------------------------------------------------
|
|
|
|
|
echo "Installing Server"
|
2024-10-12 14:42:38 +02:00
|
|
|
cd "${server_dir}"
|
2024-10-12 14:26:07 +02:00
|
|
|
sleep 1
|
2024-10-12 14:42:38 +02:00
|
|
|
java -jar forge-${version}-installer.jar --installServer > /dev/null 2>&1 &
|
2024-10-12 14:26:07 +02:00
|
|
|
|
|
|
|
|
# Store the PID of the installer process
|
|
|
|
|
PID=$!
|
|
|
|
|
|
|
|
|
|
# Progress monitoring while the server is installing
|
|
|
|
|
(
|
|
|
|
|
while kill -0 $PID 2> /dev/null; do
|
|
|
|
|
echo "Installing server....."
|
|
|
|
|
sleep 5
|
|
|
|
|
done
|
|
|
|
|
echo "Server installation finished."
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
echo "Removing Installer"
|
2024-10-12 14:46:09 +02:00
|
|
|
rm "forge-${version}-installer.jar"
|
|
|
|
|
mv "forge-${version}-installer.jar.log" $management_logs
|
2024-10-12 14:48:42 +02:00
|
|
|
|
2024-10-12 14:50:49 +02:00
|
|
|
echo "You can now find the management script in /$HOME/$management_dir "
|