3443de0b89f6b9688ebec95d30e38718262c0f02
[public/netxms.git] / contrib / installAgent.sh
1 #!/bin/sh
2
3 prefix=/opt/netxms
4 configureAdd=
5
6 ##example #if [ `hostname --fqdn` = "host1.domain.tld" ]; then
7 # prefix=/opt/nagios
8 # configureAdd=--with-nice-option
9 #fi
10
11 ###############################################################################
12 #
13 # Main code
14 #
15
16 case `uname -s` in
17 Linux)
18 pkill=killall
19 make=make
20 ;;
21 *BSD)
22 pkill=killall
23 make=gmake
24 ;;
25 *)
26 pkill=pkill
27 make=gmake
28 ;;
29 esac
30
31 cd `dirname $0`
32 name=`ls netxms-*.tar.gz 2>/dev/null|sed s',\.tar\.gz$,,'`
33 if [ "x$name" = "x" ]; then
34 echo invalid package
35 exit 1
36 fi
37
38 tar zxf $name.tar.gz 2>/dev/null
39 if [ $? != 0 ]; then
40 echo invalid package
41 exit 2
42 fi
43 cd $name
44 if [ $? != 0 ]; then
45 echo invalid package
46 exit 3
47 fi
48
49 # do configure
50 ./configure --prefix=$prefix --with-agent $configureAdd >/dev/null
51 if [ $? != 0 ]; then
52 echo configure failed, duh
53 exit 4
54 fi
55
56 # build
57 $make >/dev/null 2>/dev/null
58 if [ $? != 0 ]; then
59 echo build failed, duh
60 exit 4
61 fi
62
63 # ask nxagentd gently
64 $pkill nxagentd 2>/dev/null
65 # wait a few seconds and smash it down
66 sleep 1 && $pkill -9 nxagentd 2>/dev/null
67
68 # now we can insall it...
69 $make install >/dev/null 2>/dev/null
70 if [ $? != 0 ]; then
71 echo install failed
72 exit 5
73 fi
74
75 # and restart
76 $prefix/bin/nxagentd -d >/dev/null 2>/dev/null
77 if [ $? != 0 ]; then
78 echo nxagentd not started
79 exit 5
80 fi