#!/bin/bash
# script inspired by cool34000 initial smeserver contribs
# it allows to download all required binaries to run teamspeak 2
# current release : #1 
# please update at every change
# copyleft JP Pialasse @ contribs.org 2013


# Variables
SRVNAME=$(/sbin/e-smith/db configuration get SystemName)
DOMAINNAME=$(/sbin/e-smith/db configuration get DomainName)
TSPASS=$(/sbin/e-smith/db configuration getprop teamspeak UserPassword)

echo "Dowloading file"
cd /temp
wget ftp://ftp.freenet.de/pub/4players/teamspeak.org/releases/ts2_server_rc2_202319.tar.bz2 -O ts2_server_rc2_202319.tar.bz2
echo "Decompressing files..."
tar -xjf ts2_server_rc2_202319.tar.bz2 -C /opt
mv -f /opt/tss2_rc2 /opt/teamspeak
mv -f /opt/teamspeak/server_linux  /opt/teamspeak/server_linux.old
wget ftp://ftp.freenet.de/pub/4players/teamspeak.org/developer/server/202401/server_linux -O server_linux
#cp -f /usr/share/doc/teamspeak-server-2.0.24.1/Sources/server_linux /opt/teamspeak/
rm -f /opt/teamspeak/teamspeak2-server_startscript

echo "Creating user teamspeak..."
useradd -M -c 'TeamSpeak Server' -d /opt/teamspeak teamspeak -s /bin/bash -p '$TSPASS'
chown -R root:teamspeak /opt/teamspeak
chmod 770 /opt/teamspeak
chmod 750 /opt/teamspeak/server_linux
chmod 750 /opt/teamspeak/sqlite_sql

/sbin/e-smith/signal-event remoteaccess-update

echo "Restarting Apache..."
/sbin/e-smith/expand-template /opt/tsweb/config.php
/sbin/e-smith/expand-template /etc/httpd/conf/httpd.conf
/etc/rc7.d/S86httpd-e-smith sigusr1

echo "Starting the daemon..."
/etc/rc7.d/S98teamspeak start

echo " "
echo "-------------------------------------------------------------------------------"
echo "TeamSpeak Server installation finished."
echo "You can access to the configuration page at: http://$SRVNAME:14534"
/etc/rc7.d/S98teamspeak passwords
echo " "
echo "The web page for teamspeak webusers: http://$DOMAINNAME/tsweb"
echo " "
/sbin/e-smith/config show teamspeak
echo "-------------------------------------------------------------------------------"


