# Need root
sudo su -
# Install dependancies
apt-get update && apt-get install unzip screen \
mono-runtime libmono-system-core4.0-cil libmono-sqlite4.0-cil libmysql-cil-dev \
libmono-system-runtime-serialization4.0-cil libmono-web4.0-cil libmono-system-xml-linq4.0-cil
# Add terraria group and user
sudo groupadd --gid 70001 terraria
sudo useradd --gid 70001 -d /home/terraria -m --uid 70001 -s /bin/bash terraria
# Change user to terraria
su terraria
# Make and change to bin folder
mkdir ~/bin
cd ~/bin
# Download and extract TShock Terraria Server
wget http://cloud.github.com/downloads/TShock/TShock/TShock-4.0.zip
unzip TShock-4.0.zip
# Fix case-insensitive folder
ln -s serverplugins ServerPlugins
# Run Terraria for first time, create world
# (note down auth code for admin access, and exit-nosave)
mono TerrariaServer.exe -ip 0.0.0.0 -port 7777 -maxplayers 8
# Change server password
TERRARIAPASSWORD="password";
sed -i "s/("ServerPassword": ")[^"]*(",)$/1${TERRARIAPASSWORD}2/" tshock/config.json
# Terraria is now installed, keep reading to setup startup init script
# Go back to root
exit
# Download init script to /etc/init.d/
wget -O /etc/init.d/terraria-server http://www.nooblet.org/blog/download/terraria-init.sh
# Fix permissions
chmod +x /etc/init.d/terraria-server
# Insert to startup
insserv -v /etc/init.d/terraria-server
# At this point you may want to edit the init script if you are using a
# different world-file or server-port
# Also by default, the script does not save on exit, see variable: EXIT_COMMAND
# Start the server
invoke-rc.d terraria-server start
# Check its running in screen (press Ctrl-a then d to exit)
invoke-rc.d terraria-server connect