88 lines
2.0 KiB
Bash
88 lines
2.0 KiB
Bash
#!/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 |