Skip to content

Instantly share code, notes, and snippets.

@lazypower
Forked from Ribesg/bash_aliases.sh
Created December 21, 2013 23:17
Show Gist options
  • Save lazypower/8076479 to your computer and use it in GitHub Desktop.
Save lazypower/8076479 to your computer and use it in GitHub Desktop.
alias sb_start="sudo start starbound"
alias sb_stop="sudo stop starbound"
alias sb_restart="sb_stop;sb_start"
alias sb_update="sudo /home/ribesg/sb_update"
alias sb_online="netstat -nt | grep -c 21025"
alias sb_status="sudo status starbound"
#!/bin/bash
###########################
## Default Configuration ##
###########################
# STEAM_USER - The Steam or Starbound unix user, whatever you named it
STEAM_USER="steam"
# STARBOUND_FOLDER - The root starbound folder
# WARNING: THIS SCRIPT ERASE THIS FOLDER - DOUBLE CHECK IT!
STARBOUND_FOLDER="/home/$STEAM_USER/starbound"
# TO_BACKUP_FOLDER - Should contain the folder to backup
# You can use the linuxXX folder or the whole starbound folder, or just the universe folder
TO_BACKUP_FOLDER="/home/$STEAM_USER/starbound/linux64/universe"
# DEST_FILE - The destination file for backup
# I use the date in it, but you can do whatever you want
DATE=$(date +%F_%H:%M:%S)
DEST_FILE="/home/$STEAM_USER/backups/universe-$DATE.tar.bzip2"
# STEAM_CMD - Location of the steamcmd.sh script
STEAM_CMD="/home/$STEAM_USER/steamcmd.sh"
# STEAM_LOGIN - Do I need to define what it is
STEAM_LOGIN="YourSteamLogin"
# STEAM_PASSWORD - In the futur we should be able to use anonymous Steam login...
STEAM_PASSWORD="YourSteamPassword"
# SERVER_PASSWORD - The password to apply to the server
# Note: Setting this to empty will apply an empty password, aka no password
SERVER_PASSWORD="YourServerPassword"
#
# Arguments that can be changed by command line
#
# Will be set to true if argument passed is "clean"
CLEAN=false
if [[ "$1" == "clean" ]]; then
CLEAN=true
echo "Clean set to true"
fi
# Will be set to true if argument passed is "nobackup"
NOBACKUP=false
if [[ "$1" == "nobackup" ]]; then
NOBACKUP=true
echo "Nobackup set to true"
fi
############
## Script ##
############
echo "###############################"
echo "## Updating Starbound Server ##"
echo "###############################"
RESTART=false
# Check server status and shut it down if it's online
echo
echo "1 - Checking server status..."
STATUS=$(sudo initctl status starbound)
echo "Status: $STATUS"
if [[ "$STATUS" =~ ^(.*)start(.*)$ ]]; then
echo "Server is online! Shutting down..."
sudo initctl stop starbound >/dev/null 2>&1
echo "Server shut down!"
RESTART=true
else
echo "Server is offline!"
fi
echo "1 - Done!"
# Backup the whole server, just in case
echo
echo "2 - Make a backup of the $TO_BACKUP_FOLDER folder"
if $NOBACKUP; then
echo "2 - Skipped!"
elif [ ! -d "$TO_BACKUP_FOLDER" ]; then
echo "2 - Not found!"
else
echo "Compressing $(sudo find $TO_BACKUP_FOLDER/* -type f | wc -l) files..."
sudo tar cf - $TO_BACKUP_FOLDER -P | sudo pv -w 80 -s $(sudo du -sb $TO_BACKUP_FOLDER | sudo awk '{print $1}') | sudo bzip2 > $DEST_FILE
sudo chown $STEAM_USER:$STEAM_USER $DEST_FILE
echo "2 - Done!"
fi
# Remove the existing starbound folder
echo
echo "3 - Remove the 'old' starbound folder $STARBOUND_FOLDER"
if $CLEAN; then
echo "Removing..."
sudo rm -rf $STARBOUND_FOLDER
echo "3 - Done!"
else
echo "3 - Skipped!"
fi
# Use SteamCMD to re-download the up-to-date server
echo
echo "4 - Update the server using SteamCMD"
echo "Calling $STEAM_CMD..."
sudo su $STEAM_USER -c "$STEAM_CMD +login $STEAM_LOGIN $STEAM_PASSWORD +force_install_dir $STARBOUND_FOLDER +app_update 211820 validate +quit"
echo "4 - Done!"
# Set password in config
CONFIG_FILE="$STARBOUND_FOLDER/assets/default_configuration.config"
echo
echo "5 - Setting password in $CONFIG_FILE"
echo "Replacing..."
sudo su $STEAM_USER -c "mv $CONFIG_FILE $CONFIG_FILE.tmp"
sudo su $STEAM_USER -c "cat $CONFIG_FILE.tmp | jq '.serverPasswords = [ \"$SERVER_PASSWORD\" ]' > $CONFIG_FILE"
echo "5 - Done!"
# If the server was on, restart it
if $RESTART; then
echo
echo "6 - The server was online, restart it"
echo "Restarting..."
sudo initctl start starbound >/dev/null 2>&1
echo "6 - Done!"
else
echo
echo "6 - The server was offline, we do not restart it"
fi
echo
echo "######################################"
echo "## Starbound Server update Complete ##"
echo "######################################"
#!upstart
description "Starbound"
# As Steam user
setuid steam
# Start the job
exec '/home/steam/starbound/linux64/launch_starbound_server.sh'
# Start on boot (when Disk + Network OK)
start on filesystem and net-device-up IFACE=lo
# Restart the process if it dies
respawn
# Give up if restart occurs 10 times in 90 seconds
respawn limit 10 90
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment