solaris... userland tools... POSIX...
authorAlex Kirhenshtein <alk@netxms.org>
Wed, 1 Jun 2005 00:24:38 +0000 (00:24 +0000)
committerAlex Kirhenshtein <alk@netxms.org>
Wed, 1 Jun 2005 00:24:38 +0000 (00:24 +0000)
... If i had my way I'd have all of you shot!

contrib/installAgent.sh
tools/sharIt
tools/stub.sh

index 8a26721..a6e8bd6 100755 (executable)
@@ -25,7 +25,11 @@ while [ "x"$1 != "x" ]; do
 done
 
 make=`which gmake`
-[ "x"$make = "x" ] && make=make
+if [ $? = 0 ]; then
+       echo $make | grep "no gmake in " >/dev/null && make=make
+else
+       make=make
+fi
 
 case `uname -s` in
        Linux)
@@ -49,7 +53,7 @@ if [ "x$name" = "x" ]; then
        exit 1
 fi
 
-tar zxf $name.tar.gz 2>/dev/null
+gzip -dc $name.tar.gz | tar xf - 2>/dev/null
 if [ $? != 0 ]; then
        echo invalid package >> $log
        exit 2
index a635755..767c47d 100755 (executable)
@@ -41,8 +41,11 @@ case `uname -s` in
                exit;
                ;;
 esac
+skip1=`let $skip+1`
 
-sed "s,__SKIP__,$skip,g" < stub.sh | sed "s,__COMMAND__,$2,g" > tmp
+sed "s,__SKIP__,$skip,g" < stub.sh |
+       sed "s,__SKIP1__,$skip1,g" |
+       sed "s,__COMMAND__,$2,g" > tmp
 hash1=`tail -n+5 tmp | $md5 | cut -b1-32 | tr A-Z a-z`
 hash2=`cat $1 | $md5 | cut -b1-32 | tr A-Z a-z`
 sed "s,__HASH1__,$hash1,g" < tmp | sed "s,__HASH2__,$hash2,g" > $3
index 5f89370..a329820 100755 (executable)
@@ -3,45 +3,70 @@
 hash1=__HASH1__
 hash2=__HASH2__
 skip=__SKIP__
+skip1=__SKIP1__
 command=__COMMAND__
+command=inst/installAgent.sh
 log=/tmp/nxagentupdate.log
 
+wd=`pwd -P`
+
 trap '
        echo "Upgrade script finished" >> $log
+       cd $wd
        [ "x"$temp != "x" ] && rm -rf $temp
        exit
 ' INT EXIT
 
 rm -f $log
 
-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" >> $log
-                       exit
-               else
-                       md5="$md5 md5"
+_PATH=$PATH
+PATH=$PATH:`echo /opt/openssl*/bin | tr ' ' ':'`
+export PATH
+md5=
+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
+                       [ $app = "openssl" ] && md5="$md5 md5"
                fi
        fi
-fi
+done
+PATH=$_PATH
+export PATH
 
-if [ "X"`head -n$skip $0 | tail -n +5 | $md5 | cut -b1-32 | tr A-Z a-z` != "X"$hash1 ]; then
-       echo "Script MD5 mismach" >> $log
-       exit
+tail="tail -n"
+if [ `uname` = "SunOS" ]; then
+       tail=tail
+       mktemp() {
+               d=/tmp/nxupdate.$$.UniQ
+               mkdir $d && echo $d || false
+       }
 fi
 
-let "skip=skip+1" 2>/dev/null
-if [ $? != 0 ]; then
-       # real sh?
-       skip=`let "$skip+1"`
-fi
+if [ "x$md5" != "x" ]; then
+       if [ "X"`head -n$skip $0 |
+               $tail +5 |
+               $md5 |
+               cut -b1-32 |
+               tr A-Z a-z` != "X"$hash1 ];
+       then
+               echo "Script MD5 mismach" >> $log
+               exit
+       fi
 
-if [ "X"`tail -n +$skip $0 | $md5 | cut -b1-32 | tr A-Z a-z` != "X"$hash2 ]; then
-       echo "Payload MD5 mismach" >> $log
-       exit
+       if [ "X"`$tail +$skip1 $0 |
+               $md5 |
+               cut -b1-32 |
+               tr A-Z a-z` != "X"$hash2 ];
+       then
+               echo "Payload MD5 mismach" >> $log
+               exit
+       fi
+else
+       echo "No md5/md5sum/openssl found, can't check integrity" >> $log
 fi
 
 temp=`mktemp -d /tmp/nxinst.XXXXXX 2>/dev/null`
@@ -49,12 +74,12 @@ if [ $? != 0 ]; then
        echo "Can't create temp dir" >> $log
        exit 0
 fi
-tail -n +$skip $0 | gzip -dc 2>/dev/null | tar xf - -C $temp
+cd $temp
+$tail +$skip1 $wd/$0 | gzip -dc 2>/dev/null | tar xf -
 if [ $? != 0 ]; then
        echo "Can't unpack" >> $log
        exit;
 else
-       cd $temp
        chmod +x ./$command
        if [ $? != 0 ]; then
                echo "Can't chmod $command" >> $log