Gamer-Server-Utility-Scripts/Teamspeak/update.sh

75 lines
1.9 KiB
Bash
Raw Permalink Normal View History

2024-02-08 14:06:36 -05:00
#!/bin/bash
# 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
2024-02-08 14:06:36 -05:00
PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin
TS_DIR=/home/teamspeak/
# FUNCTIONS
2024-02-08 14:06:36 -05:00
get_versions() {
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"
2024-02-08 14:06:36 -05:00
local_version=$(grep -Eom1 'Server Release \S*' "CHANGELOG" | cut -b 16-)
echo "$local_version"
2024-02-08 14:06:36 -05:00
}
download() {
wget "https://files.teamspeak-services.com/releases/server/$remote_version/teamspeak3-server_linux_amd64-$remote_version.tar.bz2" -O TS.tar.bz2
2024-02-08 14:06:36 -05:00
}
db_backup() {
mkdir -p "$TS_DIR/TS_Update/db_backup"
cp "$TS_DIR/ts3server.sqlitedb" "$TS_DIR/TS_Update/db_backup/"
2024-02-08 14:06:36 -05:00
}
extract() {
mkdir -p temp
2024-02-08 14:06:36 -05:00
tar xf TS.tar.bz2 -C temp/
}
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')"
2024-02-08 14:06:36 -05:00
sleep 15
screen -X -S teamspeak quit
}
clean_up() {
rm -rf temp/ TS.tar.bz2
chown -R teamspeak:teamspeak "$TS_DIR"
2024-02-08 14:06:36 -05:00
}
start_ts() {
cd "$TS_DIR"
2024-02-08 14:06:36 -05:00
screen -dmS teamspeak ./teamspeak.sh
}
# MAIN SCRIPT
2024-02-08 14:06:36 -05:00
get_versions
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
2024-02-08 14:06:36 -05:00
fi
exit 0