now it's like HP-UX-ready ;p
[public/netxms.git] / tools / stub.sh
CommitLineData
b78936e5
AK
1#!/bin/sh
2
3hash1=__HASH1__
4hash2=__HASH2__
5skip=__SKIP__
3e80aa9c 6skip1=__SKIP1__
b78936e5 7command=__COMMAND__
5e43ae16 8log=/tmp/nxagentupdate.log
b78936e5 9
3e80aa9c
AK
10wd=`pwd -P`
11
b78936e5 12trap '
861fb447 13 echo "Upgrade script finished" >> $log
3e80aa9c 14 cd $wd
2dad1e4c 15 [ "x"$temp != "x" ] && rm -rf $temp
b78936e5
AK
16 exit
17' INT EXIT
18
5e43ae16 19rm -f $log
2f06a66e 20echo "WD = $wd" >> $log
861fb447 21
3e80aa9c
AK
22_PATH=$PATH
23PATH=$PATH:`echo /opt/openssl*/bin | tr ' ' ':'`
24export PATH
25md5=
26for app in openssl md5sum md5;
27do
28 tmp=`which $app 2>/dev/null`
29 if [ $? = 0 ]; then
30 echo $tmp | grep "no $app in " >/dev/null 2>&1
31 if [ $? != 0 ]; then
32 md5=$tmp
33 [ $app = "openssl" ] && md5="$md5 md5"
b78936e5 34 fi
b78936e5 35 fi
3e80aa9c
AK
36done
37PATH=$_PATH
38export PATH
b78936e5 39
3e80aa9c
AK
40tail="tail -n"
41if [ `uname` = "SunOS" ]; then
42 tail=tail
43 mktemp() {
44 d=/tmp/nxupdate.$$.UniQ
45 mkdir $d && echo $d || false
46 }
b78936e5 47fi
1216cc73 48
3e80aa9c
AK
49if [ "x$md5" != "x" ]; then
50 if [ "X"`head -n$skip $0 |
51 $tail +5 |
52 $md5 |
53 cut -b1-32 |
54 tr A-Z a-z` != "X"$hash1 ];
55 then
56 echo "Script MD5 mismach" >> $log
57 exit
58 fi
1216cc73 59
3e80aa9c
AK
60 if [ "X"`$tail +$skip1 $0 |
61 $md5 |
62 cut -b1-32 |
63 tr A-Z a-z` != "X"$hash2 ];
64 then
65 echo "Payload MD5 mismach" >> $log
66 exit
67 fi
68else
69 echo "No md5/md5sum/openssl found, can't check integrity" >> $log
b78936e5
AK
70fi
71
72temp=`mktemp -d /tmp/nxinst.XXXXXX 2>/dev/null`
73if [ $? != 0 ]; then
861fb447 74 echo "Can't create temp dir" >> $log
b78936e5
AK
75 exit 0
76fi
3e80aa9c
AK
77cd $temp
78$tail +$skip1 $wd/$0 | gzip -dc 2>/dev/null | tar xf -
b78936e5 79if [ $? != 0 ]; then
861fb447 80 echo "Can't unpack" >> $log
b78936e5
AK
81 exit;
82else
2dad1e4c
AK
83 chmod +x ./$command
84 if [ $? != 0 ]; then
861fb447 85 echo "Can't chmod $command" >> $log
2dad1e4c
AK
86 exit
87 fi
de31a623
AK
88 echo Starting $command $*... >> $log
89 ./$command $* 2>&1 >> $log
b78936e5
AK
90fi
91
92exit
93###################################