Various fixes
[public/netxms.git] / tools / sharIt
CommitLineData
39cc66bb 1#!/usr/local/bin/bash
b78936e5 2
39cc66bb
VK
3#trap '
4# rm -f tmp
5#' INT EXIT
b78936e5
AK
6
7if [ "x"$3 = "x" ]; then
8 echo "Usage: $0 input.tar.gz scriptname output.sh"
9 exit
10fi
11
2dad1e4c
AK
12if [ ! -r $1 ]; then
13 echo "Can't read $1"
14 exit
15fi
71a419d0 16
2dad1e4c 17md5=`which md5 2>/dev/null`
b78936e5 18if [ $? != 0 ]; then
2dad1e4c 19 md5=`which md5sum 2>/dev/null`
b78936e5 20 if [ $? != 0 ]; then
2dad1e4c 21 md5=`which openssl 2>/dev/null`
b78936e5
AK
22 if [ $? != 0 ]; then
23 echo "Can't calculate MD5, exiting"
24 exit
25 else
26 md5="$md5 md5"
27 fi
b78936e5
AK
28 fi
29fi
30
2dad1e4c 31case `uname -s` in
2dad1e4c
AK
32 *BSD)
33 skip=`echo \`wc -l stub.sh|cut -b1-8\``
34 ;;
35 *)
39cc66bb 36 skip=`cat stub.sh | wc -l | sed 's,^ *,,'`
2dad1e4c
AK
37 ;;
38esac
9c96f75c
AK
39if [ "x$BASH" == "x" ]; then
40 skip1=`let $skip+1`
41else
42 skip1=$skip
43 let skip1++
44fi
2dad1e4c 45
3e80aa9c
AK
46sed "s,__SKIP__,$skip,g" < stub.sh |
47 sed "s,__SKIP1__,$skip1,g" |
48 sed "s,__COMMAND__,$2,g" > tmp
39cc66bb 49hash1=`tail -n +5 tmp | $md5 | cut -b1-32 | tr A-Z a-z`
2dad1e4c 50hash2=`cat $1 | $md5 | cut -b1-32 | tr A-Z a-z`
b78936e5
AK
51sed "s,__HASH1__,$hash1,g" < tmp | sed "s,__HASH2__,$hash2,g" > $3
52
53cat $1 >> $3