Script to Automatically Upgrade Minecraft Server Jar

I got tired of upgrading my son’s minecraft server manually so I wrote these scripts so that he could upgrade the server himself.

There are two scripts. One shell script to make a backup of his old server configuration and a simple python script to download the latest jar

The shell script assumes the minecraft server folder is in /opt/minecraft. You will need to update that to the folder where you have it installed.

updateminecraft.sh

#!/bin/sh
today=$(date +"%Y-%m-%d")

sudo service minecraft stop

cd /opt/minecraft
python download_minecraft.py

mv server server.bak.${today}
mkdir server
mv server.jar server

cd server
cp ../server.bak.${today}/*.json .
cp ../server.bak.${today}/*.txt .
cp ../server.bak.${today}/*.properties .
cp ../server.bak.${today}/world . -R

sudo service minecraft start

printf "Minecraft Updated!"

download_minecraft.py

# name this file download_minecraft.py
import json, requests

manifestUrl = json.loads(requests.get("https://launchermeta.mojang.com/mc/game/version_manifest.json").content)

urls = manifestUrl["versions"]

for url in urls:
        if url["type"] == "release":
                manifestUrl = url["url"]
                break

downloadUrl = json.loads(requests.get(manifestUrl).content)["downloads"]["server"]["url"]

print "Download URL: " + str(downloadUrl)

fileData = requests.get(downloadUrl)

with open("server.jar", "wb") as fileObject:
        fileObject.write(fileData.content)


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *