added Eclipse project for Tuxedo subagent
[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
ed73635e
AK
6configureAdd=
7
ed73635e
AK
8###############################################################################
9#
10# Main code
11#
12
bdeffcb7
AK
13# process args
14while [ "x"$1 != "x" ]; do
02d6e024
AK
15 name=`echo $1|cut -d= -f1`
16 val=`echo $1|cut -d= -f2`
dfa81f4b
VK
17 if [ "x$name" = "xopt" ]; then
18 configureAdd="$configureAdd $val"
19 else
20 eval $name=$val
21 fi
bdeffcb7
AK
22 shift
23done
24
9523ff5c 25make=`which gmake`
3e80aa9c
AK
26if [ $? = 0 ]; then
27 echo $make | grep "no gmake in " >/dev/null && make=make
28else
29 make=make
30fi
9523ff5c 31
ed73635e 32case `uname -s` in
861fb447 33 SunOS)
78821e2f
AK
34 KILLALL() {
35 pkill $*
36 }
ed73635e 37 ;;
78821e2f
AK
38 AIX|HP-UX)
39 KILLALL() {
40 pids=`/usr/bin/ps -ef | grep $2 | grep -v grep | awk '{ print $2 }'`
41 [ ! -z "$pids" ] && kill $1 $pids
42 }
ed73635e 43 ;;
e1ca00b2
AK
44 *)
45 KILLALL() {
46 killall $*
47 }
48 ;;
ed73635e
AK
49esac
50
51cd `dirname $0`
52name=`ls netxms-*.tar.gz 2>/dev/null|sed s',\.tar\.gz$,,'`
53if [ "x$name" = "x" ]; then
c0b41956 54 echo invalid package >>$log
ed73635e
AK
55 exit 1
56fi
57
3e80aa9c 58gzip -dc $name.tar.gz | tar xf - 2>/dev/null
ed73635e 59if [ $? != 0 ]; then
38656df9 60 echo Unable to unpack >>$log
ed73635e
AK
61 exit 2
62fi
63cd $name
64if [ $? != 0 ]; then
38656df9 65 echo Unable to change working dir >>$log
ed73635e
AK
66 exit 3
67fi
68
74dd9f19 69# ask nxagentd gently
78821e2f 70KILLALL -15 nxagentd >>$log 2>&1
74dd9f19 71# wait a few seconds and smash it down
78821e2f 72sleep 15 && KILLALL -9 nxagentd >>$log 2>&1
74dd9f19 73
ed73635e 74# do configure
a74d4e63 75./configure --prefix=$prefix --with-agent --with-internal-libtre $configureAdd >>$log 2>&1
78821e2f 76 if [ $? != 0 ]; then
c0b41956 77 echo configure failed, restarting old agent >>$log
78821e2f
AK
78 # Try to restart existing agent
79 $prefix/bin/nxagentd -d -c $config >>$log 2>&1
ed73635e
AK
80 exit 4
81fi
82
a74d4e63
VK
83# move old libs to prevent linker errors
84rm -rf $prefix/lib.bak
85mv $prefix/lib $prefix/lib.bak
86
ed73635e 87# build
c0b41956 88$make >>$log 2>&1
ed73635e 89if [ $? != 0 ]; then
6e320944 90 echo build failed, restarting old agent >>$log
a74d4e63
VK
91 # restore lib dir
92 rm -rf $prefix/lib
93 mv $prefix/lib.bak $prefix/lib
78821e2f
AK
94 # Try to restart existing agent
95 $prefix/bin/nxagentd -d -c $config >>$log 2>&1
ed73635e
AK
96 exit 4
97fi
98
74dd9f19 99# now we can install it...
c0b41956 100$make install >>$log 2>&1
ed73635e 101if [ $? != 0 ]; then
c0b41956 102 echo install failed, restarting old agent >>$log
a74d4e63
VK
103 # restore lib dir
104 rm -rf $prefix/lib
105 mv $prefix/lib.bak $prefix/lib
78821e2f
AK
106 # Try to restart existing agent
107 $prefix/bin/nxagentd -d -c $config >>$log 2>&1
ed73635e
AK
108 exit 5
109fi
110
62e9320f 111# show config
c0b41956
AK
112echo "config ($config):" >>$log
113cat $config >>$log 2>&1
114echo "---------------" >>$log
62e9320f 115
ed73635e 116# and restart
c0b41956
AK
117echo "Starting agent: $prefix/bin/nxagentd -d -c $config" >>$log
118$prefix/bin/nxagentd -d -c $config >>$log 2>&1
62e9320f
AK
119ret=$?
120if [ $ret != 0 ]; then
c0b41956 121 echo nxagentd not started \($ret\) >>$log
ed73635e
AK
122 exit 5
123fi
a74d4e63
VK
124
125# remove old and temporary files
126rm -rf $prefix/lib.bak
62e9320f 127rm -f $log.tmp