Add Teamspeak/update.sh

This commit is contained in:
Clarth 2024-02-08 14:06:36 -05:00
parent 01d48e8408
commit 2ece9d1bf5
1 changed files with 88 additions and 0 deletions

88
Teamspeak/update.sh Normal file
View File

@ -0,0 +1,88 @@
#!/bin/bash
#Custom TS update script. There are 'better' update scripts out there.
##########################
# Requires jq #
# sudo apt install jq -y #
##########################
####################################### VARIABLES #####################################
PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin
tsdir=/home/teamspeak/
#################################### FUNCTIONS ##################################
get_versions() {
server=$(curl -Ls 'https://www.teamspeak.com/versions/server.json' | jq ".linux.x86_64")
remote_version=$(printf '%s' "$server" | jq -r '.version')
echo $remote_version
local_version=$(grep -Eom1 'Server Release \S*' "CHANGELOG" | cut -b 16-)
echo $local_version
}
download() {
wget https://files.teamspeak-services.com/releases/server/$remote_version/teamspeak3-server_linux_amd64-$remote_version.tar.bz2 -O TS.tar.bz2
}
db_backup(){
mkdir $tsdir/TS_Update/db_backup
cp $tsdir/ts3server.sqlitedb $tsdir/TS_Update/db_backup/
}
extract(){
mkdir temp
tar xf TS.tar.bz2 -C temp/
}
move(){
cp -rf temp/teamspeak3-server_linux_amd64/* $tsdir
}
stop_ts(){
echo "Waiting for Teamspeak to save."
screen -p 0 -S teamspeak -X eval "stuff serverprocessstop\015"
screen -S teamspeak -p 0 -X stuff "serverprocessstop^M"
sleep 15
screen -X -S teamspeak quit
}
clean_up(){
rm -rf temp/
chown -R teamspeak:teamspeak $tsdir
rm -f TS.tar.bz2
}
start_ts(){
cd $tsdir
screen -dmS teamspeak ./teamspeak.sh
}
############################################################# RUN IT ! ##########################################
get_versions
if [ $remote_version = $local_version ];
then
echo "No update needed!" && exit 0
else
echo
echo "Update required"
echo
sleep 0.5
echo
echo "Starting Update"
echo
download
stop_ts
extract
move
clean_up
start_ts
fi
exit