Terraria - OneClick

by linode
4 deployments · 4 still active · last rev. 2 days ago

Compatible with: Debian 9
						#!/bin/bash
#
#<UDF name="steamuser" Label="Steam username"  example="username" />
#<UDF name="steampassword" Label="Steam password, must have Steam Guard turned off for deployment" example="YourSteamPassword" />
#<UDF name="pubkey" Label="SSH public key" example="ssh-rsa..." default="" />

#Game config options

#<UDF name="seed" label="seed" default="AwesomeSeed"/>
#<UDF name="worldname" label="worldname" default="world1"/>
#<UDF name="difficulty" label="difficulty" default="0"/>
#<UDF name="maxplayers" label="maxplayers" default="20"/>
#<UDF name="password" label="password" default=""/>
#<UDF name="port" label="port" default="7777"/>
#<UDF name="motd" label="motd" default="Powered by Linode!"/>


#Non-MVP config options
#name="autocreate" label="autocreate" default="1"/>
#name="worldpath" label="worldpath" default="~/.local/share/Terraria/Worlds/"/>
#name="banlist" label="banlist" default="banlist.txt"/>
#name="priority" label="priority" default="1"/>
#name="upnp" label="upnp" default="1"/>
#name="npcstream" label="npcstream" default="60"/>
#name="secure" label="secure" default="1"/>
#name="language" label="language" default="en-US"/>


source <ssinclude StackScriptID="349139">
source <ssinclude StackScriptID="370022">

exec 1> >(tee -a "/var/log/stackscript.log") 2>&1

GAMESERVER="terrariaserver"

set_hostname
apt_setup_update

if [[ "$PUBKEY" != "" ]]; then
  add_pubkey
fi

# Terraria specific dependencies
debconf-set-selections <<< "postfix postfix/main_mailer_type string 'No Configuration'"
debconf-set-selections <<< "postfix postfix/mailname string `hostname`"
dpkg --add-architecture i386
apt update
sudo apt -q -y install mailutils postfix \
curl wget file bzip2 gzip unzip bsdmainutils \
python util-linux ca-certificates binutils bc \
jq tmux lib32gcc1 libstdc++6 libstdc++6:i386

# Install linuxGSM
linuxgsm_install

echo Requires Steam username and password to install
su - $GAMESERVER -c "mkdir -p /home/$GAMESERVER/lgsm/config-lgsm/$GAMESERVER"
su - $GAMESERVER -c "touch /home/$GAMESERVER/lgsm/config-lgsm/$GAMESERVER/common.cfg"
su - $GAMESERVER -c "echo steamuser=\"$STEAMUSER\" >> /home/$GAMESERVER/lgsm/config-lgsm/$GAMESERVER/common.cfg"
su - $GAMESERVER -c "echo steampass=\''$STEAMPASSWORD'\' >> /home/$GAMESERVER/lgsm/config-lgsm/$GAMESERVER/common.cfg"

# Install Terraria
game_install

sed -i s/#seed=AwesomeSeed/seed="$SEED"/ home/"$GAMESERVER"/serverfiles/"$GAMESERVER".txt
sed -i s/worldname=world1/worldname="$WORLDNAME"/ home/"$GAMESERVER"/serverfiles/"$GAMESERVER".txt
sed -i s/difficulty=0/difficulty="$DIFFICULTY"/ home/"$GAMESERVER"/serverfiles/"$GAMESERVER".txt
sed -i s/maxplayers=20/maxplayers="$MAXPLAYERS"/ home/"$GAMESERVER"/serverfiles/"$GAMESERVER".txt
sed -i s/port=7777/port="$PORT"/ home/"$GAMESERVER"/serverfiles/"$GAMESERVER".txt
sed -i s/password=/password="$PASSWORD"/ home/"$GAMESERVER"/serverfiles/"$GAMESERVER".txt
sed -i s/motd=.*/motd="$MOTD"/ home/"$GAMESERVER"/serverfiles/"$GAMESERVER".txt

#Non-MVP config options
# sed -i s/autocreate=1/autocreate="$AUTOCREATE"/ home/"$GAMESERVER"/serverfiles/"$GAMESERVER".txt
#sed -i s/worldpath=\~\/\.local\/share\/Terraria\/Worlds\//worldpath="$WORLDPATH"/ home/"$GAMESERVER"/serverfiles/"$GAMESERVER".txt
#sed -i s/banlist=banlist.txt/banlist="$BANLIST"/ home/"$GAMESERVER"/serverfiles/"$GAMESERVER".txt
#sed -i s/\#priority=1/priority="$PRIORITY"/ home/"$GAMESERVER"/serverfiles/"$GAMESERVER".txt
#sed -i s/#npcstream=60/npcstream="$NPCSTREAM"/ home/"$GAMESERVER"/serverfiles/"$GAMESERVER".txt
#sed -i s/#upnp=1/upnp="$UPNP"/ home/"$GAMESERVER"/serverfiles/"$GAMESERVER".txt
#sed -i s/secure=1/secure="$SECURE"/ home/"$GAMESERVER"/serverfiles/"$GAMESERVER".txt
#sed -i s/language=en\-US/language="$LANGUAGE"/ home/"$GAMESERVER"/serverfiles/"$GAMESERVER".txt

# Setup crons and create systemd service file
service_config

# Start the service and setup firewall
ufw_install
ufw allow "$PORT"/tcp
ufw allow "$PORT"/udp
ufw enable
fail2ban_install
systemctl start "$GAMESERVER".service
systemctl enable "$GAMESERVER".service
stackscript_cleanup