Last active
June 21, 2019 10:31
-
-
Save razaqq/42c604268ed7023fcf854664a6ab3004 to your computer and use it in GitHub Desktop.
an update script for teaspeak
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# config | |
query_port=10102 | |
query_user=user | |
query_pass=pass | |
warning_secs=180 | |
warning_interval=30 | |
# the user which runs the server, used for fixing permissions | |
teaspeak_user=teaspeak | |
teaspeak_group=teaspeak | |
# connect | |
exec 8<>/dev/tcp/localhost/$query_port | |
printf "login $query_user $query_pass\r\n" >&8 | |
# run hostinfo and transform data into asso. array | |
declare -A hostinfo | |
while read -r -t 1 -u 8 REPLY; do :; done | |
printf "hostinfo\r\n" >&8 | |
read -r -t 1 -u 8 REPLY | |
for data in $REPLY; do | |
set -- `echo $data | tr '=' ' '` | |
hostinfo[$1]=$2 | |
done | |
servers=${hostinfo[virtualservers_running_total]} | |
clients=${hostinfo[virtualservers_total_clients_online]} | |
echo "# ------------------------------------------------" | |
# check version and ask for update | |
echo "# Getting version..." | |
if [ `getconf LONG_BIT` = "64" ] | |
then | |
version=$(curl -s -S -k https://repo.teaspeak.de/server/linux/amd64_stable/latest) | |
else | |
version=$(curl -s -S -k https://repo.teaspeak.de/server/linux/x86_stable/latest) | |
fi | |
IFS=' ' read -ra installedversion <<< $(head -1 buildVersion.txt) | |
echo "# Installed version is : '${installedversion[2]}'" | |
echo "# Newest version is : '${version}'" | |
if [ "$version" == "${installedversion[2]}" ] | |
then | |
printf "logout\r\n" >&8 | |
printf "exit\r\n" >&8 | |
echo "# Already up to date!" | |
exit 0 | |
else | |
echo "# Currently there are $clients clients connected on $servers servers" | |
echo -n "# Update required. Would you like to update now? (y/n)" | |
read answer | |
if [ "$answer" != "${answer#[Nn]}" ] | |
then | |
printf "logout\r\n" >&8 | |
printf "exit\r\n" >&8 | |
echo "# Exiting..." | |
exit 0 | |
fi | |
fi | |
echo "# ------------------------------------------------" | |
# count down and notify clients of upcoming restart | |
echo -n "# Would you like to give the clients a $warning_secs seconds warning? (y/n)" | |
read answer | |
if [ "$answer" != "${answer#[Yy]}" ] | |
then | |
printf "gm msg=Server\swill\srestart\sfor\san\supdate\ssoon.\sWont\stake\slong!\r\n" >&8 | |
for ((i=$warning_secs;i>0;i=i-$warning_interval)); do | |
echo -n "$i." | |
printf "gm msg=Server\srestart\sin\s$i\sseconds!\r\n" >&8 | |
sleep $warning_interval | |
done | |
fi | |
echo -e "\n# ------------------------------------------------" | |
# stop the server | |
printf "serverprocessstop type=schedule time=0 msg=Stopping\sServer!\r\n" >&8 | |
# update | |
echo "# Starting update..." | |
if [ `getconf LONG_BIT` = "64" ] | |
then | |
echo "# Detected an 64 bit environment" | |
requesturl="https://repo.teaspeak.de/server/linux/amd64_stable/TeaSpeak-${version}.tar.gz" | |
else | |
echo "# Detected an 32 bit environment" | |
requesturl="https://repo.teaspeak.de/server/linux/x86_stable/TeaSpeak-${version}.tar.gz" | |
fi | |
echo "# Downloading ${requesturl}" | |
curl -s -S "$requesturl" -o updatefile.tar.gz | |
echo "# Backing up config and database" | |
cp config.yml config.yml.old | |
cp TeaData.sqlite TeaData.sqlite.old | |
echo "# Unpacking and removing .tar.gz" | |
tar -xzf updatefile.tar.gz | |
rm updatefile.tar.gz | |
echo "# Making scripts executable" | |
chmod u+x *.sh | |
echo "# TeaSpeak should be now updated to ${version}" | |
echo "# ------------------------------------------------" | |
echo "# Setting permissions of the entire folder back to ${teaspeak_user}" | |
chown -R ${teaspeak_user}:${teaspeak_group} ./* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment