#!/usr/bin/zsh
if [ -z $1 ];then
echo specify command. Valid commands are: binupdate, disable, disableall, enable, enableall, log, logcat, new, probinupdate, remove, restart, restartall, start, startall, stop, stopall
exit 1
fi
case "$1" in
binupdate)
if which lynx > /dev/null 2>/dev/null;then
sleep .01
else
echo please install lynx package
exit 2
fi
if id -u|grep -qw 0;then
export mydistro=ubuntu22
export dirurl=`lynx --listonly --nonumbers --dump https://bearware.dk/teamtalk|grep v|sort -V|tail -n 1`
export url=`lynx --listonly --nonumbers --dump $dirurl|sed /teamtalkpro/d|grep $mydistro|grep tgz|tail -n 1`
export dirname=`basename $url|sed "s|[.]tgz||g"`
cd /usr/bin
curl $url|tar --strip-components=2 -xz $dirname/server/tt5srv
else
echo please run binary updates as root by running: sudo $0 binupdate
fi
;;
disable)
if [ -z $2 ];then
echo specify server name to opperate on. 
exit 1
fi
systemctl disable tt5@$2
;;
disableall)
for f in `ls /home/tt/*.xml|sed "s|\/home\/tt\/||g"|cut -f 1 -d .`;do
tt disable $f
done
;;
enable)
if [ -z $2 ];then
echo specify server name to opperate on. 
exit 1
fi
systemctl enable tt5@$2
;;
enableall)
for f in `ls /home/tt/*.xml|sed "s|\/home\/tt\/||g"|cut -f 1 -d .`;do
tt enable $f
done
;;
log)
if [ -z $2 ];then
echo specify server name to opperate on. 
exit 1
fi
journalctl --full --no-pager -r -u tt5@$2.service
;;
logcat)
if [ -z $2 ];then
echo specify server name to opperate on. 
exit 1
fi
journalctl --full --no-pager -o cat -r -u tt5@$2.service
;;
new)
if [ -z $2 ];then
echo specify server name to opperate on. 
exit 1
fi
mkdir -p /home/tt/files.$2
tt5srv -c /home/tt/$2.xml -wizard
chown -R tt:tt /home/tt
echo start this server on boot\? y/n
read bootanswer
if [ $bootanswer = "y" ];then
systemctl enable tt5@$2
fi
echo start this server now\? y/n
read startanswer
if [ $startanswer = "y" ];then
systemctl --no-block start tt5@$2
fi
;;
probinupdate)
if which lynx > /dev/null 2>/dev/null;then
sleep .01
else
echo please install lynx package
exit 2
fi
if id -u|grep -qw 0;then
export mydistro=ubuntu22
export dirurl=`lynx --listonly --nonumbers --dump https://bearware.dk/teamtalk|grep v|sort -V|tail -n 1`
export url=`lynx --listonly --nonumbers --dump $dirurl|grep $mydistro|grep teamtalkpro|grep tgz|tail -n 1`
export dirname=`basename $url|sed "s|[.]tgz||g"`
cd /usr/bin
curl $url|tar --strip-components=2 -xz $dirname/server/tt5prosrv
mv tt5prosrv tt5srv
else
echo please run binary updates as root by running: sudo $0 binupdate
fi
;;
remove)
if [ -z $2 ];then
echo specify server name to opperate on. 
exit 1
fi
systemctl --no-block stop tt5@$2
systemctl disable tt5@$2
rm -rf /home/tt/$2.xml  /home/tt/files.$2
;;
restart)
if [ -z $2 ];then
echo specify server name to opperate on. 
exit 1
fi
systemctl --no-block restart tt5@$2
;;
restartall)
for f in `ls /home/tt/*.xml|sed "s|\/home\/tt\/||g"|cut -f 1 -d .`;do
tt restart $f
done
;;
start)
if [ -z $2 ];then
echo specify server name to opperate on. 
exit 1
fi
systemctl --no-block start tt5@$2
;;
startall)
for f in `ls /home/tt/*.xml|sed "s|\/home\/tt\/||g"|cut -f 1 -d .`;do
tt start $f
done
;;
stop)
if [ -z $2 ];then
echo specify server name to opperate on. 
exit 1
fi
systemctl --no-block stop tt5@$2
;;
stopall)
for f in `ls /home/tt/*.xml|sed "s|\/home\/tt\/||g"|cut -f 1 -d .`;do
tt stop $f
done
;;
*)
echo specify a valid command. Valid commands are: binupdate, disable, disableall, enable, enableall, log, logcat, new, probinupdate, remove, restart, restartall, start, startall, stop, stopall
exit 1
;;
esac
if which tt5srv > /dev/null 2>/dev/null;then
sleep .01
else
$0 binupdate
$0 $@
fi
