#!/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 # # 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="x86_64" _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="i686" 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 /tmp/teamspeak3-server_linux-x86-${server_version} /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 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 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 () # 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 () # 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 # "/dbsqlcreatepath/" subdirectory. # #* licensepath () # 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_amd64 /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!"