Skip to content

Commit c4fa63e

Browse files
committed
don't (re)start server if it was stopped before running the script
1 parent a41d45b commit c4fa63e

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

ts3updater.sh

+16-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22
# Script Name: ts3updater.sh
33
# Author: eminga
4-
# Version: 1.5
4+
# Version: 1.6
55
# Description: Installs and updates TeamSpeak 3 servers
66
# License: MIT License
77

@@ -12,11 +12,11 @@ if ! command -v curl > /dev/null 2>&1; then
1212
echo 'curl not found' 1>&2
1313
exit 1
1414
elif ! command -v jq > /dev/null 2>&1; then
15-
echo 'jq not found' 1>&2
16-
exit 1
15+
echo 'jq not found' 1>&2
16+
exit 1
1717
elif ! command -v tar > /dev/null 2>&1; then
18-
echo 'tar not found' 1>&2
19-
exit 1
18+
echo 'tar not found' 1>&2
19+
exit 1
2020
fi
2121

2222
# determine os and cpu architecture
@@ -41,9 +41,10 @@ else
4141
fi
4242
fi
4343

44-
44+
# download JSON file which provides information on server versions and checksums
4545
server=$(curl -Ls 'https://www.teamspeak.com/versions/server.json' | jq "$jqfilter")
4646

47+
# determine installed version by parsing the most recent entry of the CHANGELOG file
4748
if [ -e 'CHANGELOG' ]; then
4849
old_version=$(grep -Eom1 'Server Release \S*' "CHANGELOG" | cut -b 16-)
4950
else
@@ -93,6 +94,7 @@ if [ "$old_version" != "$version" ]; then
9394
if [ "$checksum" = "$sha256" ]; then
9495
tsdir=$(tar -tf "$tmpfile" | grep -m1 /)
9596
if [ ! -e '.ts3server_license_accepted' ]; then
97+
# display server license
9698
tar --to-stdout -xf "$tmpfile" "$tsdir"LICENSE
9799
echo -n "Accept license agreement (y/N)? "
98100
read answer
@@ -102,15 +104,21 @@ if [ "$old_version" != "$version" ]; then
102104
fi
103105
fi
104106
if [ -e 'ts3server_startscript.sh' ]; then
105-
./ts3server_startscript.sh stop
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
106113
else
107114
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; }
108115
cd "$tsdir" && mv ../"$(basename "$0")" .
109116
fi
110117

118+
# extract the archive into the installation directory and overwrite existing files
111119
tar --strip-components 1 -xf "$tmpfile" "$tsdir"
112120
touch .ts3server_license_accepted
113-
if [ "$1" != '--dont-start' ]; then
121+
if [ "$1" != '--dont-start' ] && [ "$server_stopped" != true ]; then
114122
./ts3server_startscript.sh start "$@"
115123
fi
116124
else

0 commit comments

Comments
 (0)