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