forked from codeniner/nmonagent-linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
261 lines (206 loc) · 6.07 KB
/
install.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
#!/bin/bash
#
#////////////////////////////////////////////////////////////
#===========================================================
# nMon - Installer v1.0
#===========================================================
# Set environment
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# Clear the screen
clear
#SERVERKEY=$1
#GATEWAY=$2
LOG=/tmp/nmon.log
echo "--------------------------------"
echo " Welcome to nMon Agent Installer"
echo "--------------------------------"
echo " "
# Are we running as root
if [ $(id -u) != "0" ]; then
echo "nMon Agent installer needs to be run with root priviliges"
echo "Try again with root privilileges"
exit 1;
fi
# Is the server key parameter given ?
if [ $# -lt 2 ]; then
echo "The server key or gateway is missing"
echo "Exiting installer"
exit 1;
fi
### install Dependencies here
echo "Installing Dependencies"
# RHEL / CentOS / etc
if [ -n "$(command -v yum)" ]; then
yum -y install cronie gzip curl >> $LOG 2>&1
service crond start >> $LOG 2>&1
chkconfig crond on >> $LOG 2>&1
# Check if perl available or not
if ! type "perl" >> $LOG 2>&1; then
yum -y install perl >> $LOG 2>&1
fi
# Check if unzip available or not
if ! type "unzip" >> $LOG 2>&1; then
yum -y install unzip >> $LOG 2>&1
fi
# Check if curl available or not
if ! type "curl" >> $LOG 2>&1; then
yum -y install curl >> $LOG 2>&1
fi
fi
# Debian / Ubuntu
if [ -n "$(command -v apt-get)" ]; then
apt-get update -y >> $LOG 2>&1
apt-get install -y cron curl gzip >> $LOG 2>&1
service cron start >> $LOG 2>&1
# Check if perl available or not
if ! type "perl" >> $LOG 2>&1; then
apt-get install -y perl >> $LOG 2>&1
fi
# Check if unzip available or not
if ! type "unzip" >> $LOG 2>&1; then
apt-get install -y unzip >> $LOG 2>&1
fi
# Check if curl available or not
if ! type "curl" >> $LOG 2>&1; then
apt-get install -y curl >> $LOG 2>&1
fi
fi
# ArchLinux
if [ -n "$(command -v pacman)" ]; then
pacman -Sy >> $LOG 2>&1
pacman -S --noconfirm cronie curl gzip >> $LOG 2>&1
systemctl start cronie >> $LOG 2>&1
systemctl enable cronie >> $LOG 2>&1
# Check if perl available or not
if ! type "perl" >> $LOG 2>&1; then
pacman -S --noconfirm perl >> $LOG 2>&1
fi
# Check if unzip available or not
if ! type "unzip" >> $LOG 2>&1; then
pacman -S --noconfirm unzip >> $LOG 2>&1
fi
# Check if curl available or not
if ! type "curl" >> $LOG 2>&1; then
pacman -S --noconfirm curl >> $LOG 2>&1
fi
fi
# OpenSuse
if [ -n "$(command -v zypper)" ]; then
zypper --non-interactive install cronie curl gzip >> $LOG 2>&1
service cron start >> $LOG 2>&1
# Check if perl available or not
if ! type "perl" >> $LOG 2>&1; then
zypper --non-interactive install perl >> $LOG 2>&1
fi
# Check if unzip available or not
if ! type "unzip" >> $LOG 2>&1; then
zypper --non-interactive install unzip >> $LOG 2>&1
fi
# Check if curl available or not
if ! type "curl" >> $LOG 2>&1; then
zypper --non-interactive install curl >> $LOG 2>&1
fi
fi
# Gentoo
if [ -n "$(command -v emerge)" ]; then
# Check if crontab is present or not available or not
if ! type "crontab" >> $LOG 2>&1; then
emerge cronie >> $LOG 2>&1
/etc/init.d/cronie start >> $LOG 2>&1
rc-update add cronie default >> $LOG 2>&1
fi
# Check if perl available or not
if ! type "perl" >> $LOG 2>&1; then
emerge perl >> $LOG 2>&1
fi
# Check if unzip available or not
if ! type "unzip" >> $LOG 2>&1; then
emerge unzip >> $LOG 2>&1
fi
# Check if curl available or not
if ! type "curl" >> $LOG 2>&1; then
emerge net-misc/curl >> $LOG 2>&1
fi
# Check if gzip available or not
if ! type "gzip" >> $LOG 2>&1; then
emerge gzip >> $LOG 2>&1
fi
fi
# Slackware
if [ -f "/etc/slackware-version" ]; then
if [ -n "$(command -v slackpkg)" ]; then
# Check if crontab is present or not available or not
if ! type "crontab" >> $LOG 2>&1; then
slackpkg -dialog=off -batch=on -default_answer=y install dcron >> $LOG 2>&1
fi
# Check if perl available or not
if ! type "perl" >> $LOG 2>&1; then
slackpkg -dialog=off -batch=on -default_answer=y install perl >> $LOG 2>&1
fi
# Check if unzip available or not
if ! type "unzip" >> $LOG 2>&1; then
slackpkg -dialog=off -batch=on -default_answer=y install infozip >> $LOG 2>&1
fi
# Check if curl available or not
if ! type "curl" >> $LOG 2>&1; then
slackpkg -dialog=off -batch=on -default_answer=y install curl >> $LOG 2>&1
fi
# Check if gzip available or not
if ! type "gzip" >> $LOG 2>&1; then
slackpkg -dialog=off -batch=on -default_answer=y install gzip >> $LOG 2>&1
fi
else
echo "Please install slackpkg and re-run installation."
exit 1;
fi
fi
# Is Cron available?
if [ ! -n "$(command -v crontab)" ]; then
echo "Cron is required but we could not install it."
echo "Exiting installer"
exit 1;
fi
# Is CURL available?
if [ ! -n "$(command -v curl)" ]; then
echo "CURL is required but we could not install it."
echo "Exiting installer"
exit 1;
fi
# Remove previous installation
if [ -f /opt/nmon/agent.sh ]; then
# Remove folder
rm -rf /opt/nmon
# Remove crontab
crontab -r -u nmonagent >> $LOG 2>&1
# Remove user
userdel nmonagent >> $LOG 2>&1
fi
### Install ###
mkdir -p /opt/nmon >> $LOG 2>&1
wget -O /opt/nmon/agent.sh $2/assets/agent.sh >> $LOG 2>&1
echo "$1" > /opt/nmon/serverkey
echo "$2/agent.php" > /opt/nmon/gateway
# Did it download ?
if ! [ -f /opt/nmon/agent.sh ]; then
echo "Unable to install!"
echo "Exiting installer"
exit 1;
fi
useradd nmonagent -r -d /opt/nmon -s /bin/false >> $LOG 2>&1
groupadd nmonagent >> $LOG 2>&1
# Disable cagefs for nmon
if [ -f /usr/sbin/cagefsctl ]; then
/usr/sbin/cagefsctl --disable nmonagent >> $LOG 2>&1
fi
# Modify user permissions
chown -R nmonagent:nmonagent /opt/nmon && chmod -R 700 /opt/nmon >> $LOG 2>&1
# Configure cron
crontab -u nmonagent -l 2>/dev/null | { cat; echo "* * * * * bash /opt/nmon/agent.sh > /opt/nmon/cron.log 2>&1"; } | crontab -u nmonagent -
echo " "
echo "-------------------------------------"
echo " Installation Completed "
echo "-------------------------------------"
# Attempt to delete this installer
if [ -f $0 ]; then
rm -f $0
fi