now it's like HP-UX-ready ;p
[public/netxms.git] / tools / stub.sh
1 #!/bin/sh
2
3 hash1=__HASH1__
4 hash2=__HASH2__
5 skip=__SKIP__
6 skip1=__SKIP1__
7 command=__COMMAND__
8 log=/tmp/nxagentupdate.log
9
10 wd=`pwd -P`
11
12 trap '
13 echo "Upgrade script finished" >> $log
14 cd $wd
15 [ "x"$temp != "x" ] && rm -rf $temp
16 exit
17 ' INT EXIT
18
19 rm -f $log
20 echo "WD = $wd" >> $log
21
22 _PATH=$PATH
23 PATH=$PATH:`echo /opt/openssl*/bin | tr ' ' ':'`
24 export PATH
25 md5=
26 for app in openssl md5sum md5;
27 do
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"
34 fi
35 fi
36 done
37 PATH=$_PATH
38 export PATH
39
40 tail="tail -n"
41 if [ `uname` = "SunOS" ]; then
42 tail=tail
43 mktemp() {
44 d=/tmp/nxupdate.$$.UniQ
45 mkdir $d && echo $d || false
46 }
47 fi
48
49 if [ "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
59
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
68 else
69 echo "No md5/md5sum/openssl found, can't check integrity" >> $log
70 fi
71
72 temp=`mktemp -d /tmp/nxinst.XXXXXX 2>/dev/null`
73 if [ $? != 0 ]; then
74 echo "Can't create temp dir" >> $log
75 exit 0
76 fi
77 cd $temp
78 $tail +$skip1 $wd/$0 | gzip -dc 2>/dev/null | tar xf -
79 if [ $? != 0 ]; then
80 echo "Can't unpack" >> $log
81 exit;
82 else
83 chmod +x ./$command
84 if [ $? != 0 ]; then
85 echo "Can't chmod $command" >> $log
86 exit
87 fi
88 echo Starting $command $*... >> $log
89 ./$command $* 2>&1 >> $log
90 fi
91
92 exit
93 ###################################