Skip to content

Instantly share code, notes, and snippets.

@RoyCurtis
Last active November 19, 2016 12:41
Show Gist options
  • Save RoyCurtis/e7f85fd3a836781d224e955601341abf to your computer and use it in GitHub Desktop.
Save RoyCurtis/e7f85fd3a836781d224e955601341abf to your computer and use it in GitHub Desktop.
#!/bin/bash
# Minecraft live->beta sync script by RoyCurtis
# MIT license, 2016
# CONFIGURATION:
# Path to live Survival server. DO NOT LEAVE EMPTY!
LIVE=/path/to/your/Survival
# Path to beta Survival server. DO NOT LEAVE EMPTY!
BETA=/path/to/your/SBeta
# Path to changes to apply on top of beta. DO NOT LEAVE EMPTY!
BETADELTA=/path/to/your/SBetaChanges
# Path to Dynmap tiles for beta server. DO NOT LEAVE EMPTY!
DYNTILES=/path/to/your/Dynmap/SBeta
# Identity of beta server's tmux session
IDENT=YourBeta
# FUNCTIONS:
function onError
{
if [ $? -ne 0 ]; then
echo -e "*** $1 ***"
exit 1
fi
}
function doSQL
{
mysql --login-path=your_minecraft_login_path -e "$1"
onError "MYSQL ERROR; SEE ABOVE"
}
# OPTIONS:
while test $# -gt 0
do
case "$1" in
--no-kill) noKill=true
;;
--no-start) noStart=true
;;
--skip-sql) skipSQL=true
;;
--skip-file) skipFile=true
;;
--skip-delta) skipDelta=true
;;
--skip-spigot) skipSpigot=true
;;
--skip-plugins) skipPlugins=true
;;
*) echo "[SYNC] Unknown param '$1'"
echo "Usage: refreshBeta.sh [OPTIONS]"
echo ""
echo " --no-kill Don't kill session"
echo " --no-start Don't start session"
echo " --skip-sql Skips MySQL refresh"
echo " --skip-file Skips file refresh"
echo " --skip-delta Skips applying BETA changes"
echo " --skip-spigot Skips Spigot building"
echo " --skip-plugins Skips plugin update"
exit 1
;;
esac
shift
done
# SCRIPT:
cd $BETA
echo -e "[SYNC] Working in directory $BETA"
echo -e "[SYNC] Syncing live into beta..."
# Session
if [ -z $noKill ]; then
echo -e "[SESSION] Killing tmux session..."
tmux kill-session -t $IDENT
fi
# MySQL
if [ -z $skipSQL ]; then
echo -e "[SQL] Deleting existing beta databases..."
doSQL "DROP DATABASE IF EXISTS \`your_beta\`;"
doSQL "DROP DATABASE IF EXISTS \`your_prism_beta\`;"
echo -e "[SQL] Creating new beta databases..."
doSQL "CREATE SCHEMA \`your_beta\` DEFAULT CHARACTER SET utf8;"
doSQL "CREATE SCHEMA \`your_prism_beta\` DEFAULT CHARACTER SET utf8;"
echo -e "[SQL] Copying minecraft database into minecraft_beta database..."
mysqldump --login-path=your_minecraft_login_path your_minecraft | mysql --login-path=your_minecraft_login_path your_beta
onError "MYSQL ERROR; SEE ABOVE"
fi
# Filesystem
if [ -z $skipFile ]; then
echo -e "[FILE] Deleting existing beta directory..."
cd ~
rm -rfd $BETA
echo -e "[FILE] Copying live to beta directory..."
rsync --info=progress2 -a $LIVE/ $BETA
fi
if [ -z $skipDelta ]; then
echo -e "[FILE] Copying beta changes to beta directory..."
rsync --info=progress2 -a $BETADELTA/ $BETA
onError "COULDN'T COPY CHANGES ONTO BETA; SEE ABOVE"
fi
# PaperSpigot
if [ -z $skipSpigot ]; then
cd $BETA
echo -e "[SPIGOT] Installing PaperSpigot..."
wget -O PaperSpigot.jar https://ci.destroystokyo.com/job/PaperSpigot/lastSuccessfulBuild/artifact/paperclip.jar
fi
# Plugin update
if [ -z $skipPlugins ]; then
cd $BETA/plugins
./update.sh
onError "PLUGIN UPDATE ERROR; SEE ABOVE"
fi
# Session
if [ -z $noStart ]; then
cd $BETA
echo -e "[SESSION] Restarting tmux session..."
./start.sh
fi
history -c
echo -e "[SYNC] Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment