-
Notifications
You must be signed in to change notification settings - Fork 0
/
teamspeak.sh
138 lines (116 loc) · 5.81 KB
/
teamspeak.sh
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
#!/usr/bin/env bash
function cleanup()
{
log "[i] Removing Teamspeak zip from ${TMP_LOCATION}." 'g'
rm -r "${TMP_LOCATION}"/teamspeak.tar
}
trap cleanup EXIT
function install_teamspeak {
# Make sure all the directories are accessible.
directory_check "${TMP_LOCATION}" 'force_failure'
directory_check "${OPT_LOCATION}" 'force_failure'
# Check if Teamspeak is running.
if systemctl is-active --quiet teamspeak
then
log '[w] A teamspeak version is currently running, stopping.' 'w'
systemctl stop teamspeak
fi
# Get a copy of Teamspeak.
fetch "${TEAMSPEAK_URL}" 'teamspeak.tar'
# Check if Teamspeak is installed in the default location
if directory_check "${OPT_LOCATION}${TEAMSPEAK_FOLDER_NAME}"
then
log '[w] Previous version of teamspeak found, removing.' 'w'
rm -rf "${OPT_LOCATION}${TEAMSPEAK_FOLDER_NAME}"
fi
unzip_move "${TMP_LOCATION}/teamspeak.tar" "${OPT_LOCATION}"
# Check if the teamspeak user exsists, if not create it.
if grep 'teamspeak' /etc/passwd > /dev/null
then
log '[w] Teamspeak user already exsists, not creating again.' 'w'
else
adduser teamspeak --system --no-create-home --no-log --shell /sbin/nologin
passwd -l teamspeak > /dev/dell
fi
# Add ports to firewalld.
systemctl stop firewalld
log '[i] Adding necessary ports to firewalld.' 'g'
firewall-cmd --permanent --zone=public --add-port=9987/udp >/dev/null 2>&1
firewall-cmd --permanent --zone=public --add-port=30033/tcp >/dev/null 2>&1
if ! systemctl restart firewalld
then
log '[!!!] Failed to bring firewalld up, please manually check firewalld and restart the script.' 'r'
exit 1
fi
# Check if a previos version of Teamspeak was installed
if [[ -f '/var/local/teamspeak3/ts3server.sqlitedb' ]]
then
log '[w] A previous version of Teamspeak was found, not overwriting the database.' 'w'
ln -s "${TEAMSPEAK_STATE}"ts3server.ini "${OPT_LOCATION}${TEAMSPEAK_FOLDER_NAME}"ts3server.ini
ln -s "${TEAMSPEAK_STATE}"ts3server.sqlitedb "${OPT_LOCATION}${TEAMSPEAK_FOLDER_NAME}"ts3server.sqlitedb
log "[i] Setting permissions on ${OPT_LOCATION}${TEAMSPEAK_FOLDER_NAME}" 'g'
chown -R teamspeak:teamspeak "${OPT_LOCATION}${TEAMSPEAK_FOLDER_NAME}"
chmod 700 "${OPT_LOCATION}${TEAMSPEAK_FOLDER_NAME}"ts3server_startscript.sh
log "[i] Setting permissions on ${TEAMSPEAK_STATE}" 'g'
chown -R teamspeak:teamspeak "${TEAMSPEAK_STATE}"
chmod -R 660 "${TEAMSPEAK_STATE}"ts3server.ini
chmod -R 660 "${TEAMSPEAK_STATE}"ts3server.sqlitedb
else
# Start teamspeak to create configuration files.
log '[i] Starting Teampseak to create configuration and database.' 'g'
chown -R teamspeak:teamspeak "${OPT_LOCATION}${TEAMSPEAK_FOLDER_NAME}"
chmod 700 "${OPT_LOCATION}${TEAMSPEAK_FOLDER_NAME}"ts3server_startscript.sh
sudo -u teamspeak "${OPT_LOCATION}${TEAMSPEAK_FOLDER_NAME}"ts3server_startscript.sh start createinifile=1 license_accepted=1 > /dev/null
sleep 10
# Stop verser
log '[i] Stopping server.' 'g'
sudo -u teamspeak "${OPT_LOCATION}${TEAMSPEAK_FOLDER_NAME}"ts3server_startscript.sh stop > /dev/null
# Check if /var/local/teamspeak3 exsists.
if ! directory_check "${TEAMSPEAK_STATE}"
then
log "[i] Creating ${TEAMSPEAK_STATE}." 'g'
mkdir -p "${TEAMSPEAK_STATE}"
fi
# Move configuration files to state location
log "[i] Moving State tiles to ${TEAMSPEAK_STATE}" 'g'
mv "${OPT_LOCATION}${TEAMSPEAK_FOLDER_NAME}"ts3server.ini "${TEAMSPEAK_STATE}"
mv "${OPT_LOCATION}${TEAMSPEAK_FOLDER_NAME}"ts3server.sqlitedb "${TEAMSPEAK_STATE}"
# Set permissions
log "[i] Setting permissions on ${TEAMSPEAK_STATE}" 'g'
chown -R teamspeak:teamspeak "${TEAMSPEAK_STATE}"
chmod -R 660 "${TEAMSPEAK_STATE}"ts3server.ini
chmod -R 660 "${TEAMSPEAK_STATE}"ts3server.sqlitedb
# Create softlinks to teamspeak directory.
log "[i] Creatings soft-links to ${OPT_LOCATION}${TEAMSPEAK_FOLDER_NAME}" 'g'
ln -s "${TEAMSPEAK_STATE}"ts3server.ini "${OPT_LOCATION}${TEAMSPEAK_FOLDER_NAME}"ts3server.ini
ln -s "${TEAMSPEAK_STATE}"ts3server.sqlitedb "${OPT_LOCATION}${TEAMSPEAK_FOLDER_NAME}"ts3server.sqlitedb
chown -R teamspeak:teamspeak "${OPT_LOCATION}${TEAMSPEAK_FOLDER_NAME}"
fi
# Check if service exsists.
if [[ ! -f '/etc/systemd/system/teamspeak.service' ]]
then
log '[i] A service file for Teamspeak does not exsist, creating...' 'g'
cat teamspeak.service > /etc/systemd/system/teamspeak.service
else
log '[w] A service file for Teamspeak already exsists, not creating again.' 'w'
fi
# Fix for the bug reported here. https://forum.teamspeak.com/threads/93623-Instance-check-error-failed-to-register-local-accounting-service-on-Linux/page8
if [[ -f '/dev/shm/7gbhujb54g8z9hu43jre8' ]]
then
rm -f /dev/shm/7gbhujb54g8z9hu43jre8
fi
# Start teamspeak
log '[i] Starting Teamspeak' 'g'
systemctl daemon-reload
systemctl enable --quiet teamspeak
systemctl start teamspeak
# Sleep 10 seconds to see it started successfully.
sleep 10
# Report status of job.
if systemctl is-active --quiet teamspeak
then
log '[i] Teamspeak was successfully started.' 'g'
else
log '[!!!] Teamspeak could not be started, exsiting..' 'r'
fi
}