Update setup_bedrock.sh

This commit is contained in:
==TIM.©.B == 2025-03-16 18:48:37 +01:00 committed by GitHub
parent f6a817806e
commit e577d192bb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -4,35 +4,60 @@
# Tested on Debian 11/12 and Ubuntu 24.04
# Author: TimInTech
# Update package lists and install required dependencies
apt update && apt upgrade -y
apt install -y unzip wget screen curl
set -e
# Create directory for the Minecraft Bedrock server
mkdir -p /opt/minecraft-bedrock && cd /opt/minecraft-bedrock
# Create a dedicated user for the server
if ! id -u mcserver > /dev/null 2>&1; then
sudo useradd -m -r -d /opt/minecraft-bedrock mcserver
fi
# Fetch the latest Bedrock Server download URL
# Install required dependencies if not already installed
for pkg in unzip wget screen curl; do
if ! dpkg -l | grep -qw $pkg; then
sudo apt update
sudo apt install -y $pkg
fi
done
# Set up server directory
sudo -u mcserver mkdir -p /opt/minecraft-bedrock
cd /opt/minecraft-bedrock
# Fetch the latest Bedrock server URL
LATEST_URL=$(curl -s https://www.minecraft.net/en-us/download/server/bedrock | grep -o 'https://minecraft.azureedge.net/bin-linux/bedrock-server-[0-9.]*.zip' | head -1)
# Validate if the URL was retrieved
# Exit if no URL was found
if [[ -z "$LATEST_URL" ]]; then
echo "❌ ERROR: Unable to fetch the latest Bedrock Server version. Check https://www.minecraft.net/en-us/download/server/bedrock"
echo "ERROR: Couldn't retrieve the latest Bedrock server URL."
exit 1
fi
echo "📥 Downloading Minecraft Bedrock Server from: $LATEST_URL"
echo "Downloading Minecraft Bedrock Server from: $LATEST_URL"
wget -O bedrock-server.zip "$LATEST_URL"
# Validate download success
# Check if the download was successful
if [[ $? -ne 0 ]]; then
echo "❌ ERROR: Download failed. Please check your network connection."
echo "ERROR: Download failed. Check your internet connection."
exit 1
fi
# Extract server files
unzip -o bedrock-server.zip
# Check if the file is a valid ZIP archive
if ! unzip -tq bedrock-server.zip >/dev/null; then
echo "ERROR: The downloaded file is not a valid ZIP archive."
rm -f bedrock-server.zip
exit 1
fi
# Extract the server files
sudo -u mcserver unzip -o bedrock-server.zip
rm -f bedrock-server.zip
# Make sure the server binary exists
if [[ ! -f "bedrock_server" ]]; then
echo "ERROR: The server binary is missing. Installation failed."
exit 1
fi
# Create start script
cat <<EOF > start.sh
#!/bin/bash
@ -40,8 +65,9 @@ LD_LIBRARY_PATH=. ./bedrock_server
EOF
chmod +x start.sh
chown mcserver:mcserver start.sh
# Start the server in a detached screen session
screen -dmS bedrock ./start.sh
sudo -u mcserver screen -dmS bedrock ./start.sh
echo "✅ Setup complete! Use 'screen -r bedrock' to access the console."
echo "Setup complete! Use 'sudo -u mcserver screen -r bedrock' to open the console."