Skip to content

Instantly share code, notes, and snippets.

@rcguy
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rcguy/5dfc0afb029fd5b33edc to your computer and use it in GitHub Desktop.
Save rcguy/5dfc0afb029fd5b33edc to your computer and use it in GitHub Desktop.
Installs INSURGENCY (2014) Dedicated Server on Ubuntu
#!/bin/bash
# Name: install-insurgency.sh
# Version: 1.0
# Author: rcguy
# Updated: 03.09.2015
# Tested on: Ubuntu Server 14.10 x64 / 2 Cores / 2GB RAM / 20 GB SSD
# ==> USER VARIABLES <==
STEAM_USER="steam" # user to run the game-server
# ==> INTERNAL SETTINGS <==
BASE_DIR="/opt/game-servers"
# steamcmd stuff
STEAMCMD_URL="http://media.steampowered.com/client/steamcmd_linux.tar.gz"
STEAMCMD_TARBALL="steamcmd_linux.tar.gz"
STEAMCMD_INSTALL_DIR="$BASE_DIR/steamcmd"
# game-server stuff
GAME="insurgency"
GAME_SERVER_DIR="$BASE_DIR/$GAME"
GAME_SERVER_CFG_URL="http://im0b.club/game-servers/$GAME.tgz" # these are default configs that need to be edited after install
GAME_SERVER_START_SCRIPT="$GAME_SERVER_DIR/start-$GAME.sh"
GAME_SERVER_UPDATE_SCRIPT="$GAME_SERVER_DIR/update-$GAME.sh"
APPID="237410"
MAP="market_coop"
MAXPLAYERS="32"
START_CMD="screen -A -m -d -S $GAME $GAME_SERVER_DIR/srcds_linux -game $GAME -console -ip $SYSTEM_IP -port 27015 +map $MAP +maxplayers $MAXPLAYERS"
# system
SYSTEM_IP=`ifconfig eth0 | awk -F: '/inet addr:/ {print $2}' | awk '{ print $1 }'` #Source: https://www.linode.com/stackscripts/view/1
LOCAL_TZ=`timedatectl status | grep Timezone | awk '{print $2}'` # Source: http://askubuntu.com/a/565139
REAL_TZ=`wget -qO - http://geoip.ubuntu.com/lookup | sed -n -e 's/.*<TimeZone>\(.*\)<\/TimeZone>.*/\1/p'` # Source: http://askubuntu.com/a/565139
CUR_TIME=`date +"%m.%d.%Y @ %T/%Z"`
# ==> SCRIPT MUST RUN WITH ROOT PRIVILAGES <==
if [ "$EUID" -ne 0 ]
then
echo -e "\nERROR!!! SCRIPT MUST RUN WITH ROOT PRIVILAGES\n"
exit 1
fi
# ==> CHECK IF THE USER VARIABLES ARE VALID <==
if [ -z "$STEAM_USER" ]; then
echo -e "\nERROR!!! Steam user-name is not set\n"
exit 1
fi
# ==> WHERE THE MAGIC HAPPENS <==
set -e
# install steamcmd
apt-get install lib32gcc1 -y
mkdir -p $STEAMCMD_INSTALL_DIR
cd $STEAMCMD_INSTALL_DIR
wget -q $STEAMCMD_URL
tar -xvzf $STEAMCMD_TARBALL
rm $STEAMCMD_TARBALL
# install game-server
$STEAMCMD_INSTALL_DIR/steamcmd.sh +login anonymous +force_install_dir $GAME_SERVER_DIR +app_update $APPID validate +quit
mkdir -p /home/$STEAM_USER/.steam/sdk32/
ln -s $STEAMCMD_INSTALL_DIR/linux32/steamclient.so /home/$STEAM_USER/.steam/sdk32/
# install server.cfg
wget $GAME_SERVER_CFG_URL
tar -xvzf $GAME.tgz
cp *.cfg $GAME_SERVER_DIR/$GAME/cfg
rm $GAME.tgz *.cfg
# Creates start and update scripts
touch $GAME_SERVER_START_SCRIPT
cat >$GAME_SERVER_START_SCRIPT<<EOF
#!/bin/bash
# Created on $CUR_TIME
# Starts the $GAME server in a screen window named [ $GAME ]
sudo -u $STEAM_USER $START_CMD
EOF
touch $GAME_SERVER_UPDATE_SCRIPT
cat >$GAME_SERVER_UPDATE_SCRIPT<<EOF
#!/bin/bash
# Created on $CUR_TIME
# Use this script to update the $GAME server to the latest version
sudo -u $STEAM_USER $STEAMCMD_INSTALL_DIR/steamcmd.sh +login anonymous +force_install_dir $GAME_SERVER_DIR +app_update $APPID validate +quit
EOF
chmod a+x $GAME_SERVER_UPDATE_SCRIPT $GAME_SERVER_START_SCRIPT
# set file permissions
chown -R $STEAM_USER:$STEAM_USER $BASE_DIR
# set motd
cat >> /etc/motd.tail <<EOF
------------------------------------------------------------------------------------------
This $GAME server has been deployed using rcguys Source Dedicated Server Install Script.
Make sure you edit the default configuration file (server.cfg) before running the $GAME server.
To edit the $GAME server.cfg, do the following:
# nano $GAME_SERVER_DIR/$GAME/cfg/server.cfg
To start $GAME, run the following:
# $GAME_SERVER_START_SCRIPT
All files related to the $GAME server are in: $GAME_SERVER_DIR
------------------------------------------------------------------------------------------
To delete this message of the day: rm -rf /etc/motd.tail
EOF
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment