"Fossies" - the Fresh Open Source Software Archive

Member "netxms-3.8.166/tools/stub.sh" (23 Feb 2021, 2722 Bytes) of package /linux/misc/netxms-3.8.166.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/bin/sh
    2 
    3 hash1=__HASH1__
    4 hash2=__HASH2__
    5 skip=__SKIP__
    6 skip1=__SKIP1__
    7 command=__COMMAND__
    8 log=/tmp/nxagentupdate.log
    9 
   10 for var in "$@"; do
   11    if [ $(echo $var | cut -d= -f1) = "prefix" ]; then
   12       prefix=$(echo $var | cut -d= -f2)
   13    fi
   14 done
   15 
   16 if [ "x$prefix" != "x" ]; then
   17    prefix=/opt/netxms
   18 fi
   19 
   20 # trap '
   21 #   echo "Upgrade script finished" >> $log
   22 #   cd $wd
   23 #   [ "x"$temp != "x" ] && rm -rf $temp
   24 #   exit
   25 # ' INT EXIT
   26 
   27 SCRIPT_DIR=`dirname $0`
   28 if [[ "$SCRIPT_DIR" = /* ]]; then
   29    SELF=$0
   30 else
   31    SELF=`pwd -P`/$0
   32 fi
   33 
   34 echo "$SELF started: $*" > $log
   35 
   36 _mktemp() {
   37     d=/tmp/nxupdate.$$.UniQ
   38     mkdir $d && echo $d || false
   39 }
   40 
   41 if [ "x$md5" = "x" ] && [ "x`echo test | $prefix/bin/nxcsum md5 -`" = 'xd8e8fca2dc0f896fd7cb4cb0031ba249' ]; then
   42    md5="$prefix/bin/nxcsum md5 -"
   43 fi
   44 if [ "x`echo test | md5 2>/dev/null | tr A-Z a-z | cut -b1-32`" = 'xd8e8fca2dc0f896fd7cb4cb0031ba249' ]; then
   45    md5="md5 | tr A-Z a-z | cut -b1-32"
   46 fi
   47 if [ "x$md5" = "x" ] && [ "x`echo test | md5sum 2>/dev/null | tr A-Z a-z | cut -b1-32`" = 'xd8e8fca2dc0f896fd7cb4cb0031ba249' ]; then
   48    md5="md5sum | tr A-Z a-z | cut -b1-32"
   49 fi
   50 if [ "x$md5" = "x" ] && [ "x`echo test | openssl md5 2>/dev/null | tr A-Z a-z`" = 'xd8e8fca2dc0f896fd7cb4cb0031ba249' ]; then
   51    md5="openssl md5 | tr A-Z a-z"
   52 fi
   53 if [ "x$md5" = "x" ] && [ "x`echo test | openssl md5 2>/dev/null | tr A-Z a-z | rev | cut -b1-32 | rev`" = 'xd8e8fca2dc0f896fd7cb4cb0031ba249' ]; then
   54    md5="openssl md5 | tr A-Z a-z | rev | cut -b1-32 | rev"
   55 fi
   56 
   57 tail="tail -n"
   58 case `uname -s` in
   59     SunOS)
   60         tail="tail"
   61         mktemp() {
   62             _mktemp $*
   63         }
   64         ;;
   65     HP-UX)
   66         alias mktemp=_mktemp
   67         ;;
   68     *)
   69         ;;
   70 esac
   71 
   72 tmp=`which mktemp 2>/dev/null`
   73 if [ $? = 0 ]; then
   74     echo $tmp | grep "no mktemp in " >/dev/null 2>&1
   75     [ $? = 0 ] && alias mktemp=_mktemp
   76 else
   77     alias mktemp=_mktemp
   78 fi
   79 
   80 if [ "x$md5" != "x" ]; then
   81    h1=`head -n $skip $SELF | $tail +5 | eval $md5`
   82     h2=`$tail +$skip1 $SELF | eval $md5`
   83 
   84    if [ "x$h1" != "x$hash1" ]; then
   85       echo "Script MD5 mismach (calculated: $h1, expected: $hash1); upgrade aborted" >> $log
   86         exit
   87     fi
   88 
   89    if [ "x$h2" != "x$hash2" ]; then
   90       echo "Payload MD5 mismach (calculated: $h2, expected: $hash2); upgrade aborted" >> $log
   91         exit
   92     fi
   93 else
   94     echo "No md5/md5sum/csum/openssl found, can't check integrity" >> $log
   95 fi
   96 
   97 temp=`mktemp -d /tmp/nxinst.XXXXXX 2>/dev/null`
   98 if [ $? != 0 ]; then
   99     echo "Can't create temp dir" >> $log
  100     exit
  101 fi
  102 cd $temp
  103 $tail +$skip1 $SELF | gzip -dc 2>/dev/null | tar xf -
  104 if [ $? != 0 ]; then
  105     echo "Can't unpack" >> $log
  106     exit;
  107 else
  108     chmod +x ./$command
  109     if [ $? != 0 ]; then
  110         echo "Can't chmod $command" >> $log
  111         exit
  112     fi
  113     echo Starting $command $*... >> $log
  114     ./$command $* 2>&1 >> $log
  115 fi
  116 
  117 exit
  118 ###################################