├── LICENSE ├── README.md └── ts3updater.sh /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 eminga 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TeamSpeak 3 Server Installer and Updater 2 | A lightweight script to install or update a TeamSpeak 3 server on Linux or FreeBSD. Should also work on macOS (currently untested). 3 | 4 | ## Dependencies 5 | * **jq** 1.4 or newer (https://stedolan.github.io/jq/download/) 6 | * curl 7 | * shasum, sha256, or sha256sum 8 | * tar 9 | * bzip2 10 | 11 | All other dependencies (basename, cd, command, cut, dirname, echo, grep, mktemp, printf, read, sed, test, touch, uname, wc, and an sh-compatible shell) are installed by default on most systems. 12 | 13 | ## How to use 14 | ### Install a new TeamSpeak 3 server 15 | Place the script where you want to install the TS server, make it executable with `chmod +x ts3updater.sh` and run it with `./ts3updater.sh`. After the installation, the script moves itself into the installation folder. Run it from there whenever you want to update the server. 16 | 17 | ### Update an existing TeamSpeak 3 server installation 18 | Place the script in the directory of your existing TS installation. This means, the script has to be in the same directory as for example the file `ts3server_startscript.sh`. Make it executable with `chmod +x ts3updater.sh` and run it with `./ts3updater.sh`. 19 | 20 | If you use TSDNS, make sure the service is stopped before you execute this script. 21 | 22 | ### Update the server automatically 23 | As the server is only updated if a new version is available, you can also use the script to automate updates. Simply create a cronjob which executes the script for instance hourly or daily. 24 | A crontab entry to run ts3updater daily at 13:28 could look like this: `28 13 * * * /home/ts/teamspeak3-server_linux_amd64/ts3updater.sh`. Append ` >/dev/null 2>&1` if you don't want to get a mail each time the script is run. 25 | 26 | You must accept the server license agreement before you create the cronjob. To do so, go to the directory of your TS installation, read the file `LICENSE` and create a file called `.ts3server_license_accepted`. 27 | 28 | ### Commandline parameters 29 | All parameters are passed to `ts3server_startscript.sh` when the server is started. If you don't want to start the server after installing or updating, use the parameter `--dont-start`. 30 | 31 | ## What this script is doing 32 | 1. Determine the OS and CPU architecture 33 | 2. Check if there is an existing installation and determine its version 34 | 3. Check for newer versions 35 | 4. If there is a newer version: 36 | 1. Download the new version 37 | 2. Check whether the checksum is correct 38 | 3. Stop the server 39 | 4. Extract the updated files into the server directory 40 | 5. Start the server 41 | -------------------------------------------------------------------------------- /ts3updater.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Script Name: ts3updater.sh 3 | # Author: eminga 4 | # Version: 1.6 5 | # Description: Installs and updates TeamSpeak 3 servers 6 | # License: MIT License 7 | 8 | cd "$(dirname "$0")" || exit 1 9 | 10 | # check whether the dependencies curl, jq, and tar are installed 11 | if ! command -v curl > /dev/null 2>&1; then 12 | echo 'curl not found' 1>&2 13 | exit 1 14 | elif ! command -v jq > /dev/null 2>&1; then 15 | echo 'jq not found' 1>&2 16 | exit 1 17 | elif ! command -v tar > /dev/null 2>&1; then 18 | echo 'tar not found' 1>&2 19 | exit 1 20 | fi 21 | 22 | # determine os and cpu architecture 23 | os=$(uname -s) 24 | if [ "$os" = 'Darwin' ]; then 25 | jqfilter='.macos' 26 | else 27 | if [ "$os" = 'Linux' ]; then 28 | jqfilter='.linux' 29 | elif [ "$os" = 'FreeBSD' ]; then 30 | jqfilter='.freebsd' 31 | else 32 | echo 'Could not detect operating system. If you run Linux, FreeBSD, or macOS and get this error, please open an issue on Github.' 1>&2 33 | exit 1 34 | fi 35 | 36 | architecture=$(uname -m) 37 | if [ "$architecture" = 'x86_64' ] || [ "$architecture" = 'amd64' ]; then 38 | jqfilter="${jqfilter}.x86_64" 39 | else 40 | jqfilter="${jqfilter}.x86" 41 | fi 42 | fi 43 | 44 | # download JSON file which provides information on server versions and checksums 45 | server=$(curl -Ls 'https://www.teamspeak.com/versions/server.json' | jq "$jqfilter") 46 | 47 | # determine installed version by parsing the most recent entry of the CHANGELOG file 48 | if [ -e 'CHANGELOG' ]; then 49 | old_version=$(grep -Eom1 'Server Release \S*' "CHANGELOG" | cut -b 16-) 50 | else 51 | old_version='-1' 52 | fi 53 | 54 | version=$(printf '%s' "$server" | jq -r '.version') 55 | 56 | if [ "$old_version" != "$version" ]; then 57 | echo "New version available: $version" 58 | checksum=$(printf '%s' "$server" | jq -r '.checksum') 59 | links=$(printf '%s' "$server" | jq -r '.mirrors | values[]') 60 | 61 | # order mirrors randomly 62 | if command -v shuf > /dev/null 2>&1; then 63 | links=$(printf '%s' "$links" | shuf) 64 | fi 65 | 66 | tmpfile=$(mktemp "${TMPDIR:-/tmp}/ts3updater.XXXXXXXXXX") 67 | i=1 68 | n=$(printf '%s\n' "$links" | wc -l) 69 | 70 | # try to download from mirrors until download is successful or all mirrors tried 71 | while [ "$i" -le "$n" ]; do 72 | link=$(printf '%s' "$links" | sed -n "$i"p) 73 | echo "Downloading the file $link" 74 | curl -Lo "$tmpfile" "$link" 75 | if [ $? = 0 ]; then 76 | i=$(( n + 1 )) 77 | else 78 | i=$(( i + 1 )) 79 | fi 80 | done 81 | 82 | if command -v sha256sum > /dev/null 2>&1; then 83 | sha256=$(sha256sum "$tmpfile" | cut -b 1-64) 84 | elif command -v shasum > /dev/null 2>&1; then 85 | sha256=$(shasum -a 256 "$tmpfile" | cut -b 1-64) 86 | elif command -v sha256 > /dev/null 2>&1; then 87 | sha256=$(sha256 -q "$tmpfile") 88 | else 89 | echo 'Could not generate SHA256 hash. Please make sure at least one of these commands is available: sha256sum, shasum, sha256' 1>&2 90 | rm "$tmpfile" 91 | exit 1 92 | fi 93 | 94 | if [ "$checksum" = "$sha256" ]; then 95 | tsdir=$(tar -tf "$tmpfile" | grep -m1 /) 96 | if [ ! -e '.ts3server_license_accepted' ]; then 97 | # display server license 98 | tar --to-stdout -xf "$tmpfile" "$tsdir"LICENSE 99 | echo -n "Accept license agreement (y/N)? " 100 | read answer 101 | if ! echo "$answer" | grep -iq "^y" ; then 102 | rm "$tmpfile" 103 | exit 1 104 | fi 105 | fi 106 | if [ -e 'ts3server_startscript.sh' ]; then 107 | # check if server is running 108 | if [ -e 'ts3server.pid' ]; then 109 | ./ts3server_startscript.sh stop 110 | else 111 | server_stopped=true 112 | fi 113 | else 114 | mkdir "$tsdir" || { echo 'Could not create installation directory. If you wanted to upgrade an existing installation, make sure to place this script INSIDE the existing installation directory.' 1>&2; rm "$tmpfile"; exit 1; } 115 | cd "$tsdir" && mv ../"$(basename "$0")" . 116 | fi 117 | 118 | # extract the archive into the installation directory and overwrite existing files 119 | tar --strip-components 1 -xf "$tmpfile" "$tsdir" 120 | touch .ts3server_license_accepted 121 | if [ "$1" != '--dont-start' ] && [ "$server_stopped" != true ]; then 122 | ./ts3server_startscript.sh start "$@" 123 | fi 124 | else 125 | echo 'Checksum of downloaded file is incorrect!' 1>&2 126 | rm "$tmpfile" 127 | exit 1 128 | fi 129 | 130 | rm "$tmpfile" 131 | else 132 | echo "The installed server is up-to-date. Version: $version" 133 | fi 134 | --------------------------------------------------------------------------------