solaris... userland tools... POSIX...
[public/netxms.git] / contrib / installAgent.sh
CommitLineData
ed73635e
AK
1#!/bin/sh
2
bdeffcb7
AK
3prefix=/opt/netxms
4config=/etc/nxagentd.conf
5e43ae16 5log=/tmp/nxagentupdate.log
bdeffcb7 6#prefix=/usr/local
ed73635e
AK
7configureAdd=
8
9##example #if [ `hostname --fqdn` = "host1.domain.tld" ]; then
10# prefix=/opt/nagios
11# configureAdd=--with-nice-option
12#fi
13
14###############################################################################
15#
16# Main code
17#
18
bdeffcb7
AK
19# process args
20while [ "x"$1 != "x" ]; do
21 name=`echo -n $1|cut -d= -f1`
22 val=`echo -n $1|cut -d= -f2`
23 eval $name=$val
24 shift
25done
26
9523ff5c 27make=`which gmake`
3e80aa9c
AK
28if [ $? = 0 ]; then
29 echo $make | grep "no gmake in " >/dev/null && make=make
30else
31 make=make
32fi
9523ff5c 33
ed73635e
AK
34case `uname -s` in
35 Linux)
36 pkill=killall
ed73635e 37 ;;
861fb447
VK
38 SunOS)
39 pkill=pkill
861fb447 40 ;;
ed73635e
AK
41 *BSD)
42 pkill=killall
ed73635e
AK
43 ;;
44 *)
45 pkill=pkill
ed73635e
AK
46 ;;
47esac
48
49cd `dirname $0`
50name=`ls netxms-*.tar.gz 2>/dev/null|sed s',\.tar\.gz$,,'`
51if [ "x$name" = "x" ]; then
5e43ae16 52 echo invalid package >> $log
ed73635e
AK
53 exit 1
54fi
55
3e80aa9c 56gzip -dc $name.tar.gz | tar xf - 2>/dev/null
ed73635e 57if [ $? != 0 ]; then
5e43ae16 58 echo invalid package >> $log
ed73635e
AK
59 exit 2
60fi
61cd $name
62if [ $? != 0 ]; then
5e43ae16 63 echo invalid package >> $log
ed73635e
AK
64 exit 3
65fi
66
74dd9f19
VK
67# ask nxagentd gently
68$pkill nxagentd 2>/dev/null
69# wait a few seconds and smash it down
70sleep 15 && $pkill -9 nxagentd 2>/dev/null
71
ed73635e 72# do configure
1216cc73 73./configure --prefix=$prefix --with-agent $configureAdd 2>/dev/null >/dev/null
ed73635e 74if [ $? != 0 ]; then
5e43ae16 75 echo configure failed, duh >> $log
74dd9f19 76 # Try to restart existing agent
5e43ae16 77 $prefix/bin/nxagentd -d -c $config >/dev/null 2>/dev/null
ed73635e
AK
78 exit 4
79fi
80
81# build
82$make >/dev/null 2>/dev/null
83if [ $? != 0 ]; then
5e43ae16 84 echo build failed, duh >> $log
74dd9f19 85 # Try to restart existing agent
5e43ae16 86 $prefix/bin/nxagentd -d -c $config >/dev/null 2>/dev/null
ed73635e
AK
87 exit 4
88fi
89
74dd9f19 90# now we can install it...
ed73635e
AK
91$make install >/dev/null 2>/dev/null
92if [ $? != 0 ]; then
5e43ae16 93 echo install failed >> $log
74dd9f19 94 # Try to restart existing agent
5e43ae16 95 $prefix/bin/nxagentd -d -c $config >/dev/null 2>/dev/null
ed73635e
AK
96 exit 5
97fi
98
62e9320f
AK
99# show config
100echo "config ($config):" >> $log
101cat $config >> $log 2>&1
102echo "---------------" >> $log
103
ed73635e 104# and restart
62e9320f
AK
105echo "Starting agent: $prefix/bin/nxagentd -d -c $config" >> $log
106$prefix/bin/nxagentd -d -c $config > $log.tmp 2>&1
107ret=$?
108if [ $ret != 0 ]; then
109 cat $log.tmp >> $log
110 rm -f $log.tmp
111 echo nxagentd not started \($ret\) >> $log
ed73635e
AK
112 exit 5
113fi
62e9320f 114rm -f $log.tmp