-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.local.sh
executable file
·279 lines (227 loc) · 7.61 KB
/
install.local.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
#!/bin/sh
# install.local.sh
#
# Copyright 2014 Quentin Hess
#
# This file is part of Hub'erte.
#
# Hub'erte is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Hub'erte is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Hub'erte. If not, see <http://www.gnu.org/licenses/>.
#
cp ext/Config.php.orig ext/Config.php
cp wwwroot/config.php.orig wwwroot/config.php
if [ -e install.hobbit.sh ]; then
rm install.hobbit.sh
fi
echo "Welcome on Hub'erte Installation"
echo
echo "===> User creation <==="
echo
echo "Where do you want to install Hub'erte [/usr/local/huberte] ?"
read prefix
echo "What userid will be run Hub'erte [huberte] ?"
read userid
echo "What groupid will be run Hub'erte [huberte] ?"
read groupid
if [ "$prefix" == "" ]; then
prefix="/usr/local/huberte"
fi
if [ "$userid" == "" ]; then
userid="huberte"
fi
if [ "$groupid" == "" ]; then
groupid="huberte"
fi
echo
echo "User environnement creation ..."
echo
mkdir -p $prefix
groupadd $groupid
useradd -d $prefix -g $groupid $userid
chown -R $userid:$groupid $prefix
sed -i s'|PREFIX|'$prefix'|' ext/Config.php
sed -i s'/HUBERTE_USER/'$userid'/' ext/Config.php
echo
echo "===> Hobbit/Xymon & Asterisk <==="
echo
echo "Asterisk and Xymon / Hobbit are on same server [yes] ?"
read oneserver
echo "What is Xymon/Hobbit username ?"
read hobbituser
echo "What is Xymon/Hobbit directory ?"
read xymonprefix
echo "What is Asterisk username [asterisk] ?"
read asteriskuserid
if [ "$hobbituser" == "" ] || [ "$xymonprefix" == "" ]; then
echo "Error, one field is blank"
exit 1
fi
if [ "$asteriskuserid" == "" ]; then
asteriskuserid="asterisk"
fi
if [ "$oneserver" == "N" ] || [ "$oneserver" == "n" ] || [ "$oneserver" == "no" ] || [ "$oneserver" == "NO" ]; then
oneserver=FALSE
su - $userid -c "mkdir -p $prefix/.ssh"
su - $userid -c "ssh-keygen -t rsa -b 2048 -f $prefix/.ssh/id_rsa -P \"\""
echo "#!/bin/sh
# install.hobbit.sh
#
# Copyright 2014 Quentin Hess
#
# This file is part of Hub'erte.
#
# Hub'erte is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Hub'erte is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Hub'erte. If not, see <http://www.gnu.org/licenses/>.
#" > install.hobbit.sh
echo "mkdir -p $prefix" >> install.hobbit.sh
echo "groupadd $groupid" >> install.hobbit.sh
echo "useradd -d $prefix -g $groupid $userid" >> install.hobbit.sh
echo "chown -R $userid:$groupid $prefix" >> install.hobbit.sh
echo "su - $userid -c \"mkdir -p $prefix/.ssh\"" >> install.hobbit.sh
echo "su - $userid -c \"ssh-keygen -t rsa -b 2048 -f $prefix/.ssh/id_rsa -P \\\"\\\"\"" >> install.hobbit.sh
echo "echo \"`cat $prefix/.ssh/id_rsa.pub`\" >> $prefix/.ssh/authorized_keys" >> install.hobbit.sh
echo "echo" >> install.hobbit.sh
echo "echo \"Copy following line on $prefix/.ssh/authorized_keys, on Hub'erte Server :\"" >> install.hobbit.sh
echo "cat $prefix/.ssh/id_rsa.pub" >> install.hobbit.sh
echo "echo \"$hobbituser ALL=(ALL) NOPASSWD:ALL\" >> /etc/sudoers" >> install.hobbit.sh
echo "What is IP of Xymon server for ssh from here ?"
read xymonip
echo "What is IP of local server for ssh from Xymon/Hobbit server ?"
read localip
cp ext/HobbitAlert.sh.ssh ext/HobbitAlert.sh
sed -i s'/HUBERTE_IP/'$localip'/' ext/HobbitAlert.sh
sed -i s'/XYMON_IP/'$xymonip'/' ext/Config.php
else
oneserver=TRUE
cp ext/HobbitAlert.sh.local ext/HobbitAlert.sh
echo "$hobbituser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
fi
sed -i s'|PREFIX|'$prefix'|' ext/HobbitAlert.sh
sed -i s'|XYMON_PATH|'$xymonprefix'|' ext/Config.php
echo "$asteriskuserid ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
echo
echo "===> MySQL Database <==="
echo "Please create MySQL user which have grants to modify a database"
echo
echo "MySQL Host [127.0.0.1] ?"
read mysqlhost
echo "MySQL Username ?"
read mysqluser
echo "MySQL Password ?"
read mysqlpassword
echo "MySQL Database ?"
read mysqldb
if [ "$mysqlhost" == "" ]; then
mysqlhost="127.0.0.1"
fi
if [ "$mysqluser" == "" ] || [ "$mysqlpassword" == "" ] || [ "$mysqldb" == "" ]; then
echo "Error, one field is blank"
exit 1
fi
echo
echo "MySQL database installation ..."
echo
mysql -u$mysqluser -p$mysqlpassword -h$mysqlhost $mysqldb < ./install.sql
if [ ! $? -eq 0 ]; then
echo "MySQL installation error"
exit 1
fi
sed -i s'/MYSQL_HOST/'$mysqlhost'/' ext/Config.php
sed -i s'/MYSQL_HOST/'$mysqlhost'/' wwwroot/config.php
sed -i s'/MYSQL_USER/'$mysqluser'/' ext/Config.php
sed -i s'/MYSQL_USER/'$mysqluser'/' wwwroot/config.php
sed -i s'/MYSQL_PASSWORD/'$mysqlpassword'/' ext/Config.php
sed -i s'/MYSQL_PASSWORD/'$mysqlpassword'/' wwwroot/config.php
sed -i s'/MYSQL_DB/'$mysqldb'/' ext/Config.php
sed -i s'/MYSQL_DB/'$mysqldb'/' wwwroot/config.php
echo "===> Asterisk Manager <==="
echo
echo "Manager host [127.0.0.1] ?"
read managerhost
echo "Manager port [5038] ?"
read managerport
echo "Manager user ?"
read manageruser
echo "Manager password ?"
read managerpassword
if [ "$managerhost" == "" ]; then
managerhost="127.0.0.1"
fi
if [ "$managerport" == "" ]; then
managerport="5038"
fi
if [ "$manageruser" == "" ]; then
echo "Error, one field is blank"
exit 1
fi
sed -i s'/MANAGER_HOST/'$managerhost'/' ext/Config.php
sed -i s'/MANAGER_PORT/'$managerport'/' ext/Config.php
sed -i s'/MANAGER_USER/'$manageruser'/' ext/Config.php
sed -i s'/MANAGER_SECRET/'$managerpassword'/' ext/Config.php
echo "===> Others <==="
echo
echo "What is the context used to call numbers from huberte ?"
read context
echo "What is a delivery strategy to apply [per_alert] ?"
read delstrat
echo "What is escalation delay to set [1800] (seconds) ?"
read escaldelay
echo "Non-business hour start [20] ?"
read hnostart
echo "Non-business hour end [8] ?"
read hnoend
if [ "$delstrat" == "" ]; then
delstrat="per_alert"
fi
if [ "$escaldelay" == "" ]; then
escaldelay="1800"
fi
if [ "$hnostart" == "" ]; then
hnostart="20"
fi
if [ "$hnoend" == "" ]; then
hnoend="8"
fi
if [ "$context" == "" ]; then
echo "Error, one field is blank"
exit 1
fi
sed -i s'/CONTEXT_CALL/'$context'/' ext/Config.php
sed -i s'/DELIVERY_STRATEGY/'$delstrat'/' ext/Config.php
sed -i s'/ESCALATION_DELAY/'$escaldelay'/' ext/Config.php
sed -i s'/HNO_START/'$hnostart'/' ext/Config.php
sed -i s'/HNO_END/'$hnoend'/' ext/Config.php
cp -r sounds $prefix/
cp -r ext $prefix/
cp COPYING $prefix/
cp -r asterisk $prefix/
chown -R $userid:$groupid $prefix
echo
echo "===> Installation Complete <==="
echo
if [ "$oneserver" == "FALSE" ]; then
echo "Copy install.hobbit.sh script on Hobbit/Xymon server and run it"
echo
fi
echo "Add following line at the end of your Asterisk extensions.conf file :"
echo "#include $prefix/asterisk/extensions_huberte.conf"