bugfix
[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`
15 if [ $? != 0 ]; then
16 md5=`which md5sum`
17 if [ $? != 0 ]; then
18 md5=`which openssl`
19 if [ $? != 0 ]; then
20 echo "Can't calculate MD5, exiting"
21 exit
22 else
23 md5="$md5 md5"
24 fi
25 else
26 md5="$md5 | cut -d' ' -f1"
27 fi
28 fi
29
30 if [ "X"`head -n$skip $0 | tail -n +5 | $md5 ` != "X"$hash1 ]; then
31 echo Script MD5 mismach
32 exit
33 fi
34 skip=`let "$skip+1"`
35 if [ "X"`tail -n +$skip $0 | $md5 ` != "X"$hash2 ]; then
36 echo Payload MD5 mismach
37 exit
38 fi
39
40 temp=`mktemp -d /tmp/nxinst.XXXXXX 2>/dev/null`
41 if [ $? != 0 ]; then
42 echo "Can't create temp dir"
43 exit 0
44 fi
45 tail -n +$skip $0 | gzip -dc 2>/dev/null | tar xf - -C $temp
46 if [ $? != 0 ]; then
47 echo "Can't unpack"
48 exit;
49 else
50 cd $temp
51 chmod +x ./$command
52 ./$command
53 fi
54
55 exit
56 ###################################