Skip to content

Instantly share code, notes, and snippets.

@toAlice
Last active February 2, 2022 10:11
Show Gist options
  • Save toAlice/15e4afb87e5bee5fd3dd347dd8ac3480 to your computer and use it in GitHub Desktop.
Save toAlice/15e4afb87e5bee5fd3dd347dd8ac3480 to your computer and use it in GitHub Desktop.
Minecraft Bedrock Edition's Official Dedicated Linux Server setup and upgrade script.
#!/usr/bin/env bash
FORCE=0
while getopts ":f" flag
do
case "${flag}" in
f)
echo "Ignoring $OPTARG"
FORCE=1
;;
\?)
echo "Invalid Option -$OPTARG" >&2
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
ArchiveURL=$(curl -cL --user-agent 'Mozilla/5.0 (X11; Linux x86_64; rv:96.0) Gecko/20100101 Firefox/96.0' https://www.minecraft.net/en-us/download/server/bedrock 2>>/dev/null | grep bin-linux)
ArchiveURL=${ArchiveURL#*\"}
ArchiveURL=${ArchiveURL%%\"*}
ArchiveFilename=${ArchiveURL##*/}
echo "Latest=${ArchiveFilename}"
mkdir -p bedrock
cd bedrock
[[ -f "current_ver.txt" ]] && CurVer=$(cat current_ver.txt)
if [ "$FORCE" -ne 1 ]; then
if [ "$ArchiveFilename" == "$CurVer" ]; then
echo "Server is up to date. You can force it with -f"
exit 0
fi
fi
echo $ArchiveFilename > current_ver.txt
echo -n "Downloading..."
curl -OL $ArchiveURL
unzip -o $ArchiveFilename
if [ ! -f "server_start.sh" ]; then
tee > server_start.sh <<-EOT
#!/usr/bin/env bash
LD_LIBRARY_PATH=. ./bedrock_server
EOT
chmod +x server_start.sh
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment