sharIt: creates self-installing shell script with embeded .tgz
[public/netxms.git] / tools / sharIt
CommitLineData
b78936e5
AK
1#!/bin/sh
2
3trap '
4 rm tmp
5' INT EXIT
6
7if [ "x"$3 = "x" ]; then
8 echo "Usage: $0 input.tar.gz scriptname output.sh"
9 exit
10fi
11
12md5=`which md5`
13if [ $? != 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
26fi
27
28skip=`echo \`wc -l stub.sh|cut -b1-8\``
29sed "s,__SKIP__,$skip,g" < stub.sh | sed "s,__COMMAND__,$2,g" > tmp
30hash1=`tail -n+5 tmp | $md5`
31hash2=`cat $1 | $md5`
32sed "s,__HASH1__,$hash1,g" < tmp | sed "s,__HASH2__,$hash2,g" > $3
33
34cat $1 >> $3