Wrote a bash scripts for updating FTBserverBeyond(not FTBBeyond specific)

W

wgoff194

Guest
Hello FeedTheBeast Brethren,

I run a FTB Beyond server and hate the update process. I find moving my personal server from FTB Beyond from its current version to the latest release a real pain. However as a Linux admin I find minor scripting to be rewarding. I have created a 2 script system for staging and making live a new update. I use an AMP/MCMA server setup so I will use this for examples.

---- Warning ------
Although tested in my enviroment. Use of these scripts or dirivatives is at your own risk. Using this script is considered an acknowledgement of this warning. I hold no liability.

Remember Backups are your friend!

There are a number of things that need to be set up one time. To explain I will use the following:
$BasePath - This is the Parent Directory path where your Minecraft server resides (ie /home/AMP/.ampdata/instances/MCMA/
$StagingPath - This is the directory inside $BasePath for staging (ie mc-staging in /home/AMP/.ampdata/instances/MCMA/)
$BackupPath - This is the Directory the current live site will be backed up to (ie mc-backups in /home/AMP/.ampdata/instances/MCMA/)
$Extramods - Location of Mods not typically included in your FTB pack (ie $StagingPath/mc-extramods
$FTBType - This is the FTB Pack in use (ie FTBBeyondServer found in the name of the zip file FTBBeyondServer_1.9.0.zip)
$FTBVersion - The version of the FTB pack (ie 1.9.0 as seen in the name of the zip file, in this script a pront will ask for this)
$World - Name of your world directory
One time must setup:
A directory for $StagingPath will need to be created prior to use of script
A directory for $BackupPath will need to be created prior to use of script
If using additional mods the $Extramods folder and its subfolders (see spoiler below) will need to be created in the $StagingPath directory
Example of Extramods
/home/AMP/.ampdata/instances/MCMA/mc-staging/mc-extramods/
- mods/RTG-1.10.2-4.1.2.4.jar
- mods/GeographiCraft-1.9.4-0.7.6.jar
- mods/Dynmap-2.4-forge-1.10.2.jar
- mods/worldedit-forge-mc1.10.2-6.1.4-dist.jar
- config/GeographiCraft/geographicraft.cfg
- config/GeographiCraft/CCDimensions.cfg
- config/Dynmap.cfg
- config/worldedit/worldedit.properties
and so forth

And now the scripts!
Place these in the $BasePath directory & always run as the linux user minecraft runs as

Updating Script `update.sh`

Code:
#!/bin/bash

###########################
# Updating FTB to go live with provided version DL link
# Script by WBrown 
# Originated on personal FTB Beyond server
# wget rewrite with assistance from u_phit URL: https://www.reddit.com/user/u_phit
############################

# Examples of use using data from FTB Beyond Version 1.9.0 for MC 1.10.2
# https://www.feed-the-beast.com/projects/ftb-beyond/files/2434638#additional-files

# Script starts with asking for the download url from https://www.feed-the-beast.com/projects/ftb-beyond/files
echo "\n\nWhat is the FTB Download link?\n(ie https://www.feed-the-beast.com/projects/ftb-beyond/files/2435256/download)"
read FTBDLa
FTBDLb="$(curl -i $FTBDLa | grep Location | awk '{print$2}'| tr -d '\r')"
ZipFile="$(echo $FTBDLb | awk -F"/" '{print$7}')"
FTBType="$(echo $ZipFile | awk -F"\_" '{print$1}')"
FTBVersion="$(echo $ZipFile | awk -F"_" '{print$2}' | awk -F"." '{print$1"."$2"."$3}')"

# Sets other variables needed 
# Change to match for FTBType and path locations 
# Base directory will be the directory the the Minecraft server directory resides
BasePath="/home/AMP/.ampdata/instances/MCMA/"
StagingPath="mc-staging"
BackupPath="mc-backups"
World="world"

# Goes to base directory and creates the staging directory
cd $BasePath
mkdir $StagingPath/Minecraft-$FTBType-$FTBVersion

# Updates user of new staging directory
echo "\nStaging directory: \n$BasePath$StagingPath/Minecraft-$FTBType-$FTBVersion/"

#Downloads zip
echo "\nDownloading Specified file $ZipFile from $FTBDLb"
wget -P ${BasePath}${StagingPath}/Minecraft-$FTBType-$FTBVersion/ $FTBDLb 

# unzips FTB zip into staging directory
unzip $StagingPath/Minecraft-$FTBType-$FTBVersion/$ZipFile -d $StagingPath/Minecraft-$FTBType-$FTBVersion
echo "\nUnzip complete."

# RSyncs live Mincraft files without overwriting new FTB data (world is not moved in this script. See staging2live.sh
rsync -av --progress Minecraft/* $StagingPath/Minecraft-$FTBType-$FTBVersion --exclude mods --exclude libraries --exclude scripts --exclude modpack --exclude config --exclude ServerStart.sh --exclude ServerStart.bat --exclude $World
echo "\nLive to Staging rsync Complete."

# Rsync Additional Mods places in proper pathing (example below) 
# mc-staging/mc-extramods/
#   - mods/RTG-1.10.2-4.1.2.4.jar
#   - mods/GeographiCraft-1.9.4-0.7.6.jar
#   - mods/Dynmap-2.4-forge-1.10.2.jar
#   - mods/worldedit-forge-mc1.10.2-6.1.4-dist.jar
#   - config/GeographiCraft/geographicraft.cfg
#   - config/GeographiCraft/CCDimensions.cfg
#   - config/Dynmap.cfg
#   - config/worldedit/worldedit.properties
# and so forth 
rsync -av --progress $StagingPath/mc-extramods/* $StagingPath/Minecraft-$FTBType-$FTBVersion
echo "\nAdditional Mods rsync Complete."

echo "\n\nStaging Complete, please verify Minecraft Server is stopped.\n\n"
read -p "Press Enter to Continue" FTBDLa

# Move Live MC to mc-backups/Minecraft-${FTBType}-[date]
mv Minecraft mc-backups/Minecraft-${FTBType}-$(date +"%Y-%m-%d")
echo "\nLive Minecraft successfully moved to ${BasePath}mc-backups/Minecraft-${FTBType}-$(date +"%Y-%m-%d")"

# Makes new Minecraft folder and rsyncs the staging in
mkdir Minecraft/
rsync -av --progress $StagingPath/Minecraft-$FTBType-$FTBVersion/* Minecraft
echo "\nStaging has been moved into ${BasePath}Minecraft/"

# Syncs world data from new backup to live
mkdir Minecraft/$World/
rsync -av --progress mc-backups/Minecraft-${FTBType}-$(date +"%Y-%m-%d")/$World/* Minecraft/$World
echo "\n$World has been moved into ${BasePath}Minecraft/"

Thank you for reviewing. Hopefully other Linux Admins will be able to use this for easy and quick updated to their FTB server.