1c35a6b73c9d953ec8a2de95d292bc5eee3187ab
[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 let "skip=skip+1" >/dev/null
33 if [ "X"`tail -n +$skip $0 | $md5 | cut -b1-32 | tr A-Z a-z` != "X"$hash2 ]; then
34 echo Payload MD5 mismach
35 exit
36 fi
37
38 temp=`mktemp -d /tmp/nxinst.XXXXXX 2>/dev/null`
39 if [ $? != 0 ]; then
40 echo "Can't create temp dir"
41 exit 0
42 fi
43 tail -n +$skip $0 | gzip -dc 2>/dev/null | tar xf - -C $temp
44 if [ $? != 0 ]; then
45 echo "Can't unpack"
46 exit;
47 else
48 cd $temp
49 chmod +x ./$command
50 if [ $? != 0 ]; then
51 echo "Can't chmod $command"
52 exit
53 fi
54 ./$command
55 fi
56
57 exit
58 ###################################