now sharIt is bash compatible
[public/netxms.git] / tools / sharIt
CommitLineData
b78936e5
AK
1#!/bin/sh
2
3trap '
71a419d0 4 rm -f tmp
b78936e5
AK
5' INT EXIT
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
AK
31case `uname -s` in
32 Linux)
861fb447
VK
33 #skip=`wc -l stub.sh|cut -d' ' -f1`
34 skip=`cat stub.sh | wc -l | sed 's,^ *,,'`
2dad1e4c
AK
35 ;;
36 *BSD)
37 skip=`echo \`wc -l stub.sh|cut -b1-8\``
38 ;;
39 *)
40 echo unknown system, duh
41 exit;
42 ;;
43esac
9c96f75c
AK
44if [ "x$BASH" == "x" ]; then
45 skip1=`let $skip+1`
46else
47 skip1=$skip
48 let skip1++
49fi
2dad1e4c 50
3e80aa9c
AK
51sed "s,__SKIP__,$skip,g" < stub.sh |
52 sed "s,__SKIP1__,$skip1,g" |
53 sed "s,__COMMAND__,$2,g" > tmp
2dad1e4c
AK
54hash1=`tail -n+5 tmp | $md5 | cut -b1-32 | tr A-Z a-z`
55hash2=`cat $1 | $md5 | cut -b1-32 | tr A-Z a-z`
b78936e5
AK
56sed "s,__HASH1__,$hash1,g" < tmp | sed "s,__HASH2__,$hash2,g" > $3
57
58cat $1 >> $3