Update setup_bedrock.sh
This commit is contained in:
parent
f6a817806e
commit
e577d192bb
1 changed files with 41 additions and 15 deletions
|
|
@ -4,35 +4,60 @@
|
||||||
# Tested on Debian 11/12 and Ubuntu 24.04
|
# Tested on Debian 11/12 and Ubuntu 24.04
|
||||||
# Author: TimInTech
|
# Author: TimInTech
|
||||||
|
|
||||||
# Update package lists and install required dependencies
|
set -e
|
||||||
apt update && apt upgrade -y
|
|
||||||
apt install -y unzip wget screen curl
|
|
||||||
|
|
||||||
# Create directory for the Minecraft Bedrock server
|
# Create a dedicated user for the server
|
||||||
mkdir -p /opt/minecraft-bedrock && cd /opt/minecraft-bedrock
|
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)
|
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
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "📥 Downloading Minecraft Bedrock Server from: $LATEST_URL"
|
echo "Downloading Minecraft Bedrock Server from: $LATEST_URL"
|
||||||
wget -O bedrock-server.zip "$LATEST_URL"
|
wget -O bedrock-server.zip "$LATEST_URL"
|
||||||
|
|
||||||
# Validate download success
|
# Check if the download was successful
|
||||||
if [[ $? -ne 0 ]]; then
|
if [[ $? -ne 0 ]]; then
|
||||||
echo "❌ ERROR: Download failed. Please check your network connection."
|
echo "ERROR: Download failed. Check your internet connection."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Extract server files
|
# Check if the file is a valid ZIP archive
|
||||||
unzip -o bedrock-server.zip
|
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
|
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
|
# Create start script
|
||||||
cat <<EOF > start.sh
|
cat <<EOF > start.sh
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
@ -40,8 +65,9 @@ LD_LIBRARY_PATH=. ./bedrock_server
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
chmod +x start.sh
|
chmod +x start.sh
|
||||||
|
chown mcserver:mcserver start.sh
|
||||||
|
|
||||||
# Start the server in a detached screen session
|
# 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."
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue