sharIt: creates self-installing shell script with embeded .tgz
[public/netxms.git] / tools / sharIt
1 #!/bin/sh
2
3 trap '
4 rm tmp
5 ' INT EXIT
6
7 if [ "x"$3 = "x" ]; then
8 echo "Usage: $0 input.tar.gz scriptname output.sh"
9 exit
10 fi
11
12 md5=`which md5`
13 if [ $? != 0 ]; then
14 md5=`which md5sum`
15 if [ $? != 0 ]; then
16 md5=`which openssl`
17 if [ $? != 0 ]; then
18 echo "Can't calculate MD5, exiting"
19 exit
20 else
21 md5="$md5 md5"
22 fi
23 else
24 md5="$md5 | cut -d' ' -f1"
25 fi
26 fi
27
28 skip=`echo \`wc -l stub.sh|cut -b1-8\``
29 sed "s,__SKIP__,$skip,g" < stub.sh | sed "s,__COMMAND__,$2,g" > tmp
30 hash1=`tail -n+5 tmp | $md5`
31 hash2=`cat $1 | $md5`
32 sed "s,__HASH1__,$hash1,g" < tmp | sed "s,__HASH2__,$hash2,g" > $3
33
34 cat $1 >> $3