Updated scripts
[public/netxms.git] / tools / sharIt
1 #!/bin/sh
2
3 trap '
4 rm -f 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 if [ ! -r $1 ]; then
13 echo "Can't read $1"
14 exit
15 fi
16
17 md5=`which md5 2>/dev/null`
18 if [ $? != 0 ]; then
19 md5=`which md5sum 2>/dev/null`
20 if [ $? != 0 ]; then
21 md5=`which openssl 2>/dev/null`
22 if [ $? != 0 ]; then
23 echo "Can't calculate MD5, exiting"
24 exit
25 else
26 md5="$md5 md5"
27 fi
28 fi
29 fi
30
31 case `uname -s` in
32 Linux)
33 #skip=`wc -l stub.sh|cut -d' ' -f1`
34 skip=`cat stub.sh | wc -l | sed 's,^ *,,'`
35 ;;
36 *BSD)
37 skip=`echo \`wc -l stub.sh|cut -b1-8\``
38 ;;
39 *)
40 echo unknown system, duh
41 exit;
42 ;;
43 esac
44
45 sed "s,__SKIP__,$skip,g" < stub.sh | sed "s,__COMMAND__,$2,g" > tmp
46 hash1=`tail -n+5 tmp | $md5 | cut -b1-32 | tr A-Z a-z`
47 hash2=`cat $1 | $md5 | cut -b1-32 | tr A-Z a-z`
48 sed "s,__HASH1__,$hash1,g" < tmp | sed "s,__HASH2__,$hash2,g" > $3
49
50 cat $1 >> $3