Skip to content

Instantly share code, notes, and snippets.

@Scrxtchy
Last active August 12, 2016 21:33
Show Gist options
  • Save Scrxtchy/0e46117968a9267442583787e4ea5fc9 to your computer and use it in GitHub Desktop.
Save Scrxtchy/0e46117968a9267442583787e4ea5fc9 to your computer and use it in GitHub Desktop.
tu.sh

#tu.sh Bascially it's a bunch of spaghetti I made in an afternoon.
It will only shutdown the server and update when the new build is publically avaliable.

##Usage ./tu.sh Check for a force update file
./tu.sh online Check build id with lastest public version

##Setup It requires jq, this is on apt-get or whatever, but not the required versions, download it from github
If someone wants to write something better, comments and forks are appreciated.

Currently, I run tmux within my terminal instead of screen as I see it as a vast improvment. Using tmux rename-window tower to rename a window to tower, which tu.sh can use to target and apply commands to stop and start the server. The commands in the shell file also rely that the window has it's working directory at the main /Tower/ directory of game

The tub file contains the current build used by the server, which is used to compare against the one stored on the steam server
and the dotush file is a temporary file that is used to force and update

I have a file on my machine that will create this file over an ssh connection
ssh -t [user]@[address] "touch dotush" Edit this appropriately to where you want it stored, but be sure to edit the script to compensate

Finally, the use of cron is used to fire off these commands;

0 * * * * ~/tu.sh online
*/5 * * * * ~/tu.sh

In human terms;

  • Check against online bulid every hour on the hour
  • Check for a force update file every five minutes
#!/bin/bash
# https://gist.github.com/Scrxtchy/0e46117968a9267442583787e4ea5fc9
#CONFIG
scmdTuDir=Tower
if [[ ! -f tub ]]
then
echo "0" > tub
fi
echo -e "\e[0;32mExecuting tush\e[0m"
if [[ "$1" -eq "online" ]]
then
echo "getting build id"
NEW=$(curl -s 'https://steampics-mckay.rhcloud.com/info?apps=439660&prettyprint=1' | jq '.apps."439660".depots.branches.public.buildid' | sed 's/"//g')
else
NEW=$(cat tub) #because fuck you
fi
OLD=$(cat tub)
if [ $NEW != $OLD ] || [ -a ~/dotush ]
then
if [ -a ~/dotush ]
then
echo "force update file existed, forcing update"
rm ~/dotush
fi
echo "Bombing the Tower..."
tmux send-keys -t tower C-c
echo -e "Going full \e[0;33mGaben\e[0m..."
echo "-------------------------------------- STEAM LOGS --------------------------------------"
~/steamcmd/steamcmd.sh +login anonymous +force_install_dir ./$scmdTuDir +app_update 439660 +quit
echo "-------------------------------------- STEAM LOGS --------------------------------------"
echo "Building the tower..."
tmux send-keys -t tower './Binaries/Linux/TowerServer-Linux-Shipping' Enter
echo "Log Changes..."
echo $NEW > tub
else
echo -e "\e[0;31mServer does not need updating\e[0m"
fi
echo "BYE BYE"
@tamara-schmitz
Copy link

I reinstalled my server and I switched to running every server as a docker instance. I'd like to use your script in a modified form in my dockerfile. Could you please add some form of credit or license head to your script so that you get properly credited?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment