-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.sh
executable file
·282 lines (209 loc) · 7.96 KB
/
init.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
#!/bin/bash
#set -x
get_distribution() {
lsb_dist=""
# Every system that we officially support has /etc/os-release
if [ -r /etc/os-release ]; then
lsb_dist="$(. /etc/os-release && echo "$ID")"
elif [ -r /etc/centos-release ]; then
lsb_dist="centos"
fi
# Returning an empty string here should be alright since the
# case statements don't act unless you provide an actual value
echo "$lsb_dist"
}
command_exists() {
command -v "$@" > /dev/null 2>&1
}
main() {
sh_c='sh -c'
## Set execute command prefix.
if [ "$user" != 'root' ]; then
if command_exists sudo; then
sh_c='sudo -E sh -c'
elif command_exists su; then
sh_c='su -c'
else
cat >&2 <<-'EOF'
Error: this installer needs the ability to run commands as root.
We are unable to find either "sudo" or "su" available to make this happen.
EOF
exit 1
fi
fi
## Set linux distribution name
lsb_dist=$(get_distribution)
lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')"
## Check linux version
case "$lsb_dist" in
ubuntu)
if command_exists lsb_release; then
dist_version="$(lsb_release --codename | cut -f2)"
fi
if [ -z "$dist_version" ] && [ -r /etc/lsb-release ]; then
dist_version="$(. /etc/lsb-release && echo "$DISTRIB_CODENAME")"
fi
;;
centos)
if [ -r /etc/os-release ]; then
dist_version="$(. /etc/os-release && echo "$VERSION_ID")"
elif [ -r /etc/centos-release ]; then
dist_version="$(cat /etc/centos-release | cut -d ' ' -f 3 | cut -d '.' -f 1)"
fi
;;
esac
echo "Host's system is $lsb_dist - $dist_version"
cd /tmp
## Download resource
case "$lsb_dist" in
ubuntu)
$sh_c "apt-get update >/dev/null"
$sh_c "apt-get install -y wget >/dev/null"
;;
centos)
case "$dist_version" in
5|6|7)
yum install -y wget
;;
8)
dnf install -y wget
;;
esac
;;
esac
if [ ! -f nagioscore.tar.gz ]; then
wget -q --no-check-certificate -O nagioscore.tar.gz https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.4.5.tar.gz
tar xzf nagioscore.tar.gz
fi
if [ ! -f nagios-plugins.tar.gz ]; then
wget -q --no-check-certificate -O nagios-plugins.tar.gz https://github.com/nagios-plugins/nagios-plugins/archive/release-2.2.1.tar.gz
tar zxf nagios-plugins.tar.gz
fi
## Deploy
case "$lsb_dist" in
ubuntu)
$sh_c "apt-get install -y gcc libc6 libmcrypt-dev libssl-dev gettext \
make autoconf build-essential gawk unzip bc dc iputils-ping \
apache2 snmp libnet-snmp-perl \
libwww-perl libcrypt-ssleay-perl liblwp-protocol-https-perl >/dev/null"
case "$dist_version" in
trusty|utopic|vivid|wily)
$sh_c "apt-get install -y php5 apache2-utils libgd2-xpm-dev >/dev/null"
;;
xenial|yakkety|zesty|artful)
$sh_c "apt-get install -y php libapache2-mod-php7.0 libgd2-xpm-dev >/dev/null"
;;
bionic|cosmic)
$sh_c "apt-get install -y php libapache2-mod-php7.2 libgd-dev >/dev/null"
;;
focal)
$sh_c "apt-get install -y php libapache2-mod-php7.4 libgd-dev >/dev/null"
;;
*|disco|eoan)
echo "Error."
exit 1
;;
esac
cd /tmp/nagioscore-nagios-4.4.5/
$sh_c "./configure --with-httpd-conf=/etc/apache2/sites-enabled >/dev/null"
$sh_c "make all >/dev/null"
$sh_c "make install-groups-users >/dev/null"
$sh_c "usermod -a -G nagios www-data >/dev/null"
$sh_c "make install >/dev/null"
$sh_c "make install-daemoninit >/dev/null"
$sh_c "make install-commandmode >/dev/null"
$sh_c "make install-config >/dev/null"
$sh_c "make install-webconf >/dev/null"
$sh_c "a2enmod rewrite >/dev/null"
$sh_c "a2enmod cgi >/dev/null"
$sh_c "htpasswd -cb /usr/local/nagios/etc/htpasswd.users nagiosadmin P@ssw0rd >/dev/null"
cd /tmp/nagios-plugins-release-2.2.1/
$sh_c "./tools/setup >/dev/null"
$sh_c "./configure >/dev/null"
$sh_c "make >/dev/null"
$sh_c "make install >/dev/null"
pidof init > /dev/null
if [ 1 -eq $? ]; then
if command_exists service; then
$sh_c "service apache2 restart >/dev/null"
$sh_c "service nagios start >/dev/null"
fi
else
case "$dist_version" in
trusty|utopic)
$sh_c "service apache2 restart >/dev/null"
$sh_c "service nagios start >/dev/null"
;;
*)
$sh_c "systemctl restart apache2.service >/dev/null"
$sh_c "systemctl start nagios.service >/dev/null"
;;
esac
fi
;;
centos)
case "$dist_version" in
5|6|7)
yum install -y gcc glibc glibc-common unzip httpd php gd gd-devel perl postfix
;;
8)
dnf install -y gcc glibc glibc-common perl httpd php gd gd-devel
dnf update -y
;;
esac
cd /tmp/nagioscore-nagios-4.4.5/
./configure
make all
make install-groups-users
usermod -a -G nagios apache
make install
case "$dist_version" in
5|6)
make install-daemoninit
chkconfig --level 2345 httpd on
;;
7|8)
make install-daemoninit
systemctl enable httpd.service
;;
esac
make install-commandmode
make install-config
make install-webconf
htpasswd -cb /usr/local/nagios/etc/htpasswd.users nagiosadmin P@ssw0rd
case "$dist_version" in
5)
yum install -y gcc glibc glibc-common make gettext automake \
openssl-devel net-snmp net-snmp-utils epel-release \
perl-Net-SNMP perl-libwww-perl perl-Crypt-SSLeay perl-LWP-Protocol-https
cd /tmp
wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.60.tar.gz
tar xzf autoconf-2.60.tar.gz
cd /tmp/autoconf-2.60
./configure
make
make install
;;
6|7)
yum install -y gcc glibc glibc-common make gettext automake autoconf openssl-devel net-snmp net-snmp-utils epel-release perl-Net-SNMP
;;
8)
yum install -y gcc glibc glibc-common make gettext automake autoconf openssl-devel net-snmp net-snmp-utils epel-release
yum --enablerepo=PowerTools,epel install perl-Net-SNMP
;;
esac
case "$dist_version" in
5|6)
service nagios start
service httpd start
;;
7|8)
systemctl start nagios.service
systemctl start httpd.service
;;
esac
;;
esac
}
## Entrypoint
main