-
Notifications
You must be signed in to change notification settings - Fork 0
/
tuxglpi.sh
269 lines (184 loc) · 5.69 KB
/
tuxglpi.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
#!/bin/bash
###############################################################################
########## Scrip shell modificado para instalacao do GLPI em Centos ###########
########## Este script criara um log no diretório atual para ################
########## pesquisa de senha do banco de dados!!! By Tuxjr ################
###############################################################################
###############################################################################
## VARIAVEIS
VERSION="x.x.x"
TIMEZONE=America/Sao_Paulo
FQDN="nomedominio"
ADMINEMAIL="email"
ORGANIZATION="tuxjr"
MYSQL_ROOT_PASSWORD=''
DBUSER="glpi"
DBHOST="localhost"
DBNAME="glpi"
DBPASS="E`< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-32};echo;`"
# DBPASS="qaz123"
# MYSQL_NEW_ROOT_PASSWORD="qaz123"
MYSQL_NEW_ROOT_PASSWORD="C`< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-32};echo;`"
MYSQL="mysql -u root -p${MYSQL_NEW_ROOT_PASSWORD}"
CURL=`which curl`
cat <<EOF > ~/install_glpi.log
====================================================
## VARIAVEIS
VERSION=$VERSION
TIMEZONE=$TIMEZONE
FQDN=$FQDN
ADMINEMAIL=$ADMINEMAIL
ORGANIZATION=$ORGANIZATION
MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD
DBUSER=$DBUSER
DBHOST=$DBHOST
DBNAME=$DBNAME
DBPASS=$DBPASS
MYSQL_NEW_ROOT_PASSWORD=$MYSQL_NEW_ROOT_PASSWORD
MYSQL=$MYSQL
CURL=$CURL
====================================================
EOF
## FIREWALLD
firewall-cmd --zone=public --add-service=http --permanent
firewall-cmd --zone=public --add-service=https --permanent
## REPOSITORIO
cd ~
curl 'https://setup.ius.io/' -o setup-ius.sh
bash setup-ius.sh
yum -y install epel-release expect
## MARIADB-SERVER
#if [ "$VERSION" != "9.3" ]; then
# yum -y install mariadb-server
#else
yum -y remove mariadb-server mariadb mariadb-config mariadb-libs mariadb-common
yum -y install mariadb100u-server mariadb100u mariadb100u-config mariadb100u-libs mariadb100u-common
#fi
## Restart do mysql
systemctl enable mariadb
systemctl start mariadb
## Configuração de segurança do banco
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 \"Change 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"
## DATABASE
$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;"
## APACHE E PHP7
yum install -y httpd mod_ssl
yum -y remove php-cli mod_php php-common
yum -y install mod_php72u php72u-cli php72u-mysqlnd
yum -y install \
php-pear-CAS \
wget \
php72u-json \
php72u-mbstring \
php72u-mysqli \
php72u-session \
php72u-gd \
php72u-curl \
php72u-domxml \
php72u-imap \
php72u-ldap \
php72u-openssl \
php72u-opcache \
php72u-apcu \
php72u-xmlrpc \
openssl
systemctl enable httpd
systemctl start httpd
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/timezone.ini
[Date]
date.timezone = $TIMEZONE ;
EOF
## DOWNLOAD AND INSTALL GLPI
yum -y install wget
if [ ! -e packages/$VERSION/glpi-$VERSION.tgz ]
then
mkdir -p packages
if [ "$VERSION" != "versao??" ] ; then
wget -c https://github.com/glpi-project/glpi/releases/download/$VERSION/glpi-$VERSION.tgz -O packages/glpi-$VERSION.tgz
else
wget -c https://github.com/glpi-project/glpi/releases/download/${VERSION}.0/glpi-$VERSION.tgz -O packages/glpi-$VERSION.tgz
fi
fi
tar -zxvf packages/glpi-$VERSION.tgz -C /var/www/html/
chown -R apache:apache /var/www/html/glpi
cat <<EOF > /etc/httpd/conf.d/glpi.conf
<Directory /var/www/html/glpi/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
EOF
## DESATIVAR SELINUX
#sed -i s/enforcing/permissive/g /etc/selinux/config
#setenforce 0
## ATIVAR SELINUX
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
systemctl restart httpd
php /var/www/html/glpi/scripts/cliinstall.php --host=$DBHOST --db=$DBNAME --user=$DBUSER --pass=$DBPASS --lang=pt_BR
if [ $? -eq 0 ]; then
rm -rf /var/www/html/glpi/install/install.php
fi
## BACKUP
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