works on linux
[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)
33 skip=`wc -l stub.sh|cut -d' ' -f1`
34 ;;
35 *BSD)
36 skip=`echo \`wc -l stub.sh|cut -b1-8\``
37 ;;
38 *)
39 echo unknown system, duh
40 exit;
41 ;;
42esac
43
b78936e5 44sed "s,__SKIP__,$skip,g" < stub.sh | sed "s,__COMMAND__,$2,g" > tmp
2dad1e4c
AK
45hash1=`tail -n+5 tmp | $md5 | cut -b1-32 | tr A-Z a-z`
46hash2=`cat $1 | $md5 | cut -b1-32 | tr A-Z a-z`
b78936e5
AK
47sed "s,__HASH1__,$hash1,g" < tmp | sed "s,__HASH2__,$hash2,g" > $3
48
49cat $1 >> $3