summaryrefslogtreecommitdiff
path: root/server/debian/jessie/build
blob: ebf6e7dcff82a7bc7e6a721ccd981261bc6effda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
#!/bin/bash

# This is a script for packaging Teamspeak 3 Server into a .deb package.
# It is based on the aur package "teamspeak3-server" at 
# https://aur.archlinux.org/packages/teamspeak3-server.

# This script is intended for making Debian 8 packages ONLY and
# can be used on Debian 8.x or Arch Linux (provided that all
# dependencies are met, see INFO).

# Copyright (c) 2015, Mark Weiman <contact@markzz.com>
# 
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

# Get information about the operating system.
source /etc/os-release

# Check all passed arguments and set some booleans
for arg in $@; do
  if [ $arg == "--skip-os-check" ]; then
    _SKIPOSCHECK=true
  else
    _SKIPOSCHECK=false
  fi
  
  if [ $arg == "--skip-deps" ]; then
    _SKIPDEPS=true
  else
    _SKIPDEPS=false
  fi
done

server_version="3.0.11.3"

if [ ! $_SKIPOSCHECK ]; then
  if [ $ID == 'debian' ]; then
    if [ $VERSION_ID == '8' ]; then
      echo "Detected Debian 8 (jessie)"
    else
      echo "This script is only guarenteed to make packages for Debian 8."
      echo "If you wish to skip the operating system check (NOT RECOMMENDED),"
      echo "then pass --skip-os-check into the script."
      exit 1
    fi
  elif [ $ID == 'arch' ]; then
    echo "Detected Arch Linux"
  else
    echo "$NAME is not supported by this script."
    echo "If you wish to skip the operating system check (NOT RECOMMENDED),"
    echo "then pass --skip-os-check into the script."
    exit 1
  fi
fi

if [ ! $_SKIPDEPS ]; then
  echo "Checking dependencies for building package."
  echo
  
  if [ $ID == 'debian' ]; then
    echo "Checking if fakeroot is installed"
    command -v fakeroot >/dev/null 2>&1 && echo "fakeroot is installed" || { echo "Installing fakeroot with apt-get..."; sudo apt-get install fakeroot; }
    echo
  elif [ $ID == 'arch' ]; then
    echo "Checking if dpkg is installed"
    command -v dpkg >/dev/null 2>&1 && echo "dpkg is installed" || { echo "dpkg is not installed: Aborting!"; exit 2; }
    echo
    
    echo "Checking if fakeroot is installed"
    command -v fakeroot >/dev/null 2>&1 && echo "fakeroot is installed" || { echo "Installing fakeroot with pacman..."; sudo pacman -Sy fakeroot; }
    echo
  fi
fi

arch=`uname -m`
if [ $arch == "x86_64" ]; then
  _arch="amd64"
  _archname="amd64"
  echo "Detected $_archname"
  if [ -f "teamspeak3-server_linux-amd64-${server_version}.tar.gz" ]; then
    #cp ./teamspeak3-server_linux-amd64-3.0.11.3.tar.gz /tmp
    tar -xvzf teamspeak3-server_linux-amd64-${server_version}.tar.gz
    mv teamspeak3-server_linux-amd64 /tmp/teamspeak3
  fi
elif [ $arch == "i686" ]; then
  _arch="x86"
  _archname="i386"
  echo "Detected $_archname"
  if [ -f "teamspeak3-server_linux-x86-3.0.11.3.tar.gz" ]; then
    #cp ./teamspeak3-server_linux-x86-.tar.gz /tmp
    tar -xvzf teamspeak3-server_linux-x86-${server_version}.tar.gz
    mv teamspeak3-server_linux-x86 /tmp/teamspeak3
  fi
else
  echo "Architecture $arch not valid."
  exit 3
fi

mkdir /tmp/teamspeak3-server
mkdir /tmp/teamspeak3-server/DEBIAN

# making debian control file
echo "Package: teamspeak3-server
Version: ${server_version}
Section: daemons
Priority: optional
Architecture: $_archname
Maintainer: Mark Weiman <contact@markzz.com>
Homepage: https://github.com/markzz/teamspeak3-server-packaging
Description: Server for Teamspeak 3" > /tmp/teamspeak3-server/DEBIAN/control

mkdir -p /tmp/teamspeak3-server/lib/systemd/system/
mkdir -p /tmp/teamspeak3-server/usr/share/doc/teamspeak3-server/
mkdir -p /tmp/teamspeak3-server/usr/share/teamspeak3-server/
mkdir -p /tmp/teamspeak3-server/etc/
mkdir -p /tmp/teamspeak3-server/usr/lib/
mkdir -p /tmp/teamspeak3-server/usr/bin/

# creating debian license files.
echo "Format-Specification: http://svn.debian.org/wsvn/dep/web/deps/dep5.mdwn?op=file&rev=135
Name: teamspeak3-server
Maintainer: Mark Weiman <contact@markzz.com>
Source: http://www.teamspeak.com/

License: custom
" > /tmp/ts3-copyright.tmp

cat /tmp/ts3-copyright.tmp /tmp/teamspeak3/LICENSE > /tmp/teamspeak3-server/DEBIAN/copyright
rm /tmp/ts3-copyright.tmp

echo '#!/bin/sh
if [ -d "/usr/share/teamspeak3-serverlocal/" ]; then
  sqldir_dst="/usr/share/teamspeak3-server/"
  find "${sqldir_dst}" -type d -exec chmod 755 {} \;
  find "${sqldir_dst}" -type f -exec chmod 644 {} \;
fi
if [ -d "/usr/share/doc/teamspeak3-server/" ]; then
  local docdir_dst="/usr/share/doc/teamspeak3-server/"
  find "${docdir_dst}" -type d -exec chmod 755 {} \;
  find "${docdir_dst}" -type f -exec chmod 644 {} \;
fi' > /tmp/teamspeak3-server/DEBIAN/preinst

chmod 755 /tmp/teamspeak3-server/DEBIAN/preinst

echo '#!/bin/sh
if ! getent group "teamspeak" >/dev/null; then
  groupadd -r teamspeak
fi
if ! getent passwd "teamspeak" >/dev/null; then
  useradd -r -M -N -g teamspeak -d /var/lib/teamspeak3-server -s /usr/bin/nologin -c "Teamspeak Server" teamspeak
fi
# Install workdirs
install -dm 744 -o teamspeak -g teamspeak /var/log/teamspeak3-server/
install -dm 744 -o teamspeak -g teamspeak /var/lib/teamspeak3-server/

# Load unit file
systemctl --system daemon-reload

echo " >>> TeamSpeak End User License Agreement:"
echo " >>> You need to agree with the TeamSpeak 3 license"
echo " >>> before you use this software."

# Restart teamspeak3-server
systemctl --system daemon-reload
if ! systemctl --quiet is-active teamspeak3-server; then
  systemctl restart teamspeak3-server
fi' > /tmp/teamspeak3-server/DEBIAN/postinst

chmod 755 /tmp/teamspeak3-server/DEBIAN/postinst

echo '#!/bin/sh
if systemctl --quiet is-active teamspeak3-server; then
  systemctl stop teamspeak3-server
fi' > /tmp/teamspeak3-server/DEBIAN/prerm

chmod 755 /tmp/teamspeak3-server/DEBIAN/prerm

echo '#!/bin/sh
if getent passwd "teamspeak" >/dev/null; then
  userdel teamspeak > /dev/null
fi
if getent group "teamspeak" >/dev/null; then
  groupdel teamspeak >/dev/null
fi' > /tmp/teamspeak3-server/DEBIAN/postrm

chmod 755 /tmp/teamspeak3-server/DEBIAN/postrm

# create configuration file
echo '#
# Parameters to be passed to teamspeak3-server
#
# The following commandline parameters are available:
#
#* default_voice_port (9987)
#  UDP port open for clients to connect to. This port is used by the first 
#  virtual server, subsequently started virtual servers will open on increasing 
#  port numbers.
#  Default: The default voice port is 9987.
#
#* voice_ip (0.0.0.0)
#  IP on which the server instance will listen for incoming voice connections.
#  Default: The server is bound on any IP address.
#
#* create_default_virtualserver (1)
#  Normally one virtual server is created automatically when the TeamSpeak 3
#  Server process is started. To disable this behaviour, set this parameter
#  to "0". In this case you have to start virtual servers manually using the
#  ServerQuery interface.
#  Default: If not provided, one virtual server is created.
#
#* machine_id (<empty>)
#  Optional name of this server process to identify a group of servers with
#  the same ID. This can be useful when running multiple TeamSpeak 3 Server
#  instances on the same database. Please note that we strongly recommend that
#  you do NOT run multiple server instances on the same SQLite database.
#  Default: The server instance will not use a machine ID.
#
#* filetransfer_port (30033)
#  TCP Port opened for file transfers. If you specify this parameter, you also 
#  need to specify the "filetransfer_ip" parameter!
#  Default: The default file tranfer port is 30033.
#  
#* filetransfer_ip (0.0.0.0)
#  IP on which the file transfers are bound to. If you specify this parameter, 
#  you also need to specify the "filetransfer_port" parameter!
#  Default: File transfers are bound on any IP address.
#
#* query_port (10011)
#  TCP Port opened for ServerQuery connections. If you specify this parameter, 
#  need to specify the "query_ip" parameter!
#  Default: The default ServerQuery port is 10011.
#
#* query_ip (0.0.0.0)
#  IP bound for incoming ServerQuery connections. If you specify this parameter, 
#  you also need to specify the "query_port" parameter!
#  Default: ServerQuery connections are bound on any IP address.
#
#* clear_database (0)
#  If set to "1", the server database will be cleared before starting up the server. 
#  This is mainly used for testing. Usually this parameter should not be specified, 
#  so all server settings will be restored when the server process is restarted.
#  Default: Database is not cleared on start.
#
#* logpath (logs/)
#  The physical path where the server will create logfiles.
#  Default: The server will create logfiles in the "logs/" subdirectory.
#
#* dbplugin (ts3db_sqlite3)
#  Name of the database plugin library used by the server instance. For example, if
#  you want to start the server with MySQL support, simply set this parameter to
#  "ts3db_mysql" to use the MySQL plugin. Do *NOT* specify the "lib" prefix or the file 
#  extension of the plugin.
#  Default: The default SQLite3 database plugin will be used.
#  
#* dbpluginparameter (<empty>)
#  A custom parameter passed to the database plugin library. For example, the MySQL
#  database plugin supports a parameter to specify the physical path of the plugins
#  configuration file.
#  Default: The database plugin will be used without a parameter.
#
#* dbsqlpath (sql/)
#  The physical path where your SQL script files are located.
#  Default: The server will search for SQL script files in the "sql/" subdirectory.
#
#* dbsqlcreatepath (create_sqlite/)
#  The physical path where your SQL installation files are located. Note that this 
#  path will be added to the value of the "dbsqlpath" parameter.
#  Default: The server will search for SQL installation scripts files in the 
#  "<dbsqlpath>/dbsqlcreatepath/" subdirectory.
#  
#* licensepath (<empty>)
#  The physical path where your license file is located.
#  Default: The license file is located in your servers installation directory.
#  
#* createinifile (0)
#  If set to "1", the server will create an INI-style config file containing all 
#  commandline parameters with the values you have specified.
#  Default: The server will not create a config file.
#  
#* inifile (ts3server.ini)
#  The physical path where your config file is located. Per default, the config file will
#  be called "ts3server.ini".
#  Default: The config file is located in your servers installation directory.
#  
#* query_ip_whitelist (query_ip_whitelist.txt)
#  The file containing whitelisted IP addresses for the ServerQuery interface. All hosts
#  listed in this file will be ignored by the ServerQuery flood protection.
#  Default: The whitelist file is located in your servers installation directory.
#  
#* query_ip_backlist (query_ip_backlist.txt)
#  The file containing backlisted IP addresses for the ServerQuery interface. All hosts
#  listed in this file are not allowed to connect to the ServerQuery interface.
#  Default: The whitelist file is located in your servers installation directory.
#
#* dbclientkeepdays (90)
#  Defines how many days to keep unused client identities. Auto-pruning is triggered on every 
#  start and on every new month while the server is running.
#  Default: The server will auto-prune client identities older than 90 days.
#  
#* dblogkeepdays (90)
#  Defines how many days to keep database log entries. Auto-pruning is triggered on every 
#  start and on every new month while the server is running.
#  Default: The server will auto-prune log entries older than 90 days.
#  
#* logquerycommands (1)
#  If set to "1", the server will log every ServerQuery command executed by clients. This can
#  be useful while trying to diagnose several different issues.
#  Default: ServerQuery commands will not be logged.
#  
#* no_permission_update (0)
#  If set to "1", new permissions will not be added to existing groups automatically. Note that
#  this can break your server configuration if you dont update them manually.
#  Default: New permissions will be added to existing groups automatically.

TS_ARGS="logpath=/var/log/teamspeak3-server/ dbsqlpath=/usr/share/teamspeak3-server/sql/"' > /tmp/teamspeak3-server/etc/teamspeak3-server.conf

# create systemd service
echo "[Unit]
Description=TeamSpeak3 Server
After=network.target

[Service]
Type=simple
User=teamspeak
Group=teamspeak
WorkingDirectory=/var/lib/teamspeak3-server
EnvironmentFile=/etc/teamspeak3-server.conf
ExecStart=/usr/bin/teamspeak3-server \${TS_ARGS}

[Install]
WantedBy=multi-user.target" > /tmp/teamspeak3-server/lib/systemd/system/teamspeak3-server.service

mv /tmp/teamspeak3/libts3db_mariadb.so /tmp/teamspeak3-server/usr/lib/
mv /tmp/teamspeak3/libts3db_sqlite3.so /tmp/teamspeak3-server/usr/lib/
mv /tmp/teamspeak3/sql/ /tmp/teamspeak3-server/usr/share/teamspeak3-server/sql/
mv /tmp/teamspeak3/doc /tmp/teamspeak3-server/usr/share/doc/teamspeak3-server
mv /tmp/teamspeak3/ts3server_linux_${_arch} /tmp/teamspeak3-server/usr/bin/teamspeak3-server

echo "Building package with dpkg..."
fakeroot dpkg --build /tmp/teamspeak3-server
mv /tmp/teamspeak3-server.deb ./teamspeak3-server_${server_version}-1.deb

rm -r /tmp/teamspeak3
rm -r /tmp/teamspeak3-server
echo "DONE!"