DeDiHosting – Blog.samp-online.com

28. August 2009

Console-GUI – Services Restart-Script

Filed under: Linux — DeDi @ 12:30

Nice console Restart-GUI for viewing status-information about : mySQL, pgSQL, Apache2, proFTPd, SSHd

You can easily stop or start a service by entering the ID.

Note : pgsql is not final and tested!


ID Prozess Status am: Fri Aug 28 12:27:37 CEST 2009
0 - mySQL_DB online. PID: 3248
1 - pgsql_DB offline
2 - Apache2 online. PID: 21649
3 - proFTPd online. PID: 26904
4 - SSH-Server online. PID: 29543
Zum Starten / Stoppen bitte ID eingeben:

#!/bin/bash
#
# Author : Dennis Diel
# Last Change : 28.08.2009 - 12.30
# Name : Services Restart-Script
# Version 0.5
X=0
script="/scripts/ProcessCheck.sh"
INIT="/etc/init.d"
mysql="$INIT/mysql"
pgsql="$INIT/postgres"
apache2="$INIT/apache2"
proftpd="$INIT/proftpd"
ssh="$INIT/ssh"
 
 
 
case "$1" in
 
status)
 
	mysqlStatus()
	{
		PIDmysql=`pidof mysqld | cut -d" " -f 1 | tr -s ' '`
 
	if [ -z $PIDmysql ]; then
		echo -e "0 - \t mySQL_DB \t offline"
		mysqlAN=0
 
	elif [ $PIDmysql -gt 0 ]; then
		echo -e "0 - \t mySQL_DB \t online. PID: $PIDmysql"
		mysqlAN=1
 
	else
		echo "komischer Fehler"
		exit 2
	fi
	}
 
 
	pgsqlStatus()
	{
		PIDpgsql=`pidof pgsqld | cut -d" " -f 1 | tr -s ' '`
 
	if [ -z $PIDpgsql ]; then
		echo -e "1 - \t pgsql_DB \t offline"
		pgsqlAN=0
 
	elif [ $PIDpgsql -gt 0 ]; then
		echo -e "1 - \t pgsql_DB \t online. PID: $PIDpgsql"
		pgsqlAN=1
 
	else
		echo "komischer Fehler"
		exit 2
	fi
	}
 
 
 
	ap2Status()
	{
		PIDap2=`pidof apache2 | cut -d" " -f 1 | tr -s ' '`
 
	if [ -z $PIDap2 ]; then
		echo -e "2 - \t Apache2 \t offline"
		ap2AN=0
 
	elif [ $PIDap2 -gt 0 ]; then
		echo -e "2 - \t Apache2 \t online. PID:" $PIDap2
		ap2AN=1
 
	else
		echo "komischer Fehler"
		exit 2
	fi
	}
 
 
 
	proftpdStatus()
	{
		PIDproftpd=`pidof proftpd | cut -d" " -f 1 | tr -s ' '`
 
	if [ -z $PIDproftpd ]; then
		echo -e "3 - \t proFTPd \t offline"
		proftpdAN=0
 
	elif [ $PIDproftpd -gt 0 ]; then
		echo -e "3 - \t proFTPd \t online. PID:" $PIDproftpd
		proftpdAN=1
 
	else
		echo "komischer Fehler"
		exit 2
	fi
	}
 
 
	sshStatus()
	{
		PIDssh=`pidof sshd | cut -d" " -f 1 | tr -s ' '`
 
	if [ -z $PIDssh ]; then
		echo -e "4 - \t SSH-Server \t offline"
		sshAN=0
 
	elif [ $PIDssh -gt 0 ]; then
		echo -e "4 - \t SSH-Server \t online. PID:" $PIDssh
		sshAN=1
 
	else
		echo "komischer Fehler"
		exit 2
	fi
	}
 
 
 
 
clear
echo -e "ID \t Prozess \t Status am: `date`"
 
mysqlStatus
pgsqlStatus
ap2Status
proftpdStatus
sshStatus
 
#echo mysqlAN=$mysqlAN
#echo ap2AN=$ap2AN
 
 
echo -n "Zum Starten / Stoppen bitte ID eingeben: "
read -t 30 DoIt
echo ""
	if [ -z $DoIt ]; then
		$script status
 
	elif [ $DoIt = 0 ]; then
		if [ $mysqlAN = 1 ]; then
			$mysql stop; sleep 2
			$script status
		elif [ $mysqlAN = 0 ]; then
			$mysql start; sleep 2
			$script status
		else
			echo "Fehler in mysqlAN"
		fi
 
	elif [ $DoIt = 1 ]; then
		if [ $pgsqlAN = 1 ]; then
			$pgsql stop; sleep 2
			$script status
		elif [ $pgsqlAN = 0 ]; then
			$pgsql start; sleep 2
			$script status
		else
			echo "Fehler in pgsqlAN"
		fi
 
	elif [ $DoIt = 2 ]; then
		if [ $ap2AN = 1 ]; then
			$apache2 stop; sleep 2
			$script status
		elif [ $ap2AN = 0 ]; then
			$apache2 start; sleep 2
			$script status
		else
			echo "Fehler in ap2AN"
		fi
 
	elif [ $DoIt = 3 ]; then
		if [ $proftpdAN = 1 ]; then
			$proftpd stop; sleep 2
			$script status
		elif [ $proftpdAN = 0 ]; then
			$proftpd start; sleep 2
			$script status
		else
			echo "Fehler in proftpdAN"
		fi
 
	elif [ $DoIt = 4 ]; then
		if [ $sshAN = 1 ]; then
			$ssh stop; sleep 2
			$script status
		elif [ $sshAN = 0 ]; then
			$ssh start; sleep 2
			$script status
		else
			echo "Fehler in sshAN"
		fi
 
 
	else 
		echo "Fehler in Eingabe"
		$script status
	fi
;;
 
 
 
*)
echo "Usage: $0 {status}"
exit 1
;;
esac

22. August 2009

Teamspeak2-Server Linux INIT-Script – Easy to use =)

Filed under: Linux — DeDi @ 16:49

Still in development ! Use at your own risk !

How to install a Teamspeak2-Server on Linux for Noobs :

Copy this Script to /etc/init.d/teamspeak and make it executable with : chmod +x /etc/init.d/teamspeak

/etc/init.d/teamspeak TSinstall 1
/etc/init.d/teamspeak AFinstall 1
/etc/init.d/teamspeak start 1
/etc/init.d/teamspeak stop 1
/etc/init.d/teamspeak restart 1
/etc/init.d/teamspeak status 1

replace “1″ with your instance-number, but remember : this is not the port !

After install you have to add superadmin-passwords from server.log to af/ts2afd*.pl !

if you want to start multiple instances, you have to edit the config after install!

#! /bin/sh
#
# ts-onlyfree.org Teamspeak INIT Script von Dennis Diel 
#
# Version : 0.5.3_alpha
# Last Change : 04.09.2009 - 08.30
#  
#	- Feel free to edit the script, to pass your needs.
#	- Only redistribute orignal-copies, dont redistribute your changed script without the author's prior consent!
#	- Commercial usage prohibited, but you are allowed to trial/test the script for 10 days in commercial environment.
#	- Please contact dennis.diel@web.de for further details about commercial usage and licensing.
#
# echo "##############################"
# echo "#! This Script is NOT final !#" 
# echo "#!!! use at your own risk !!!#"
# echo "##############################"
# echo ""
 
sysVARS ()
{ 
	TS_USER="ts"
	AF_USER="tsAF"
	BOT_USER="tsbot"
	NAME="teamspeak srv$2"
	serverPID="server.pid"
	# INIT="/etc/init.d/teamspeak"
	INIT="$0"
 
	TSDIR="/home/$TS_USER"
 
	PATH="/bin:/usr/bin:/sbin:/usr/sbin"
 
	DAEMON="srv$2"
	PARAMS=""
	DESC="TS-SRV"
 
	PASS="$(date +%s)"
	datum="$(date)"
 
	ftpurl="ftp://ftp.freenet.de/pub/4players/teamspeak.org/releases/"
	ts2server_archive="ts2_server_rc2_202319.tar.bz2"
	patchurl="ftp://ftp.freenet.de/pub/4players/teamspeak.org/developer/server/202401/"
	ts2server_patch="server_linux"
	AFurl="http://download.planetteamspeak.com/teamspeak2/scripts/perl/"
	AFarchive="ts2afd-0.5.zip"
 
 
}
 
case "$1" in
 
usercheck)
	if [ $(whoami) = "$TS_USER" ]; then
		echo "II>";
		echo "II> you are `whoami`"
		exit 11
	elif [ $(whoami) = "root" ]; then	
		echo "II>"; 
		echo "II> you are `whoami`"
		exit 10
	else
		echo "EE> usercheck: wrong user"
		exit 1
	fi
;;
 
enable)
sysVARS
if [ $(whoami) = "root" ] || [ $(whoami) = "$TS_USER" ]; then
	    case "$2" in
        	*)
			if [ -e $TSDIR/srv$2/ON ]; then
				echo "II>  srv$2 already enabled ( $TSDIR/srv$2/ON ) "
				exit 1
			elif [ ! -e $TSDIR/srv$2 ]; then
				echo "II>  srv$2 not found / not installed"
				exit 1
			else
				touch $TSDIR/srv$2/ON
				chown $TS_USER:$TS_USER $TSDIR/srv$2/ON	
				echo "1" > $TSDIR/srv$2/ON
				echo "II> srv$2 enabled"
				exit 0				
			fi
		;;
		esac
else 
	echo "EE> wrong user"
	exit 1
fi 
;;
 
disable)
sysVARS
if [ $(whoami) = "root" ] || [ $(whoami) = "$TS_USER" ]; then
	    case "$2" in
        	*)
		if [ -z "$2" ]; then
			$INIT enable 1
		elif [ ! -z "$2" ]; then
 
			if [ -e $TSDIR/srv$2/ON ]; then
				rm -f $TSDIR/srv$2/ON
				echo "II>  srv$2 disabled"				
				exit 0
			else
				echo "II>  srv$2 already disabled"
				exit 1				
			fi
		else 
			echo "II> Error in enable Case 2"
		fi
		;;
		esac
else 
	echo "EE> wrong user"
	exit 1
fi 
;;
 
 
 
status)
sysVARS
if [ $(whoami) = "$TS_USER" ] || [ $(whoami) = "root" ]; then
 
	case "$2" in
        	*)
 
			if [ -z "$2" ]; then
				$INIT status 1
 
			elif [ "$2" = "all" ]; then
 
						case "$3" in
							*)
 
							if [ -z "$3" ]; then
							$INIT status 1
 
							elif [ ! -z "$2" ]; then
 
								echo "II> Checking $3 Servers."
								echo "II> Case = $3"
 
								for (( I=1; $I <= $3; I++ ))
						       		do
								 	$INIT status $I; echo "II> ";
								done;
							else
								"Error in status Case 3"
							fi								
						;;
						esac
 
			elif [ ! -z "$2" ]; then
					echo -n "II> Checking srv$2..."
						if [ -e $TSDIR/srv$2/ON ]; then
							sleep 0.1 > /dev/null
							echo " is enabled."
								if [ -e $TSDIR/srv$2/$serverPID ]; then
									sleep 0.1 > /dev/null
									echo "II>  PID-File found: srv$2 { `cat $TSDIR/srv$2/$serverPID` }"
									PIDFILE=`cat $TSDIR/srv$2/$serverPID`
										if [ `pidof srv$2` ]; then
											PIDOF=`pidof srv$2`
											sleep 0.1 > /dev/null
											echo "II>  Running TS srv$2 { $PIDOF } found."
												if [ $PIDFILE = $PIDOF ];then
													sleep 0.1 > /dev/null
													echo "II>  PIDs correct, srv$2 online."
													exit 0
												else 
													sleep 0.1 > /dev/null
													echo "II>  PIDFILE differs from running PID"
													exit 5
												fi
										else
											sleep 0.1 > /dev/null
											echo "II>  process offline"
											exit 1
										fi						
 
 
 
								elif [ `pidof srv$2` ]; then
									PIDOF=`pidof srv$2`
									echo "II>  TS srv$2 $PIDOF running, but no PIDFILE found."
									exit 0
								else
									echo "II>  TS srv$2 offline"
									exit 1
 
 
								fi
 
						else
							echo " is NOT enabled, do: { $INIT enable $2 } and retry."
							exit 0
						fi
 
 
 
			else 
				echo "II>  Case 2 Error"					
			fi
 
	;;
	esac
 
 
else 
	exit 1
fi 
;;
 
 
start)
sysVARS
if [ $(whoami) = "$TS_USER" ] || [ $(whoami) = "root" ]; then
	case "$2" in
		*)
 
	if [ -z "$2" ]; then
		$INIT start 1		
 
	elif [ ! -z "$2" ]; then 
		$INIT status $2 > /dev/null
			if [ "${?}" = "0" ]; then
				echo "EE> srv$2 already online."
					if [ -e $TSDIR/srv$2/af ]; then
					 	$TSDIR/srv$2/af/flood$2 start
						exit 0
					else
						echo "Anti-Flood for srv$2 not installed."
						exit 0
					fi
 
 
 
 
			elif [ "${?}" = "1" ]; then
				echo "II> srv$2 is offline, starting..."
 
						if [ `whoami` = root ]; then
							sudo -u $TS_USER $TSDIR/srv$2/srv$2
							echo "Teamspeak started..."
								if [ -e $TSDIR/srv$2/af/flood$2 ]; then
									echo "... checking for Anti-Flood Daemon"
									if [ -x $TSDIR/srv$2/af/flood$2 ]; then
										sudo -u $TS_USER $TSDIR/srv$2/af/flood$2 start
										sleep 5
											if [ -e $TSDIR/srv$2/af/ts2afd.pid ]; then
												echo "Anti-Flood for srv$2 online"
												exit 0
											elif [ ! -e $TSDIR/srv$2/af/ts2afd.pid ]; then
												echo "Anti-Flood for srv$2 is NOT running"
												exit 1
											else
												echo "Error in start Anti-Flood for srv$2"
												exit 1
											fi
 
									else
										echo "Anti-Flood for srv$2 is not executable"
										exit 1
									fi
								else
									echo "Anti-Flood for srv$2 not installed."
										if [ `pidof srv$2` ]; then
											echo "Teamspeak srv$2 is running."
											exit 0
										else
											echo "Teamspeak srv$2 seems NOT running."
											exit 1
										fi
								fi
 
 
						elif [ `whoami` = $TS_USER ]; then
							$TSDIR/srv$2/srv$2
							echo "Teamspeak started..."
								if [ -e $TSDIR/srv$2/af/flood$2 ]; then
									echo "... checking for Anti-Flood Daemon"
									if [ -x $TSDIR/srv$2/af/flood$2 ]; then
										$TSDIR/srv$2/af/flood$2 start
										sleep 5
											if [ `pidof ts2af$2.pl` ]; then
												echo "Anti-Flood for srv$2 online"
												exit 0
											elif [ ! `pidof ts2af$2.pl` ]; then
												echo "Couldnt find Anti-Flood for srv$2"
												exit 1
											else
												echo "Error in start Anti-Flood for srv$2"
												exit 1
											fi
 
									else
										echo "Anti-Flood for srv$2 is not executable"
										exit 1
									fi
								else
									echo "Anti-Flood for srv$2 not installed."
										if [ `pidof srv$2` ]; then
											echo "Teamspeak srv$2 is running."
											exit 0
										else
											echo "Teamspeak flood$2 seems NOT running."
											exit 1
										fi
								fi
						fi
 
				$INIT status $2
 
			elif [ "${?}" = "2" ]; then
				echo "EE> status exit-code 2"
			elif [ "${?}" = "3" ]; then
				echo "EE> status exit-code 3"
			elif [ "${?}" = "4" ]; then
				echo "EE> status exit-code 4"
			elif [ "${?}" = "5" ]; then
				echo "EE> PIDFILE differs from running PID, killing..."
				killall -9 srv$2; sleep 3; killall -9 srv$2;
								echo "II> PIDFILE differs from running PID, killing..."
 
			else
				echo "II> Exit-Code not found"
			fi
 
	elif [ "$2" = "all" ]; then
			case "$3" in
			*)
				echo "II> Stopping $3 Servers."
				echo "II> Case = $3"
				for (( I=1; $I <= $3; I++ ))
		       		do
				 	$INIT stop $I; echo "";
					$INIT status $I; echo "";
				done;								
			;;
			esac 
 
	else 
		echo "EE> Error in start Case 2"
		exit 1
	fi
	;;
	esac
 
else 
	echo "EE> started with wrong user. you are `whoami`"
	exit 1
fi 
;;
 
 
 
stop)
sysVARS
if [ $(whoami) = "root" ] || [ $(whoami) = "$TS_USER" ]; then
	case "$2" in
		*)
 
		if [ -z "$2" ]; then
			$INIT stop 1
 
		elif [ ! -z "$2" ]; then
			$INIT status $2 > /dev/null
			if [ "${?}" = "0" ]; then
				echo "II> srv$2 online, stopping... "
					if [ -x $TSDIR/srv$2/af/flood2 ]; then
						$TSDIR/srv$2/af/flood$2 stop
						sleep 1
					else
						echo "EE> Anti-Flood $TSDIR/srv$2/af/flood$2 not executable."
					fi
#################################### THX to pwk.linuxfan - START ######################################
                        if ( kill -TERM `pidof srv$2` ); then
                                for c in $(seq 1 300); do
                                        if [ `pidof srv$2` ]; then
                                                echo -n "."
                                                sleep 1
                                        fi
                                done
                        fi
                        if [ -e $TSDIR/srv$2/$serverPID ]; then
                                echo "II> server does not shutdown cleanly - killing"
                                kill -KILL `cat $TSDIR/srv$2/$serverPID`
                                rm -f $TSDIR/srv$2/$serverPID
                                sleep 5
                        else
                                echo "II> done"
                        fi
#################################### THX to pwk.linuxfan - END ######################################
 
			elif [ "${?}" = "1" ]; then
				echo "II> srv$2 already offline."
 
 
			elif [ "${?}" = "2" ]; then
				echo "II> srv$2 already offline."
 
 
			elif [ "${?}" = "3" ]; then
				echo "II> srv$2 already offline."
 
 
			elif [ "${?}" = "4" ]; then
				echo "II> srv$2 already offline."
 
 
			elif [ "${?}" = "5" ]; then
 
			PIDOF=`pidof srv$2`
			echo "EE> srv$2 seems running {$PIDOF}, but no pidfile found."
				if ( kill -TERM `$PIDOF` ); then
					for c in $(seq 1 300); do
						if [ `pidof srv$2` ]; then
                                                echo -n "."
                                                sleep 1
						fi
					done
	       		fi
                        	if [ `pidof srv$2` ]; then
                                echo "EE> server does not shutdown cleanly - killing"
                                kill -KILL `$PIDOF`
                                sleep 5
                        	else
                                echo "II> done"
                        	fi				
			else
			echo "EE> Exit-Code not found"
			fi
		else
			echo "EE> Error in stop Case 2" 
			exit 1
		fi
	;;
	esac
else 
	echo "EE> started with wrong user. you are `whoami`"
	exit 1
fi 
;;
 
 
 
TSinstall)
sysVARS
if [ $(whoami) = "root" ]; then
	case "$2" in
		*)
		if [ -z "$2" ]; then
			echo "II> using standard: srv1"
			$INIT doTSinstall 1
			exit 0
		else 
			echo "II> Installing srv$2"
			$INIT doTSinstall $2
			exit 0
		fi
	;;
	esac
else 
	echo "EE> started with wrong user. you are `whoami`"
	exit 1
fi 
;;
 
 
doTSinstall)
sysVARS
if [ $(whoami) = "root" ]; then
	case "$2" in
		*)
		if [ $(whoami) = "root" ]; then
			echo "II> "
			echo "II> You are about to install a Teamspeak2-Server. Please read the license first."
			echo "II> "
			echo "II> Get the license on the internet at http://www.teamspeak.com/?page=license"
			echo "II> "
			#sleep 10
			echo "II> Please read the license before continuing...."
			#sleep 15 
			echo "II> Do you accept the license and toc? Enter Yes/No"
	  			read -t 10 wantinstall
 
				if [ ! -z "$wantinstall" ]; then					
					if [ $wantinstall = y ] || [ $wantinstall = yes ] || [ $wantinstall = Yes ] ; then	
						echo "II> Installation in progress..."
						if [ `which bzip2` ]; then
							echo "II> Creating User { $TS_USER }"
								useradd -m $TS_USER; mkdir -p $TSDIR;
								rm -fR $TSDIR/tmp; mkdir -p $TSDIR/tmp								  
 
									cd $TSDIR/tmp
									if [ ! -e $TSDIR/srv$2 ]; then										
 
										echo -n "Installed Teamspeak-Version: "
											if [ -e $TSDIR/srv$2 ]; then
												echo "II> ERROR srv$2 already exists, can not install."; echo "II> Use another instance-number or uninstall srv$2";
												exit 1
											else
												wget -c $ftpurl/$ts2server_archive -O $TSDIR/tmp/$ts2server_archive -o /dev/null											 
												 tar xjf $TSDIR/tmp/$ts2server_archive
												  echo "II> archive unpacked, downloading patch"
												   wget -c $patchurl/$ts2server_patch -O $TSDIR/tmp/$ts2server_patch -o /dev/null
												    mv $TSDIR/tmp/$ts2server_patch $TSDIR/tmp/tss2_rc2
												     chmod u+x $TSDIR/tmp/tss2_rc2/$ts2server_patch
												      mkdir -p $TSDIR/srv$2
												       mv $TSDIR/tmp/tss2_rc2/* $TSDIR/srv$2
												        $TSDIR/srv$2/$ts2server_patch --help | head -n 1 | cut -d" " -f 3
												          mv $TSDIR/srv$2/$ts2server_patch $TSDIR/srv$2/srv$2
														chown -R $TS_USER:$TS_USER $TSDIR
														 $INIT enable $2
												 echo "II> Setup is complete. Teamspeak2 srv$2 is ready to start."
												 echo "II> Start srv$2 with the following command: $INIT start $2"
												exit 0
											fi							
									else
										echo "EE> Error : srv$2 already exists... aborting"
										exit 1
									fi
						else
							echo "EE> Error: Can not unpack archive. Missing package bzip2"
							echo "EE> Solution: install bzip2 and retry."
							echo "EE> Debian / Ubuntu : apt-get install bzip2"
							exit 1
						fi			
 
 
					else 
						echo "EE> ...aborting setup"
						exit 1
					fi
 
				elif [ -z "$2" ]; then
					echo "EE> ...aborting setup"
					exit 1
				fi
 
 
 
		else 
			echo "EE> Please run the installer as root. you are `whoami`"
			exit 1
		fi 
 
 
	;;
	esac
 
else 
	echo "EE> Please run the installer as root. you are `whoami`"
	exit 1
fi 
;;
 
TSuninstall)
sysVARS
if [ $(whoami) = "root" ] || [ $(whoami) = "$TS_USER" ]; then
	case "$2" in
		*)
		if [ -z "$2" ]; then
			echo "II> using standard: srv1"
			$INIT doTSuninstall 1
			exit 0
		else 
			echo "II> UNINSTALL srv$2"
			$INIT doTSuninstall $2
			exit 0
		fi
	esac
else 
	echo "II> you are not root. you are `whoami`"
	exit 1
fi 
;;
 
 
doTSuninstall)
sysVARS
if [ $(whoami) = "root" ] || [ $(whoami) = "$TS_USER" ]; then
	case "$2" in
		*)
		if [ -z "$2" ]; then
			$INIT doTSuninstall 1
		elif [ ! -z "$2" ]; then	
				if [ $(whoami) = "root" ]; then
					echo "II> Uninstalling srv$2."
					echo "??> Delete {user:$TS_USER} {home-directory:$TSDIR} with ALL files ??"
					echo "??> Yes: delete all installed TS-Servers."
					echo "??> No: delete only srv$2, not home-directory."
					echo "??> Stop: stop uninstall."
					echo -n "@@> Please enter Yes/No/Stop: > "
						read -t 10 DelHome
						echo ""
						if [ -z "$DelHome" ]; then	
							echo "EE> ...aborting uninstall."
						elif [ ! -z "$DelHome" ]; then	
							if [ $DelHome = y ] || [ $DelHome = yes ] || [ $DelHome = Yes ]; then
								echo "II> Do you really want to delete everything in $TSDIR ?"
									read -t 10 UnAll
									if [ $UnAll = y ] || [ $UnAll = yes ] || [ $UnAll = Yes ]; then
										userdel -r $TS_USER
										echo "II> Home-Directory $TSDIR deleted."
										echo "II> Teamspeak uninstalled."
										exit 0
									else
										echo "EE> ...aborting uninstall"
										exit 1
									fi
							elif [ $DelHome = n ] || [ $DelHome = no ] || [ $DelHome = No ]; then
								echo "II> Home-Directory $TSDIR NOT deleted."
								rm -rf $TSDIR/srv$2
								echo "II> Teamspeak2 srv$2 succesfully uninstalled."
							elif [ $DelHome = s ] || [ $DelHome = stop ] || [ $DelHome = Stop ]; then
								echo "EE> ...aborting uninstall"
							fi	
						else 
							echo "EE> Error in doTSuninstall DelHome"
						fi
 
 
				else
					echo "EE> ...aborting uninstall"
				fi
		else 
			echo "EE>  Case 2 Error"					
		fi
		;;
		esac
 
 
else 
 echo "EE> you are not root. you are `whoami`"
 exit 1
fi 
;;
 
 
AFinstall)
sysVARS
if [ $(whoami) = "root" ] || [ $(whoami) = "$TS_USER" ]; then
	case "$2" in
		*)
		if [ -z "$2" ]; then
			echo "II> No instance found, installing srv1"
			$INIT doAFinstall 1
			exit 0
		else 
			echo "II> Installing srv$2"
			$INIT doAFinstall $2
			exit 0
		fi
 
	;;
	esac	
else 
	echo "EE> you are not root. you are `whoami`"
	exit 1
fi 
;;
 
 
doAFinstall)
sysVARS
if [ $(whoami) = "root" ] || [ $(whoami) = "$TS_USER" ]; then
	case "$2" in
		*)
		if [ $(whoami) = "root" ]; then
			if [ ! -e $TSDIR/srv$2 ]; then
				echo "II> Can not install Anti-Flood on srv$2, it is not installed."
			else
				if [ ! -e $TSDIR/srv$2/af/ ]; then
					if [ `which unzip` ]; then
						mkdir -p $TSDIR/srv$2/af
						wget $AFurl/$AFarchive -O $TSDIR/srv$2/af/$AFarchive -o /dev/null
						cd $TSDIR/srv$2/af/; unzip $AFarchive > /dev/null; 
						mv $TSDIR/srv$2/af/ts2afd.pl $TSDIR/srv$2/af/ts2afd$2.pl
						ln -s $TSDIR/srv$2/af/ts2afd$2.pl $TSDIR/srv$2/af/ts2afd.pl
						mv $TSDIR/srv$2/af/ts2afd_startscript $TSDIR/srv$2/af/ts2afd$2
						chmod u+x $TSDIR/srv$2/af/ts2afd$2.pl $TSDIR/srv$2/af/ts2afd_srv$2
						chown -R $TS_USER:$TS_USER $TSDIR
						echo "II> TS Anti-Flood Daemon installed on srv$2."
						exit 0
					else
						echo "II> Can not unpack archive. Unzip not found."
						echo "II> Debian / Ubuntu: apt-get install unzip"
						exit 1
					fi
 
				else				
					echo "EE> Anti-Flood on srv$2 already installed... aborting"
					exit 1
				fi
			fi
 
 
 
 
 
 
		else
			echo "EE> Please install Anti-Flood Daemon as root"
			exit 1
		fi
 
	;;
	esac
else 
	echo "EE> started with wrong user. must to be root, but you are `whoami`"
	exit 1
fi 
;;
 
 
AFuninstall)
sysVARS
if [ $(whoami) = "root" ] || [ $(whoami) = "$TS_USER" ]; then
	case "$2" in
		*)
		if [ -z "$2" ]; then
			echo "II> UNINSTALL Anti-Flood from srv1"
			$INIT doAFuninstall 1
			exit 0
		else 
			echo "II> UNINSTALL Anti-Flood from srv$2"
			$INIT doAFuninstall $2
			exit 0
		fi
	;;
	esac
else 
	echo "EE> started with wrong user. you are `whoami`"
	exit 1
fi 
;;
 
 
doAFuninstall)
sysVARS
if [ $(whoami) = "root" ] || [ $(whoami) = "$TS_USER" ]; then
	case "$2" in
		*)
		if [ $(whoami) = "root" ]; then
			echo "II>  Uninstalling Anti-Flood from srv$2."
			rm -rf $TSDIR/srv$2/af
			echo "II>  AF from srv$2 uninstalled."
		else
			echo "EE>  ..aborting uninstall"
		fi
 
	;;
	esac
else 
	echo "EE> started with wrong user. you are `whoami`"
	exit 1
fi 
;;
 
 
 
requirements)
sysVARS
	echo "II> Checking requirements"
 
	  	if [ `which sudo` ]; then
			echo "II> sudo OK... " 
		else
			echo "EE> sudo NOT found... please fix it first."
			exit 1
		fi
 
	  	if [ `which pidof` ]; then
			echo "II> pidof OK... " 
		else
			echo "EE> pidof NOT found... please fix it first."
			exit 1
		fi
 
	  	if [ `which kill` ]; then
			echo "II> kill OK... " 
		else
			echo "EE> kill NOT found... please fix it first."
			exit 1
		fi
 
	  	if [ `which killall` ]; then
			echo "II> killall OK... " 
		else
			echo "EE> killall NOT found... please fix it first."
			exit 1
		fi
 
	  	if [ `which bzip2` ]; then
			echo "II> bzip2 OK... " 
		else
			echo "EE> bzip2 NOT found... please fix it first."
			exit 1
		fi
 
		if [ `which unzip` ]; then
			echo "II> unzip OK... " 
		else
			echo "EE> unzip NOT found... please fix it first."
			exit 1		
		fi
 
		if [ `which whoami` ]; then
			echo "II> whoami OK... " 
		else
			echo "EE> whoami NOT found... please fix it first."
			exit 1	
		fi
 
		if [ $(whoami) = "root" ]; then
			echo "II> you are root OK..."
		else
			echo "EE> you are NOT root..."
		fi
 
		if [ `which wine` ]; then
			echo "II> wine OK..."
		else
			echo "EE> wine NOT found... you wont be able to start 2xTS-Bot"
		fi
 
		echo "II> Systemcheck passed"
 
;;
 
 
 
restart)
sysVARS
$INIT stop $2
sleep 3
$INIT start $2
;;
 
*)
echo "Teamspeak2-Server INIT-Script"
echo "Usage: $0 {start|status|stop|enable|disable|TSinstall|TSuninstall|AFinstall|AFuninstall}"
exit 1
;;
esac
 
exit 0

Powered by WordPress

SEO Powered by Platinum SEO from Techblissonline