Skip to content

Instantly share code, notes, and snippets.

@tmad40blue
Last active January 26, 2016 05:41
Show Gist options
  • Save tmad40blue/ed4a8fdef24389ebf81b to your computer and use it in GitHub Desktop.
Save tmad40blue/ed4a8fdef24389ebf81b to your computer and use it in GitHub Desktop.
BungeeCord updater script.
#! /bin/bash
# BungeeCord Updater/Restarter
# By tmad40blue - http://tmad40.blue/
# Bash safety stuff
set -o errexit
# Set username that should run this process
USERNAME="minecraft"
SERVNAME="bungee"
# Set working directories
DIRECTORY="/home/minecraft"
SERVDIR="/home/minecraft/servers/bungee"
# Set SERVERPID so that we can check if the server is running
# SERVICE="$(pgrep -f $SERVNAME)"
# Set tmux session name
SESSION="bungee"
# Create is_running function to check if Bungee is running
is_running() {
# echo "DEBUG: U: ${USERNAME} S: {$SERVNAME}"
return `pgrep -u "$USERNAME" -f "$SERVNAME" > /dev/null`
}
# Create as_user function to ensure commands are not being run as root
as_user() {
if [ "$ME" = "$USERNAME" ] ; then
bash -c "$1"
else
su - "$USERNAME" -c "$1"
fi
}
echo -e "\n \n \n"
echo -e "$(tput bold)$(tput smul)BungeeCord Updater Script$(tput rmul) $(tput sgr 0)"
echo -e "$(tput bold)Written by $(tput setaf 6)tmad40blue $(tput sgr 0) -- $(tput setaf 4)http://tmad40.blue/ $(tput sgr 0)"
echo -e "$(tput dim)Version 1.1 $(tput sgr 0)"
echo -e "\n \n \n"
sleep 1
# Attach to tmux session and save, then stop
as_user "tmux send-keys -l -t "$SESSION" end"
as_user "tmux send-keys -t "$SESSION" Enter"
# Wait until BungeeCord server has stopped
if is_running ; then
echo -e "$(tput dim)Stopping $(tput setaf 3)$SERVNAME$(tput sgr 0)..."
sleep 10
if is_running ; then
echo -e "$(tput setaf 1)$(tput bold)ERROR: $(tput sgr 0)$SERVNAME could not be stopped gracefully!"
else
echo -e "$(tput setaf 2)$SERVNAME stopped.$(tput sgr 0)"
fi
else
echo -e "$(tput setaf 1)$(tput bold)ERROR: $(tput sgr 0)Server was not running!"
fi
# Run Bungee downloader script
echo -e "$(tput setaf 3)Updating to latest BungeeCord...$(tput sgr 0)"
# Make build dir
mkdir BungeeDL/
cd BungeeDL/
# Download all the things
wget http://ci.md-5.net/job/BungeeCord/lastSuccessfulBuild/artifact/bootstrap/target/BungeeCord.jar
wget http://ci.md-5.net/job/BungeeCord/lastSuccessfulBuild/artifact/module/cmd-alert/target/cmd_alert.jar
wget http://ci.md-5.net/job/BungeeCord/lastSuccessfulBuild/artifact/module/cmd-find/target/cmd_find.jar
wget http://ci.md-5.net/job/BungeeCord/lastSuccessfulBuild/artifact/module/cmd-list/target/cmd_list.jar
wget http://ci.md-5.net/job/BungeeCord/lastSuccessfulBuild/artifact/module/cmd-send/target/cmd_send.jar
wget http://ci.md-5.net/job/BungeeCord/lastSuccessfulBuild/artifact/module/cmd-server/target/cmd_server.jar
wget http://ci.md-5.net/job/BungeeCord/lastSuccessfulBuild/artifact/module/reconnect-yaml/target/reconnect_yaml.jar
# Copy all the things
cp * $DIRECTORY/servers/bungee/
# Clean up
cd $DIRECTORY
rm -rf BungeeDL/
# All done
echo -e "$(tput setaf 2)All done! $(tput sgr 0)The latest BungeeCord JAR should now be in your server directory."
# Start Bungee again
echo -e "$(tput dim) Restarting $(tput setaf 3)$SERVNAME$(tput sgr 0)..."
as_user "tmux send-keys -t "$SESSION" './start.sh' Enter"
if is_running ; then
echo -e "$(tput setaf 2)$SERVNAME is now running.$(tput sgr 0)"
else
echo -e "$(tput setaf 1)$(tput bold)ERROR: $(tput sgr 0)$SERVNAME did not restart!"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment