Binary upgrade script fixed (MD5 verification on AIX)
authorAlex Kirhenshtein <alk@netxms.org>
Thu, 24 Mar 2016 09:16:29 +0000 (11:16 +0200)
committerAlex Kirhenshtein <alk@netxms.org>
Thu, 24 Mar 2016 10:53:46 +0000 (12:53 +0200)
tools/sharIt
tools/stub.sh

index 125452a..eebf6a0 100755 (executable)
@@ -22,18 +22,25 @@ if [ ! -r $stub ]; then
        exit
 fi
 
-md5=`which md5 2>/dev/null`
-if [ $? != 0 ]; then
-       md5=`which md5sum 2>/dev/null`
-       if [ $? != 0 ]; then
-               md5=`which openssl 2>/dev/null`
-               if [ $? != 0 ]; then
-                       echo "Can't calculate MD5, exiting"
-                       exit
-               else
-                       md5="$md5 md5"
-               fi
-       fi
+if [ "x`echo test | md5 2>/dev/null | tr A-Z a-z | cut -b1-32`" = 'xd8e8fca2dc0f896fd7cb4cb0031ba249' ]; then
+   md5="md5 | tr A-Z a-z | cut -b1-32"
+fi
+if [ "x$md5" = "x" ] && [ "x`echo test | md5sum 2>/dev/null | tr A-Z a-z | cut -b1-32`" = 'xd8e8fca2dc0f896fd7cb4cb0031ba249' ]; then
+   md5="md5sum | tr A-Z a-z | cut -b1-32"
+fi
+if [ "x$md5" = "x" ] && [ "x`echo test | csum -h MD5 - 2>/dev/null | tr A-Z a-z | cut -b1-32`" = 'xd8e8fca2dc0f896fd7cb4cb0031ba249' ]; then
+   md5="csum -h MD5 - | tr A-Z a-z | cut -b1-32"
+fi
+if [ "x$md5" = "x" ] && [ "x`echo test | openssl md5 2>/dev/null | tr A-Z a-z`" = 'xd8e8fca2dc0f896fd7cb4cb0031ba249' ]; then
+   md5="openssl md5 | tr A-Z a-z"
+fi
+if [ "x$md5" = "x" ] && [ "x`echo test | openssl md5 2>/dev/null | tr A-Z a-z | rev | cut -b1-32 | rev`" = 'xd8e8fca2dc0f896fd7cb4cb0031ba249' ]; then
+   md5="openssl md5 | tr A-Z a-z | rev | cut -b1-32 | rev"
+fi
+
+if [ -z "$md5" ]; then
+   echo "Can't calculate MD5, exiting"
+   exit
 fi
 
 skip=`echo \`wc -l $stub|awk '{ print $1 }'\``
@@ -48,8 +55,8 @@ fi
 sed "s,__SKIP__,$skip,g" < $stub |
        sed "s,__SKIP1__,$skip1,g" |
        sed "s,__COMMAND__,$2,g" > tmp
-hash1=`tail -n +5 tmp | $md5 | cut -c1-32 | tr A-Z a-z`
-hash2=`cat $1 | $md5 | cut -c1-32 | tr A-Z a-z`
+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
index e65d510..1cdab40 100755 (executable)
@@ -6,9 +6,6 @@ skip=__SKIP__
 skip1=__SKIP1__
 command=__COMMAND__
 log=/tmp/nxagentupdate.log
-md5found=no
-postproc1="cut -b1-32"
-postproc2="cat"
 
 trap '
        echo "Upgrade script finished" >> $log
@@ -27,37 +24,20 @@ _mktemp() {
        mkdir $d && echo $d || false
 }
 
-for app in openssl md5sum md5; do
-       tmp=`which $app 2>/dev/null`
-       if [ $? = 0 ]; then
-               echo $tmp | grep "no $app in " >/dev/null 2>&1
-               if [ $? != 0 ]; then
-                       md5=$tmp
-                       md5found=yes
-                       break
-               fi
-       fi
-done
-
-if [ -z "$md5" ]; then
-       for dir in /bin /sbin /usr/bin /usr/local/bin /opt/openssl*/bin /opt/freeware/bin; do
-               if [ -d $dir ]; then
-                       for app in openssl md5sum md5; do
-                               if [ -x "$dir/$app" ]; then
-                                       md5="$dir/$app"
-                                       md5found=yes
-                                       break
-                               fi
-                       done
-                       [ "x" != "x$md5" ] && break
-               fi
-       done
+if [ "x`echo test | md5 2>/dev/null | tr A-Z a-z | cut -b1-32`" = 'xd8e8fca2dc0f896fd7cb4cb0031ba249' ]; then
+   md5="md5 | tr A-Z a-z | cut -b1-32"
 fi
-
-if [ "`basename $md5`" = "openssl" ]; then
-       md5="$md5 md5"
-       postproc1="cut -d = -f 2"
-       postproc2="cut -b2-33"
+if [ "x$md5" = "x" ] && [ "x`echo test | md5sum 2>/dev/null | tr A-Z a-z | cut -b1-32`" = 'xd8e8fca2dc0f896fd7cb4cb0031ba249' ]; then
+   md5="md5sum | tr A-Z a-z | cut -b1-32"
+fi
+if [ "x$md5" = "x" ] && [ "x`echo test | csum -h MD5 - 2>/dev/null | tr A-Z a-z | cut -b1-32`" = 'xd8e8fca2dc0f896fd7cb4cb0031ba249' ]; then
+   md5="csum -h MD5 - | tr A-Z a-z | cut -b1-32"
+fi
+if [ "x$md5" = "x" ] && [ "x`echo test | openssl md5 2>/dev/null | tr A-Z a-z`" = 'xd8e8fca2dc0f896fd7cb4cb0031ba249' ]; then
+   md5="openssl md5 | tr A-Z a-z"
+fi
+if [ "x$md5" = "x" ] && [ "x`echo test | openssl md5 2>/dev/null | tr A-Z a-z | rev | cut -b1-32 | rev`" = 'xd8e8fca2dc0f896fd7cb4cb0031ba249' ]; then
+   md5="openssl md5 | tr A-Z a-z | rev | cut -b1-32 | rev"
 fi
 
 tail="tail -n"
@@ -83,29 +63,23 @@ else
        alias mktemp=_mktemp
 fi
 
-if [ "$md5found" = "yes" ]; then
+if [ "x$md5" != "x" ]; then
        if [ "X"`head -n $skip $0 |
                $tail +5 |
-               $md5 |
-               $postproc1 |
-               $postproc2 |
-               tr A-Z a-z` != "X"$hash1 ];
+               $md5` != "X"$hash1 ];
        then
                echo "Script MD5 mismach; upgrade aborted" >> $log
                exit
        fi
 
        if [ "X"`$tail +$skip1 $0 |
-               $md5 |
-               $postproc1 |
-               $postproc2 |
-               tr A-Z a-z` != "X"$hash2 ];
+               $md5` != "X"$hash2 ];
        then
                echo "Payload MD5 mismach; upgrade aborted" >> $log
                exit
        fi
 else
-       echo "No md5/md5sum/openssl found, can't check integrity" >> $log
+       echo "No md5/md5sum/csum/openssl found, can't check integrity" >> $log
 fi
 
 temp=`mktemp -d /tmp/nxinst.XXXXXX 2>/dev/null`