-
Notifications
You must be signed in to change notification settings - Fork 63
/
install_glpi.sh
434 lines (296 loc) · 7.27 KB
/
install_glpi.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
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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
#!/bin/bash
###############################################################################
# Debug
# set -xv
## VARIABLES
LOGS="install_glpi.log"
GLPI_LANG="en_US"
# GLPI_LANG="pt_BR"
VERSION="9.5.6"
TIMEZONE=Etc/UTC
# TIMEZONE=America/Fortaleza
FQDN="glpi.fametec.com.br"
ADMINEMAIL="suporte@fametec.com.br"
ORGANIZATION="FAMETec"
MYSQL_ROOT_PASSWORD=''
DBUSER="glpi"
DBHOST="localhost"
DBPORT=3306
DBNAME="glpi"
DBPASS="E`< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-32};echo;`"
MYSQL_NEW_ROOT_PASSWORD="C`< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-32};echo;`"
# DBPASS="qaz123"
# MYSQL_NEW_ROOT_PASSWORD="qaz123"
MYSQL="mysql -u root -p${MYSQL_NEW_ROOT_PASSWORD}"
CURL=`which curl`
Log () {
cat <<EOF > $LOGS
====================================================
## VARIAVEIS
VERSION=$VERSION
TIMEZONE=$TIMEZONE
FQDN=$FQDN
ADMINEMAIL=$ADMINEMAIL
ORGANIZATION=$ORGANIZATION
MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD
DBUSER=$DBUSER
DBHOST=$DBHOST
DBPORT=$DBPORT
DBNAME=$DBNAME
DBPASS=$DBPASS
MYSQL_NEW_ROOT_PASSWORD=$MYSQL_NEW_ROOT_PASSWORD
MYSQL=$MYSQL
CURL=$CURL
====================================================
EOF
}
EnableFirewall() {
echo "Setting firewall rules..."
systemctl enable --now firewalld
firewall-cmd --zone=public --add-service=http --permanent
firewall-cmd --zone=public --add-service=https --permanent
}
DisableFirewall () {
systemctl disable --now firewalld
}
InstallRepo () {
echo "Installing Yum Repo..."
yum -y install expect\
epel-release \
yum-utils
yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum-config-manager --enable remi-php73
cat <<EOF > /etc/yum.repos.d/MariaDB.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
EOF
}
InstallDataBase () {
echo "Remove old database..."
yum -y remove \
mariadb-server \
mariadb \
mariadb-config \
mariadb-libs \
mariadb-common
echo "Install MariaDB 10.0u..."
yum -y install \
MariaDB-server \
MariaDB-client
echo "Enable service..."
systemctl enable --now mariadb
}
SetDataBaseSecure () {
echo "Running mysql_secure_installation..."
SECURE_MYSQL=$(expect -c "
set timeout 10
spawn mysql_secure_installation
expect \"Enter current password for root (enter for none):\"
send \"$MYSQL_ROOT_PASSWORD\r\"
expect \"Set the root password?\"
send \"y\r\"
expect \"New password:\"
send \"$MYSQL_NEW_ROOT_PASSWORD\r\"
expect \"Re-enter new password:\"
send \"$MYSQL_NEW_ROOT_PASSWORD\r\"
expect \"Remove anonymous users?\"
send \"y\r\"
expect \"Disallow root login remotely?\"
send \"y\r\"
expect \"Remove test database and access to it?\"
send \"y\r\"
expect \"Reload privilege tables now?\"
send \"y\r\"
expect eof
")
echo "$SECURE_MYSQL"
}
CreateDataBase () {
echo "Creating database $DBNAME..."
$MYSQL -e "create database $DBNAME character set utf8;"
$MYSQL -e "create user $DBUSER@localhost identified by '"$DBPASS"';"
$MYSQL -e "grant all privileges on $DBNAME.* to $DBUSER@localhost;"
}
InstallApache () {
echo "Installing Apache..."
yum -y install \
httpd \
mod_ssl
}
InstallPhp () {
echo "Remove old PHP..."
yum -y remove \
php-cli \
mod_php \
php-common
echo "Install php73..."
yum -y install \
mod_php \
php-cli \
php-mysqlnd
yum -y install \
php-pear-CAS \
wget \
php-json \
php-mbstring \
php-mysqli \
php-session \
php-gd \
php-curl \
php-domxml \
php-imap \
php-ldap \
php-openssl \
php-opcache \
php-apcu \
php-xmlrpc \
php-intl \
php-zip \
php-sodium
php-ZendFramework-Cache-Backend-Apc \
jq \
openssl
}
SetPhpIni () {
echo "Setting 99-glpi.ini..."
cat <<EOF > /etc/php.d/99-glpi.ini
memory_limit = 64M ;
file_uploads = on ;
max_execution_time = 600 ;
register_globals = off ;
magic_quotes_sybase = off ;
session.auto_start = off ;
session.use_trans_sid = 0 ;
EOF
cat <<EOF > /etc/php.d/99-timezone.ini
[Date]
date.timezone = $TIMEZONE ;
EOF
cat <<EOF > /etc/php.d/99-apcu.ini
apc.enable_cli = 1 ;
EOF
}
Install () {
echo "Download and install GLPI $VERSION ..."
curl -sSL https://github.com/glpi-project/glpi/releases/download/$VERSION/glpi-$VERSION.tgz | tar -zxf - -C /var/www/html/
}
SetPermission () {
chown -Rf apache:apache /var/www/html/glpi
}
SetHttpConf () {
cat <<EOF > /etc/httpd/conf.d/glpi.conf
<VirtualHost *:80>
ServerName ${FQDN}
DocumentRoot /var/www/html/glpi
<Directory /var/www/html/glpi/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
EOF
}
DisableSELinux () {
sed -i s/enforcing/permissive/g /etc/selinux/config
setenforce 0
}
EnableSELinux () {
chcon -R -t httpd_sys_rw_content_t /var/www/html/glpi/
setsebool -P httpd_can_network_connect 1
setsebool -P httpd_can_network_connect_db 1
setsebool -P httpd_can_sendmail 1
setenforce 1
}
StartHttpd () {
echo "Start HTTPD..."
systemctl enable --now httpd
}
DeployDataBase () {
local SUBVERSION=`echo $VERSION | cut -d . -f 2`
if [ $SUBVERSION -ge 4 ]; then
echo "Deploy DB using bin/console. Please wait..."
/usr/bin/php /var/www/html/glpi/bin/console glpi:database:install \
--no-interaction \
--db-host=${DBHOST} \
--db-port=${DBPORT} \
--db-name=${DBNAME} \
--db-user=${DBUSER} \
--db-password=${DBPASS} \
--default-language=${GLPI_LANG}
else
echo "Deploy DB using cliinstall.php. Please wait..."
/usr/bin/php /var/www/html/glpi/scripts/cliinstall.php \
--host=${DBHOST} \
--hostport=${DBPORT} \
--db=$DBNAME \
--user=$DBUSER \
--pass=$DBPASS \
--lang=$GLPI_LANG
fi
}
GetCurrentVersion () {
echo "{ `curl -s http://localhost/glpi/ajax/telemetry.php | grep -v code` }" | jq -r '.glpi.version'
}
GetTelemetry () {
echo "{ `curl -s http://localhost/glpi/ajax/telemetry.php | grep -v code` }"
}
InstallBackupJob () {
cat <<EOF > /etc/cron.daily/backup-glpi.sh
#!/bin/sh
# Backup Banco GLPI
mysqldump -u ${DBUSER} -p${DBPASS} ${DBNAME} | gzip > /var/www/html/glpi/files/_dumps/glpi-${VERSION}-\`date +%Y-%m-%d-%H-%M\`.sql.gz
EXITVALUE=\$?
if [ \$EXITVALUE != 0 ]; then
/usr/bin/logger -t GLPI "ALERT exited abnormally with [\$EXITVALUE]"
fi
chown apache.apache /var/www/html/glpi/files/_dumps/*.sql.gz
# Backup completo para dentro de /backup/
if [ ! -d /backup ]; then
mkdir -p /backup
fi
tar -zcf /backup/backup-${VERSION}-\`date +%Y-%m-%d-%H-%M\`.tar.gz /var/www/html/glpi
EXITVALUE=\$?
if [ \$EXITVALUE != 0 ]; then
/usr/bin/logger -t GLPI "ALERT exited abnormally with [\$EXITVALUE]"
fi
# Apagar backup com mais de 30d
find /var/www/html/glpi/files/_dumps/ -mtime +30 -delete
EXITVALUE=\$?
if [ \$EXITVALUE != 0 ]; then
/usr/bin/logger -t GLPI "ALERT exited abnormally with [\$EXITVALUE]"
fi
exit 0
EOF
chmod +x /etc/cron.daily/backup-glpi.sh
}
EXECUTE="
Log
DisableSELinux
DisableFirewall
InstallRepo
InstallDataBase
SetDataBaseSecure
CreateDataBase
InstallApache
InstallPhp
SetPhpIni
Install
SetHttpConf
StartHttpd
DeployDataBase
SetPermission
InstallBackupJob
"
for job in $EXECUTE; do
echo "Run $job... "
$job >> $LOGS 2>&1
if [ $? -eq 0 ]; then
echo "ok"
else
echo "fail"
fi
done
GetTelemetry >> $LOGS