condTimedWait fixed
[public/netxms.git] / tools / stub.sh
1 #!/bin/sh
2
3 hash1=__HASH1__
4 hash2=__HASH2__
5 skip=__SKIP__
6 command=__COMMAND__
7
8 trap '
9 echo Cleanup...
10 [ "x"$temp != "x" ] && rm -rf $temp
11 exit
12 ' INT EXIT
13
14 md5=`which md5 2>/dev/null`
15 if [ $? != 0 ]; then
16 md5=`which md5sum 2>/dev/null`
17 if [ $? != 0 ]; then
18 md5=`which openssl 2>/dev/null`
19 if [ $? != 0 ]; then
20 echo "Can't calculate MD5, exiting"
21 exit
22 else
23 md5="$md5 md5"
24 fi
25 fi
26 fi
27
28 if [ "X"`head -n$skip $0 | tail -n +5 | $md5 | cut -b1-32 | tr A-Z a-z` != "X"$hash1 ]; then
29 echo Script MD5 mismach
30 exit
31 fi
32
33 let "skip=skip+1" 2>/dev/null
34 if [ $? != 0 ]; then
35 # real sh?
36 skip=`let "$skip+1"`
37 fi
38
39 if [ "X"`tail -n +$skip $0 | $md5 | cut -b1-32 | tr A-Z a-z` != "X"$hash2 ]; then
40 echo Payload MD5 mismach
41 exit
42 fi
43
44 temp=`mktemp -d /tmp/nxinst.XXXXXX 2>/dev/null`
45 if [ $? != 0 ]; then
46 echo "Can't create temp dir"
47 exit 0
48 fi
49 tail -n +$skip $0 | gzip -dc 2>/dev/null | tar xf - -C $temp
50 if [ $? != 0 ]; then
51 echo "Can't unpack"
52 exit;
53 else
54 cd $temp
55 chmod +x ./$command
56 if [ $? != 0 ]; then
57 echo "Can't chmod $command"
58 exit
59 fi
60 ./$command
61 fi
62
63 exit
64 ###################################