#!/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 PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin TS_DIR=/home/teamspeak/ # FUNCTIONS 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" 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 -p "$TS_DIR/TS_Update/db_backup" cp "$TS_DIR/ts3server.sqlitedb" "$TS_DIR/TS_Update/db_backup/" } extract() { mkdir -p temp 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')" sleep 15 screen -X -S teamspeak quit } clean_up() { rm -rf temp/ TS.tar.bz2 chown -R teamspeak:teamspeak "$TS_DIR" } start_ts() { cd "$TS_DIR" screen -dmS teamspeak ./teamspeak.sh } # MAIN SCRIPT 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 fi exit 0