Update Teamspeak/update.sh

Added AI recommended changes.
This commit is contained in:
Clarth 2024-02-08 14:08:54 -05:00
parent 2ece9d1bf5
commit c1efe61711
1 changed files with 57 additions and 70 deletions

View File

@ -1,88 +1,75 @@
#!/bin/bash
#Custom TS update script. There are 'better' update scripts out there.
##########################
# Requires jq #
# sudo apt install jq -y #
##########################
####################################### VARIABLES #####################################
# Custom TS update script. There are 'better' update scripts out there.
# Ensure required commands are available
command -v jq >/dev/null 2>&1 || { echo >&2 "jq is required but it's not installed. Aborting."; exit 1; }
command -v curl >/dev/null 2>&1 || { echo >&2 "curl is required but it's not installed. Aborting."; exit 1; }
command -v wget >/dev/null 2>&1 || { echo >&2 "wget is required but it's not installed. Aborting."; exit 1; }
# VARIABLES
PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin
tsdir=/home/teamspeak/
#################################### FUNCTIONS ##################################
TS_DIR=/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
server_info=$(curl -Ls 'https://www.teamspeak.com/versions/server.json' | jq -r '.linux.x86_64')
remote_version=$(jq -r '.version' <<< "$server_info")
echo "$remote_version"
local_version=$(grep -Eom1 'Server Release \S*' "CHANGELOG" | cut -b 16-)
echo $local_version
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
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/
db_backup() {
mkdir -p "$TS_DIR/TS_Update/db_backup"
cp "$TS_DIR/ts3server.sqlitedb" "$TS_DIR/TS_Update/db_backup/"
}
extract(){
mkdir temp
extract() {
mkdir -p 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"
}
move() {
cp -rf temp/teamspeak3-server_linux_amd64/* "$TS_DIR"
}
stop_ts() {
echo "Stopping Teamspeak server."
screen -p 0 -S teamspeak -X stuff "serverprocessstop$(printf '\r')"
sleep 15
screen -X -S teamspeak quit
}
clean_up(){
rm -rf temp/
chown -R teamspeak:teamspeak $tsdir
rm -f TS.tar.bz2
clean_up() {
rm -rf temp/ TS.tar.bz2
chown -R teamspeak:teamspeak "$TS_DIR"
}
start_ts(){
cd $tsdir
start_ts() {
cd "$TS_DIR"
screen -dmS teamspeak ./teamspeak.sh
}
############################################################# RUN IT ! ##########################################
# MAIN SCRIPT
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
if [ "$remote_version" = "$local_version" ]; then
echo "No update needed!"
exit 0
else
echo "Update required"
echo "Starting update"
download
stop_ts
extract
move
clean_up
start_ts
fi
exit
exit 0