Skip to content

Instantly share code, notes, and snippets.

@x3ro
Last active September 29, 2019 18:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save x3ro/3730343 to your computer and use it in GitHub Desktop.
Save x3ro/3730343 to your computer and use it in GitHub Desktop.
Teamspeak 3 installation script for Debian based systens (incl. Ubuntu)
#!/bin/bash
#
# A small script that sets up a teamspeak 3 server.
# Tested on debian and ubuntu.
#
# Source: http://coding-journal.com
#
TMP="/tmp/teamspeak/"
INSTALL_PATH="/usr/local/teamspeak3/"
STARTSCRIPT="ts3server_startscript.sh"
function error {
echo -e "\e[00;31m$1\e[0m"
}
function abort {
error "$1"; exit 1;
}
function notice {
echo -e "\e[01;33m$1\e[0m"
}
if [ "$1" == "" ]; then
abort "Please tell me which teamspeak tar.gz you would like me to install."
fi
if [ ! -d "$TMP" ]; then
mkdir "$TMP";
else
abort "Temporary directory already exists. Please delete $TMP";
fi
notice "Extracting $1 to $TMP"
tar -xzf $1 -C "$TMP" ||
abort "Extracting the archive didn't work.";
DIR="$TMP`ls $TMP`/"
notice "Moving directory $DIR to $INSTALL_PATH"
mv $DIR $INSTALL_PATH ||
abort "Failed moving the teamspeak files to the installation directory. Perhaps you need to be root?"
# See http://forum.teamspeak.com/showthread.php/57359-insserv-reports-an-error for more
# information why this needs to be done.
notice "Patching $INSTALL_PATH$STARTSCRIPT with LSB tags"
read -r -d '' PATCH <<EOF
1a2,11
> ### BEGIN INIT INFO
> # Provides: teamspeak3-server
> # Required-Start:
> # Required-Stop:
> # Default-Start: 2 3 4 5
> # Default-Stop: 0 1 6
> # Short-Description: teamspeak3-server startscipt
> # Description:
> #
> ### END INIT INFO
EOF
patch $INSTALL_PATH$STARTSCRIPT <<< "$PATCH" ||
abort "Patching the startscript failed :("
notice "Symlinking startscript to /etc/init.d/teamspeak"
ln -s $INSTALL_PATH$STARTSCRIPT /etc/init.d/teamspeak ||
abort "Couldn't copy startscript"
notice "Updating teamspeak service to start on boot"
update-rc.d teamspeak defaults ||
abort "Couldn't set autostart for teamspeak service"
notice "Starting teamspeak service"
invoke-rc.d teamspeak start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment