sharIt: creates self-installing shell script with embeded .tgz
authorAlex Kirhenshtein <alk@netxms.org>
Mon, 31 Jan 2005 01:20:37 +0000 (01:20 +0000)
committerAlex Kirhenshtein <alk@netxms.org>
Mon, 31 Jan 2005 01:20:37 +0000 (01:20 +0000)
.gitattributes
tools/sharIt [new file with mode: 0755]
tools/stub.sh [new file with mode: 0755]

index 2006c48..687d643 100644 (file)
@@ -695,3 +695,5 @@ tools/Makefile.am -text
 tools/mc.pl -text
 tools/nwmkimp.pl -text
 tools/patch_libtool.pl -text
+tools/sharIt -text
+tools/stub.sh -text
diff --git a/tools/sharIt b/tools/sharIt
new file mode 100755 (executable)
index 0000000..2b124f2
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+trap '
+       rm tmp
+' INT EXIT
+
+if [ "x"$3 = "x" ]; then
+       echo "Usage: $0 input.tar.gz scriptname output.sh"
+       exit
+fi
+
+md5=`which md5`
+if [ $? != 0 ]; then
+       md5=`which md5sum`
+       if [ $? != 0 ]; then
+               md5=`which openssl`
+               if [ $? != 0 ]; then
+                       echo "Can't calculate MD5, exiting"
+                       exit
+               else
+                       md5="$md5 md5"
+               fi
+       else
+               md5="$md5 | cut -d' ' -f1"
+       fi
+fi
+
+skip=`echo \`wc -l stub.sh|cut -b1-8\``
+sed "s,__SKIP__,$skip,g" < stub.sh | sed "s,__COMMAND__,$2,g" > tmp
+hash1=`tail -n+5 tmp | $md5`
+hash2=`cat $1 | $md5`
+sed "s,__HASH1__,$hash1,g" < tmp | sed "s,__HASH2__,$hash2,g" > $3
+
+cat $1 >> $3
diff --git a/tools/stub.sh b/tools/stub.sh
new file mode 100755 (executable)
index 0000000..40fc49d
--- /dev/null
@@ -0,0 +1,56 @@
+#!/bin/sh
+
+hash1=__HASH1__
+hash2=__HASH2__
+skip=__SKIP__
+command=__COMMAND__
+
+trap '
+       echo Cleanup...
+       #[ "x"$temp != "x" ] && rm -rf $temp
+       exit
+' INT EXIT
+
+md5=`which md5`
+if [ $? != 0 ]; then
+       md5=`which md5sum`
+       if [ $? != 0 ]; then
+               md5=`which openssl`
+               if [ $? != 0 ]; then
+                       echo "Can't calculate MD5, exiting"
+                       exit
+               else
+                       md5="$md5 md5"
+               fi
+       else
+               md5="$md5 | cut -d' ' -f1"
+       fi
+fi
+
+if [ "X"`head -n$skip $0 | tail -n +5 | $md5 ` != "X"$hash1 ]; then
+       echo Script MD5 mismach
+       exit
+fi
+skip=`let "$skip+1"`
+if [ "X"`tail -n +$skip $0 | $md5 ` != "X"$hash2 ]; then
+       echo Payload MD5 mismach
+       exit
+fi
+
+temp=`mktemp -d /tmp/nxinst.XXXXXX 2>/dev/null`
+if [ $? != 0 ]; then
+       echo "Can't create temp dir"
+       exit 0
+fi
+tail -n +$skip $0 | gzip -dc 2>/dev/null | tar xf - -C $temp
+if [ $? != 0 ]; then
+       echo "Can't unpack"
+       exit;
+else
+       cd $temp
+       chmod +x ./$command
+       ./$command
+fi
+
+exit
+###################################