File: pandora_agent_installer

package info (click to toggle)
pandorafms-agent 4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 540 kB
  • ctags: 76
  • sloc: perl: 2,924; sh: 865; makefile: 8
file content (519 lines) | stat: -rwxr-xr-x 17,511 bytes parent folder | download | duplicates (2)
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
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
#!/bin/sh
#trap 'echo error at line $LINENO 1>&2' ERR
set -u
set -e

# **********************************************************************
# Pandora FMS Agent Installer for Unix (generic installer)
# (c) 2008-2013 Artica ST
# (c) 2008-2013 Sancho Lerena <slerena@gmail.com>
# 
# This is a generic installer for all Unix-like systems.(AIX, HP-UX, SunOS, Linux, FreeBSD)
# Please see http://www.pandorafms.org. This code is licensed under GPL 2.0 license.
# **********************************************************************

PI_VERSION=4.0.3s
PI_BUILD=130108
OS_NAME=`uname -s`

FORCE=0
LOG_TIMESTAMP=`date +"%Y/%m/%d %H:%M:%S"`
PANDORA_HOME=/usr/share/pandora_agent
PANDORA_BIN=/usr/bin/pandora_agent
PANDORA_EXEC_BIN=/usr/bin/pandora_agent_exec
PANDORA_TEMP=/var/spool/pandora
PANDORA_CFG=/etc/pandora
PANDORA_LOG_DIR=/var/log/pandora
PANDORA_LOG=pandora_agent.log
TENTACLE=/usr/bin/tentacle_client
TENTACLE_SERVER=/usr/bin/tentacle_server
PANDORA_MAN=/usr/share/man

MODE=${1:-}
PANDORA_BASE=`echo ${2:-} | sed -e 's/\/$//'`
if [ "${3:-}" != "" ]
then
	PANDORA_USER=$3
else
	PANDORA_USER="root"
fi

# Check for Perl 5.6.x or higher available
PERL_VERSION=`perl -v | egrep 'v5.6|v5.7|v5.8|v5.9|v5.1[0-9]' | grep perl`

if [ -z "$PERL_VERSION" ]
then
	echo "Perl 5.6.x or higher is not detected. This is required for Pandora FMS" 1>&2
	echo "Detected: $PERL_VERSION " 1>&2
	echo "Aborting install..." 1>&2
	exit 2
fi

UNIX_KIND=`uname -s`
if [ -z "`echo Linux HP-UX SunOS AIX Solaris Darwin BSD bsd FreeBSD | grep \"$UNIX_KIND\"`" ]
then
	echo "This system: '$UNIX_KIND' is not supported by this script" 1>&2
	echo "Please make the install yourself as it's described in documentation" 1>&2
	exit 1
fi


# check for root to do the install
if [ -z "`id | grep \"uid=0(root)\"`" ]
then
	echo "You need to be root to do the install. Please made a manual install" 1>&2
	echo "if you want to install Pandora FMS agent without root" 1>&2
	echo " " 1>&2
	echo "Aborting install" 1>&2
	exit 2
fi

help () {
	cat <<EOF
Syntax:

    ./pandora_agent_installer < --mode > [ destination_path ] [ user_to_run_as ]
 
Modes:
 
  --force-install      To force installation if already installed on system
  --install            To install Pandora FMS Agent on this system
  --uninstall          To uninstall/remove Pandora FMS Agent on this System
 
Some exaples of how to use the installer:
 
   ./pandora_agent_installer --install
   ./pandora_agent_installer --install /opt/pandora
   ./pandora_agent_installer --install "" pandora
   ./pandora_agent_installer --uninstall /opt/pandora
 
EOF
}

uninstall () {
	OS_NAME=`uname -s`
	if [ "$OS_NAME" = "FreeBSD" ]
	then
		PANDORA_HOME=/usr/local/share/pandora_agent
		PANDORA_BIN=/usr/local/bin/pandora_agent
		PANDORA_EXEC_BIN=/usr/local/bin/pandora_agent_exec
		PANDORA_CFG=/usr/local/etc/pandora
		TENTACLE=/usr/local/bin/tentacle_client
		TENTACLE_SERVER=/usr/local/bin/tentacle_server
		PANDORA_MAN=/usr/local/man
	fi

	echo "Removing Pandora FMS Agent..."
	rm -Rf $PANDORA_BASE$PANDORA_BIN 2> /dev/null
	rm -Rf $PANDORA_BASE$PANDORA_EXEC_BIN 2> /dev/null
	
	#Test if exist Pandora Server in this machine
	if [ -d $PANDORA_BASE$PANDORA_TEMP/data_in ]
	then
		echo "You have a Pandora Server in this machine. Then don't delete "$PANDORA_TEMP
		rm -Rf $PANDORA_BASE$PANDORA_TEMP/data_out 2> /dev/null
	else
		rm -Rf $PANDORA_BASE$PANDORA_TEMP 2> /dev/null
		rm -Rf $PANDORA_BASE$TENTACLE_SERVER 2> /dev/null
	fi 
	rm -Rf $PANDORA_BASE$PANDORA_CFG/pandora_agent.conf 2> /dev/null
	
	rm -Rf $PANDORA_BASE/etc/init.d/pandora_agent_daemon 2> /dev/null
	rm -Rf $PANDORA_BASE/sbin/init.d/pandora_agent_daemon 2> /dev/null
	rm -Rf $PANDORA_BASE/etc/rc.pandora_agent_daemon 2> /dev/null
	rm -Rf $PANDORA_BASE/etc/rc?.d/S90pandora_agent_daemon 2> /dev/null
	rm -Rf $PANDORA_BASE/sbin/rc?.d/S90pandora_agent_daemon 2> /dev/null
	rm -Rf $PANDORA_BASE/etc/rc?.d/S90pandora_agent 2> /dev/null
	rm -Rf $PANDORA_BASE/sbin/rc?.d/S90pandora_agent 2> /dev/null
	rm -Rf $PANDORA_BASE/etc/rc.d/rc?.d/S90pandora_agent_daemon 2> /dev/null
	rm -Rf $PANDORA_BASE/etc/rc.d/rc?.d/S90pandora_agent 2> /dev/null
	rm -Rf $PANDORA_BASE/usr/local/etc/rc.d/pandora_agent 2> /dev/null
	rm -Rf /etc/init.d/pandora_agent_daemon 2> /dev/null
	rm -Rf /sbin/init.d/pandora_agent_daemon 2> /dev/null
	rm -Rf /etc/rc.pandora_agent_daemon 2> /dev/null
	rm -Rf /etc/rc?.d/S90pandora_agent_daemon 2> /dev/null
	rm -Rf /sbin/rc?.d/S90pandora_agent_daemon 2> /dev/null
	rm -Rf /etc/rc?.d/S90pandora_agent 2> /dev/null
	rm -Rf /sbin/rc?.d/S90pandora_agent 2> /dev/null
	rm -Rf /etc/rc.d/rc?.d/S90pandora_agent_daemon 2> /dev/null
	rm -Rf /etc/rc.d/rc?.d/S90pandora_agent 2> /dev/null
	rm -Rf /usr/local/etc/rc.d/pandora_agent 2> /dev/null
	
	rm -Rf $PANDORA_BASE$PANDORA_HOME 2> /dev/null
	rm -Rf $PANDORA_BASE$PANDORA_LOG_DIR 2> /dev/null
	rm -Rf $PANDORA_BASE$TENTACLE 2> /dev/null

	rm -Rf $PANDORA_BASE$PANDORA_MAN/{man1,cat1}/tentacle_client.1.gz 2> /dev/null
	rm -Rf $PANDORA_BASE$PANDORA_MAN/{man1,cat1}/pandora_agent.1.gz 2> /dev/null

	# Skip delete of /etc/pandora if exists configuration of a server
	if [ ! -f $PANDORA_BASE/$PANDORA_CFG/pandora_server.conf ]
	then
		rm -Rf $PANDORA_BASE/$PANDORA_CFG 2> /dev/null
	fi

	if [ ! -z "$PANDORA_BASE" ]
	then
		echo "Please delete manually $PANDORA_BASE for complete uninstall"
	fi

	echo " "
	echo "Done"
}

install () {

	OS_VERSION=`uname -r`
	OS_NAME=`uname -s`
	OLDFILENAMETMP=`date +"%Y-%m-%d"`

	if [ "$OS_NAME" = "FreeBSD" ]
	then
		PANDORA_HOME=/usr/local/share/pandora_agent
		PANDORA_BIN=/usr/local/bin/pandora_agent
		PANDORA_EXEC_BIN=/usr/local/bin/pandora_agent_exec
		PANDORA_CFG=/usr/local/etc/pandora
		TENTACLE=/usr/local/bin/tentacle_client
		TENTACLE_SERVER=/usr/local/bin/tentacle_server
		PANDORA_MAN=/usr/local/man
	fi

	echo "Detecting Unix distribution: $OS_NAME version $OS_VERSION"
	if [ -f $PANDORA_BASE$PANDORA_HOME ] && [ "$FORCE" = "0" ]
	then
		echo "Seems that default dir already exists. Please use --force-install to" 1>&2
		echo "force installer to install on $PANDORA_BASE$PANDORA_HOME" 1>&2
		exit 1
	else
		echo "Checking default dir $PANDORA_BASE$PANDORA_HOME..."
	fi

	if [ -f $PANDORA_BASE$PANDORA_BIN ] && [ "$FORCE" = "0" ]
	then
		echo "Seems that $PANDORA_BASE$PANDORA_BIN already exists. Please use --force-install to" 1>&2
		echo "force installer to reinstall overwriting it" 1>&2
		echo " " 1>&2
		exit 1
	else
		echo "Checking Pandora FMS Agent on $PANDORA_BASE$PANDORA_BIN...."
	fi

	# Alter dynamically the daemon launcher and setup the new path 
	# if PANDORA_BASE is customized.

	if [ ! -z "$PANDORA_BASE" ]
	then
		if [ "$OS_NAME" = "FreeBSD" ]
		then
			DAEMON_SCRIPT=FreeBSD/pandora_agent
			DAEMON_TEMP=pandora_agent_daemon_temp
		else
			DAEMON_SCRIPT=pandora_agent_daemon
			DAEMON_TEMP=pandora_agent_daemon_temp
		fi
		
		# Backup the daemon script
		cp -f "$DAEMON_SCRIPT" "$DAEMON_SCRIPT.bak"
		
		AGENT_CFG=$OS_NAME/pandora_agent.conf
		AGENT_CFG_TEMP=$OS_NAME/pandora_agent.conf.temp

		# Check existence.
		if [ ! -r "$AGENT_CFG" ]; then
			echo "There is no default agent for the platform $OS_NAME. Please create one as $OS_NAME/pandora_agent.conf and send it to Pandora." 1>&2
			exit 1
		fi

		# Backup the configuration file
		cp -f "$AGENT_CFG" "$AGENT_CFG.bak"

		echo $PANDORA_BASE > PANDORA_BASE.temp
		sed 's/\//\\\//g' PANDORA_BASE.temp > PANDORA_BASE.temp2

		PANDORA_BASE_DECODED=`cat PANDORA_BASE.temp2`
		rm PANDORA_BASE.temp PANDORA_BASE.temp2

		if [ "$OS_NAME" = "FreeBSD" ]
		then
			sed -e "s/^PATH\=[.]*/PATH\=$PANDORA_BASE_DECODED\/usr\/local\/bin\:/g" $DAEMON_SCRIPT > $DAEMON_TEMP
			mv $DAEMON_TEMP $DAEMON_SCRIPT

			sed -e "s/^command\=[.]*/command\=$PANDORA_BASE_DECODED/g" $DAEMON_SCRIPT > $DAEMON_TEMP
			mv $DAEMON_TEMP $DAEMON_SCRIPT

			sed -e 's/^command_args\=\"[.]*/command_args\=\"$PANDORA_BASE_DECODED/g' $DAEMON_SCRIPT > $DAEMON_TEMP
			mv $DAEMON_TEMP $DAEMON_SCRIPT

			sed -e 's/^required_files\=\"[.]*/required_files\=\"$PANDORA_BASE_DECODED/g' $DAEMON_SCRIPT > $DAEMON_TEMP
			mv $DAEMON_TEMP $DAEMON_SCRIPT
		else
			sed -e "s/^PATH\=[.]*/PATH\=$PANDORA_BASE_DECODED\/usr\/bin\:/g" $DAEMON_SCRIPT > $DAEMON_TEMP
			mv  $DAEMON_TEMP $DAEMON_SCRIPT

			sed -e "s/^PANDORA_PATH\=[.]*/PANDORA_PATH\=$PANDORA_BASE_DECODED/g"  $DAEMON_SCRIPT > $DAEMON_TEMP
			mv  $DAEMON_TEMP $DAEMON_SCRIPT

			sed -e "s/^LOGFILE\=[.]*/LOGFILE\=$PANDORA_BASE_DECODED/g"  $DAEMON_SCRIPT > $DAEMON_TEMP
			mv  $DAEMON_TEMP $DAEMON_SCRIPT

			sed -e "s/^DAEMON\=[.]*/DAEMON\=$PANDORA_BASE_DECODED/g"  $DAEMON_SCRIPT > $DAEMON_TEMP
			mv  $DAEMON_TEMP $DAEMON_SCRIPT
 
			sed -e "s/^PANDORA_USER\=.*/PANDORA_USER\=$PANDORA_USER/g"  $DAEMON_SCRIPT > $DAEMON_TEMP
			mv  $DAEMON_TEMP $DAEMON_SCRIPT
		fi

		sed -e "s/^temporal [.]*/temporal $PANDORA_BASE_DECODED/g" $AGENT_CFG > $AGENT_CFG_TEMP
		mv $AGENT_CFG_TEMP $AGENT_CFG

		sed -e "s/^logfile [.]*/logfile $PANDORA_BASE_DECODED/g" $AGENT_CFG > $AGENT_CFG_TEMP
		mv $AGENT_CFG_TEMP $AGENT_CFG
	fi
	echo "Creating Pandora FMS Agent home directory at $PANDORA_BASE$PANDORA_HOME"
	if [ ! -z "$PANDORA_BASE" ]
	then
		mkdir -p $PANDORA_BASE 2> /dev/null
		mkdir -p $PANDORA_BASE/var/log 2> /dev/null
		mkdir -p $PANDORA_BASE/$PANDORA_MAN/man1 2> /dev/null
		if [ "$OS_NAME" = "FreeBSD" ]
		then
			mkdir -p $PANDORA_BASE/usr/local/bin 2> /dev/null
		else
			mkdir -p $PANDORA_BASE/usr/bin 2> /dev/null
		fi
	fi

	mkdir -p $PANDORA_BASE$PANDORA_HOME 2> /dev/null

	# Create directories based on PANDORA_BASE 

	mkdir -p $PANDORA_BASE/tmp 2> /dev/null
	mkdir -p $PANDORA_BASE$PANDORA_TEMP/data_out 2> /dev/null
	mkdir -p $PANDORA_BASE$PANDORA_CFG 2> /dev/null
	mkdir -p $PANDORA_BASE$PANDORA_LOG_DIR 2> /dev/null

	# Set the user the agent will run as
	if [ "$PANDORA_USER" != "root" ]
	then
		sed -e "s/.*pandora_user .*/pandora_user $PANDORA_USER/" $AGENT_CFG > $AGENT_CFG_TEMP 2> /dev/null && \
		mv $AGENT_CFG_TEMP $AGENT_CFG
		chmod 755 pandora_agent_daemon
		chown -R $PANDORA_USER $PANDORA_BASE
	fi

	# Create logfile
	if [ ! -z "`touch $PANDORA_BASE$PANDORA_LOG_DIR/$PANDORA_LOG`" ]
	then
		echo "Seems to be a problem generating logfile ($PANDORA_BASE$PANDORA_LOG_DIR/$PANDORA_LOG) please check it";
	else
		echo "Created logfile at $PANDORA_BASE$PANDORA_LOG_DIR/$PANDORA_LOG..."
	fi
	echo "$LOG_TIMESTAMP Pandora FMS installer has created this file at startup" > $PANDORA_BASE$PANDORA_LOG_DIR/$PANDORA_LOG

	# Copying agent and securing it
	echo "Copying Pandora FMS Agent to $PANDORA_BASE$PANDORA_BIN..."
	cp pandora_agent $PANDORA_BASE$PANDORA_BIN
	chmod 755 $PANDORA_BASE$PANDORA_BIN
	cp pandora_agent_exec $PANDORA_BASE$PANDORA_EXEC_BIN
	chmod 755 $PANDORA_BASE$PANDORA_EXEC_BIN
	chown $PANDORA_USER:0 $PANDORA_BASE$PANDORA_BIN
	chown $PANDORA_USER:0 $PANDORA_BASE$PANDORA_EXEC_BIN

	echo "Copying Pandora FMS Agent configuration file to $PANDORA_BASE$PANDORA_CFG/pandora_agent.conf..."
	if [ -f $PANDORA_BASE/$PANDORA_CFG/pandora_agent.conf ]
	then
		cp $PANDORA_BASE/$PANDORA_CFG/pandora_agent.conf $PANDORA_BASE/$PANDORA_CFG/pandora_agent.conf.$OLDFILENAMETMP
		echo "Backing up old configuration file to $PANDORA_BASE/$PANDORA_CFG/pandora_agent.conf.$OLDFILENAMETMP"
	fi

	echo "Copying Pandora FMS Agent plugins to $PANDORA_BASE$PANDORA_HOME/plugins..."
	cp -r plugins $PANDORA_BASE$PANDORA_HOME
	chmod -R 700 $PANDORA_BASE$PANDORA_HOME/plugins
	ln -sf $PANDORA_BASE$PANDORA_HOME/plugins $PANDORA_BASE$PANDORA_CFG

	echo "Copying Pandora FMS Agent collections to $PANDORA_BASE$PANDORA_HOME/collections..."
	cp -r collections $PANDORA_BASE$PANDORA_HOME
	chmod -R 700 $PANDORA_BASE$PANDORA_HOME/collections
	ln -sf $PANDORA_BASE$PANDORA_HOME/collections $PANDORA_BASE$PANDORA_CFG
	
	echo "Copying tentacle server to $PANDORA_BASE$TENTACLE_SERVER"
	cp tentacle_server $PANDORA_BASE$TENTACLE_SERVER
	chmod 755 $PANDORA_BASE$TENTACLE_SERVER	
	chown $PANDORA_USER:0 $PANDORA_BASE$TENTACLE_SERVER
	
	echo "Copying tentacle client to $PANDORA_BASE$TENTACLE"
	cp tentacle_client $PANDORA_BASE$TENTACLE
	chmod 755 $PANDORA_BASE$TENTACLE
	chown $PANDORA_USER:0 $PANDORA_BASE$TENTACLE	

	echo "Installing the Pandora Agent and Tentacle Client manuals"
	cp man/man1/tentacle_client.1.gz $PANDORA_BASE/$PANDORA_MAN/man1
	chmod 644 $PANDORA_BASE/$PANDORA_MAN/man1/tentacle_client.1.gz
	cp man/man1/pandora_agent.1.gz $PANDORA_BASE/$PANDORA_MAN/man1
	chmod 644 $PANDORA_BASE/$PANDORA_MAN/man1/pandora_agent.1.gz

	echo "Setting secure permissions and ownership for all Pandora FMS Agent files..."
	chown -R $PANDORA_USER $PANDORA_BASE$PANDORA_HOME
	chmod -R 700 $PANDORA_BASE$PANDORA_TEMP/data_out
	chmod 711 $PANDORA_BASE$PANDORA_LOG_DIR
	chmod 640 $PANDORA_BASE$PANDORA_LOG_DIR/$PANDORA_LOG
	chown $PANDORA_USER:0 $PANDORA_BASE$PANDORA_LOG_DIR/$PANDORA_LOG
	if [ "$OS_NAME" = "FreeBSD" ]
	then
		chown $PANDORA_USER:daemon $PANDORA_BASE$PANDORA_TEMP
		chmod -R 770 $PANDORA_BASE$PANDORA_TEMP
		chmod 775 $PANDORA_BASE$PANDORA_TEMP
	fi

	echo "Copying default agent configuration to $PANDORA_BASE$PANDORA_CFG/pandora_agent.conf"
	# Check existence.
	if [ ! -r "$OS_NAME/pandora_agent.conf" ]; then
		echo "There is no default agent for the platform $OS_NAME. Please create one as $OS_NAME/pandora_agent.conf and send it to Pandora." 1>&2
		exit 1
	fi

	cp $OS_NAME/pandora_agent.conf $PANDORA_BASE$PANDORA_CFG/pandora_agent.conf
	chmod 600 $PANDORA_BASE$PANDORA_CFG/pandora_agent.conf
	chown $PANDORA_USER $PANDORA_BASE$PANDORA_CFG/pandora_agent.conf

	if [ "$OS_NAME" = "FreeBSD" ]
	then
		echo "Linking start-up daemon script 'pandora_agent' on $OS_NAME";
	else
		echo "Linking start-up daemon script 'pandora_agent_daemon' on $OS_NAME";
	fi

	if [ "$OS_NAME" = "AIX" ]
	then
		cp pandora_agent_daemon /etc/rc.pandora_agent_daemon		
		ln -sf /etc/rc.pandora_agent_daemon /etc/rc.d/rc2.d/S90pandora_agent_daemon
		chmod 755 $PANDORA_STARTUP
		chown root:0 $PANDORA_STARTUP
		echo "Pandora FMS agent has been included in /etc/rc.d/rc2.d/S90pandora_agent_daemon"
	fi
	
	if [ $OS_NAME = "HP-UX" ]
	then
		PANDORA_STARTUP=/sbin/init.d/pandora_agent_daemon
		cp pandora_agent_daemon $PANDORA_STARTUP
		ln -sf /sbin/init.d/pandora_agent_daemon /sbin/rc3.d/S90pandora_agent_daemon 2> /dev/null
		ln -sf /sbin/init.d/pandora_agent_daemon /sbin/rc2.d/S90pandora_agent_daemon 2> /dev/null
		chmod 755 $PANDORA_STARTUP
		chown root:0 $PANDORA_STARTUP
		echo "Pandora FMS agent has been included in /sbin/rcX.d/S90pandora_agent_daemon"
	fi
	
	if [ $OS_NAME = "Darwin" ]
	then
		cp $OS_NAME/com.pandorafms.pandorafms.plist /Library/LaunchDaemons
		echo "Pandora FMS agent has been included in /Library/LaunchDaemons"
		PANDORA_STARTUP=/Library/LaunchDaemons
		echo "To start now: launchctl load -w /Library/LaunchDaemons/com.pandorafms.pandorafms.plist"
	fi
	
	if [ $OS_NAME = "SunOS" ]
	then
		PANDORA_STARTUP=/etc/init.d/pandora_agent_daemon
		cp pandora_agent_daemon $PANDORA_STARTUP 
		ln -sf /etc/init.d/pandora_agent_daemon /etc/rc2.d/S90pandora_agent_daemon 2> /dev/null
		chmod 755 $PANDORA_STARTUP
		chown root:0 $PANDORA_STARTUP
		echo "Pandora FMS agent has been included in /etc/rc2.d/S90pandora_agent_daemon"
	fi
	
	if [ $OS_NAME = "Linux" ]
	then
		PANDORA_STARTUP=/etc/init.d/pandora_agent_daemon
		cp pandora_agent_daemon $PANDORA_STARTUP
		if [ -d /etc/rc.d/ ]
		then
			ln -sf /etc/init.d/pandora_agent_daemon /etc/rc.d/rc2.d/S90pandora_agent 2> /dev/null
			ln -sf /etc/init.d/pandora_agent_daemon /etc/rc.d/rc3.d/S90pandora_agent 2> /dev/null
		else
			ln -sf /etc/init.d/pandora_agent_daemon /etc/rc2.d/S90pandora_agent 2> /dev/null
			ln -sf /etc/init.d/pandora_agent_daemon /etc/rc2.d/S90pandora_agent 2> /dev/null
		fi
		chmod 755 $PANDORA_STARTUP
		chown root:0 $PANDORA_STARTUP
	fi

	if [ "$OS_NAME" = "FreeBSD" ]
	then
		PANDORA_STARTUP=/usr/local/etc/rc.d/pandora_agent
		cp FreeBSD/pandora_agent $PANDORA_STARTUP
		chmod 555 $PANDORA_STARTUP
		chown root:wheel $PANDORA_STARTUP
	fi

	echo "Done."
	echo " "
	echo "You have your startup script ready at $PANDORA_STARTUP"
	echo " "
	echo "Tentacle is the default transfer mode since 2.0 version."
	echo " "
	echo "If you want to use SSH, firstly you need to copy your public SSH keys "
	echo " ($HOME/.ssh/id_dsa) under /home/pandora/.ssh/authorized_keys "
	echo "on your Pandora FMS Server host"
	echo " "
	echo "You also need to setup your $PANDORA_BASE$PANDORA_CFG/pandora_agent.conf config file"
	echo " "
	if [ "$OS_NAME" = "FreeBSD" ]
	then
		echo "Define 'pandora_agent_enable=\"YES\"' in /etc/rc.conf to enable the daemon."
	else
		echo "Check your startup configuration to be sure Pandora FMS Agent is ready "
		echo "to start automatically when system restarts":
	fi

	# Restore the daemon script
        if [ ! -z "${DAEMON_SCRIPT:-}" ]; then
		cp -f "$DAEMON_SCRIPT.bak" "$DAEMON_SCRIPT" >/dev/null 2>&1
		rm -f "$DAEMON_SCRIPT.bak" >/dev/null 2>&1
	fi

	# Restore the configuration file
        if [ ! -z "${AGENT_CFG:-}" ]; then
		cp -f "$AGENT_CFG.bak" "$AGENT_CFG" >/dev/null 2>&1
		rm -f "$AGENT_CFG.bak" >/dev/null 2>&1
	fi

}

if [ ! -f "pandora_agent" ]
then
	echo " " 1>&2
	echo "Execute installer from the directory where you have your files. " 1>&2
	help 1>&2
	exit 1
fi

# Script banner at start
echo " "
echo "Pandora FMS Agent UNIX Installer $PI_VERSION $PI_BUILD (c) 2008-2013 ArticaST"
echo "This program is licensed under GPL2 Terms. http://pandorafms.com"
echo " "


case "$MODE" in

'--force-install')
	FORCE=1
	install
	exit 0
	;;

'--install')
	install
	exit 0
	;;

'--uninstall')
	uninstall
	exit 0
	;;

*)
	help
	;;
esac