Minecraft Server Upgrade Skript
Skript, welches vom mir erstellt wurde, um automatisiert (via cronjob) einen selbst erstellten Minecraft-Server auf aktuellem Stand zu halten; resp. zu Updaten.
Skript Sourcecode
Filename: update_minecraft-server.sh
#!/bin/bash #***************************************************************************** # Subject : update_minecraft-server.sh # Description : # Author : Michael Reber <michael.r467@gmail.com> # Created : 2017.10.17 #***************************************************************************** newest_server_version=$(curl https://minecraft.net/en-us/download/server | grep https://s3.amazonaws.com/Minecraft.Download/versions/.*/minecraft_server.*.jar | cut -d '/' -f6) in_use_server_version=$(cat /opt/minecraft/logs/latest.log | grep "server version" | cut -d ' ' -f8) echo $in_use_server_version echo $newest_server_version if [ $in_use_server_version == $newest_server_version ]; then echo "Server is up to date!" fi if [ $in_use_server_version != $newest_server_version ]; then echo "SERVER NEEDS UPDATE!" new_server_download_link=$(curl https://minecraft.net/en-us/download/server | grep https://s3.amazonaws.com/Minecraft.Download/versions/.*/minecraft_server.*.jar | cut -d '"' -f2) cd /opt/minecraft #Make Backup of Server cp minecraft_server.jar minecraft_server.jar-backup cp -r world world-backup #Stop Minecraft Server server_session=$(screen -ls | grep minecraftd | cut -d '(' -f1) #screen -X -S 718.minecraftd quit rm -f minecraft_server.jar wget -O minecraft_server.jar $new_server_download_link chown -R mcuser:mcuser /opt/minecraft chmod +x /opt/minecraft/minecraft_server.jar /opt/minecraft/./start_server.sh fi
Steffs Version
#!/bin/bash #------------------------------------------------------------------------------------------------------------- # # Subject: minecraft_server_update.sh # Description : This Script updates the Minecraft Server to the actual version # Author: Stefan Gutknecht <stefgu@bluewin.ch> # Created: 2019.07.25 # Version: v0.1 # Use: You can start this script manually or you can automate it with cron/crontab # # Changelog: # --------- # # v0.1- Creation of this Script #------------------------------------------------------------------------------------------------------------- # Define BASH-Color Output NORMAL='\e[39m' GREEN='\e[32m' RED='\e[31m' CYAN='\e[36m' # Actual Date Variable - Formatted datum=$(date +"%Y%m%d") # Get the PID of the minecraft process screen_process=$(ps -aux | grep minecraftd | grep -v "grep" | awk 'NR==1{print $2}') # Define Server Variables for comparing actual_server_version=$(cat /opt/minecraft/logs/latest.log | grep -e 'server\sversion\s' | cut -d ' ' -f8) server_version_mojang=$(curl -s https://www.minecraft.net/de-de/download/server | grep -e "minecraft_server." | cut -d '.' -f5-7 | grep -v "jar") if [ $actual_server_version = $server_version_mojang ]; then echo -e "$GREEN Aktuell keine neue Server-Version verfuegbar $NORMAL - $CYAN Nothing to do $NORMAL" fi if [ $actual_server_version != $server_version_mojang ]; then echo -e "$RED Update available $NORMAL - $CYAN Will make the necessary Steps ... $NORMAL" # Kill the minecraft process kill -9 $screen_process 2>/dev/null fail_code=$(echo "$?") if [ $? == 0 ]; then echo -e "$GREEN R.I.P - Screen Process$NORMAL" else echo -e "$RED Something went wrong - couldn't kill the process$NORMAL" echo "$fail_code" exit 0 fi # Backup the minecraft_server.jar File echo "Backup Server-Jar-File /opt/minecraft/minecraft_server.jar to $CYAN/opt/minecraft/backup/jar/*$NORMAL" echo -ne 'x-----x (33%)\r' cp --preserve=mode,ownership /opt/minecraft/minecraft_server.jar /opt/minecraft/backup/jar/minecraft_server.jar.$datum sleep 0.5 echo -ne 'x----------------x (66%)\r' sleep 0.5 echo -ne 'x---------------------------x (100%)\r' echo -ne '\n' # Backup the minecraft world directory echo "Backup the world directory /opt/minecraft/ to $CYAN/opt/minecraft/backup/world/*$NORMAL" echo -ne 'x-----x (33%)\r' tar -czf /opt/minecraft/backup/world/world_$datum.tar.gz /opt/minecraft/world/ sleep 0.5 echo -ne 'x----------------x (66%)\r' sleep 0.5 echo -ne 'x---------------------------x (100%)\r' echo -ne '\n' # Download the new minecraft_server and set permissions download_link=$(curl -s https://www.minecraft.net/de-de/download/server | grep -e '<a href=' | grep 'launcher' | cut -d '"' -f2) echo -e "$CYANGoing to download the new version$NORMAL" wget -O /opt/minecraft/server.jar $download_link rm -f /opt/minecraft/minecraft_server.jar mv /opt/minecraft/server.jar /opt/minecraft/minecraft_server.jar echo -e "$CYAN Adapting the permissions$NORMAL" chown mcuser:mcuser /opt/minecraft chmod +x /opt/minecraft/minecraft_server.jar rm -f /opt/minecraft/server.jar # Start the new minecraft server echo -e "$RED Starting the Minecraft Server$NORMAL" echo -ne 'x-----x (33%)\r' sudo -u mcuser /opt/minecraft/start_minecraft_server.sh sleep 0.5 echo -ne 'x----------------x (66%)\r' sleep 0.5 echo -ne 'x---------------------------x (100%)\r' echo -ne '\n' # Removing old unnecessary Backups - older than 180 days echo -e "$CYAN Going to remove old Backups$NORMAL" find /opt/minecraft/backup/ -type f -mtime +180 -exec rm -f {} \; fi exit 0