sharIt: creates self-installing shell script with embeded .tgz
[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...
10 #[ "x"$temp != "x" ] && rm -rf $temp
11 exit
12' INT EXIT
13
14md5=`which md5`
15if [ $? != 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
28fi
29
30if [ "X"`head -n$skip $0 | tail -n +5 | $md5 ` != "X"$hash1 ]; then
31 echo Script MD5 mismach
32 exit
33fi
34skip=`let "$skip+1"`
35if [ "X"`tail -n +$skip $0 | $md5 ` != "X"$hash2 ]; then
36 echo Payload MD5 mismach
37 exit
38fi
39
40temp=`mktemp -d /tmp/nxinst.XXXXXX 2>/dev/null`
41if [ $? != 0 ]; then
42 echo "Can't create temp dir"
43 exit 0
44fi
45tail -n +$skip $0 | gzip -dc 2>/dev/null | tar xf - -C $temp
46if [ $? != 0 ]; then
47 echo "Can't unpack"
48 exit;
49else
50 cd $temp
51 chmod +x ./$command
52 ./$command
53fi
54
55exit
56###################################