Changelog update
[public/netxms.git] / tools / sharIt
CommitLineData
26070401 1#!/bin/bash
d7b7ed9e
AK
2#
3# vim:ts=3 sw=3
b78936e5 4
d7b7ed9e
AK
5trap '
6 rm -f tmp
7' INT EXIT
b78936e5
AK
8
9if [ "x"$3 = "x" ]; then
10 echo "Usage: $0 input.tar.gz scriptname output.sh"
11 exit
12fi
13
2dad1e4c
AK
14if [ ! -r $1 ]; then
15 echo "Can't read $1"
16 exit
17fi
71a419d0 18
3fbc3b89 19stub=`dirname \`echo $0\``/stub.sh
d7b7ed9e
AK
20if [ ! -r $stub ]; then
21 echo "$stub not found!"
22 exit
23fi
24
f59baf37
AK
25if [ "x`echo test | md5 2>/dev/null | tr A-Z a-z | cut -b1-32`" = 'xd8e8fca2dc0f896fd7cb4cb0031ba249' ]; then
26 md5="md5 | tr A-Z a-z | cut -b1-32"
27fi
28if [ "x$md5" = "x" ] && [ "x`echo test | md5sum 2>/dev/null | tr A-Z a-z | cut -b1-32`" = 'xd8e8fca2dc0f896fd7cb4cb0031ba249' ]; then
29 md5="md5sum | tr A-Z a-z | cut -b1-32"
30fi
31if [ "x$md5" = "x" ] && [ "x`echo test | csum -h MD5 - 2>/dev/null | tr A-Z a-z | cut -b1-32`" = 'xd8e8fca2dc0f896fd7cb4cb0031ba249' ]; then
32 md5="csum -h MD5 - | tr A-Z a-z | cut -b1-32"
33fi
34if [ "x$md5" = "x" ] && [ "x`echo test | openssl md5 2>/dev/null | tr A-Z a-z`" = 'xd8e8fca2dc0f896fd7cb4cb0031ba249' ]; then
35 md5="openssl md5 | tr A-Z a-z"
36fi
37if [ "x$md5" = "x" ] && [ "x`echo test | openssl md5 2>/dev/null | tr A-Z a-z | rev | cut -b1-32 | rev`" = 'xd8e8fca2dc0f896fd7cb4cb0031ba249' ]; then
38 md5="openssl md5 | tr A-Z a-z | rev | cut -b1-32 | rev"
39fi
40
41if [ -z "$md5" ]; then
42 echo "Can't calculate MD5, exiting"
43 exit
b78936e5
AK
44fi
45
90d5014d 46skip=`echo \`wc -l $stub|awk '{ print $1 }'\``
d7b7ed9e 47
9c96f75c
AK
48if [ "x$BASH" == "x" ]; then
49 skip1=`let $skip+1`
50else
51 skip1=$skip
52 let skip1++
53fi
2dad1e4c 54
d7b7ed9e 55sed "s,__SKIP__,$skip,g" < $stub |
3e80aa9c
AK
56 sed "s,__SKIP1__,$skip1,g" |
57 sed "s,__COMMAND__,$2,g" > tmp
26070401
AK
58hash1=`tail -n +5 tmp | eval $md5`
59hash2=`cat $1 | eval $md5`
b78936e5
AK
60sed "s,__HASH1__,$hash1,g" < tmp | sed "s,__HASH2__,$hash2,g" > $3
61
62cat $1 >> $3