Community
    • Login

    Function List incomplete

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    25 Posts 3 Posters 2.0k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • greg-michaelG
      greg-michael @Michael Vincent
      last edited by

      @Michael-Vincent Part 3

      ################################################################################
      # copy_files
      ################################################################################
      copy_files()
      {
      print_msg "\n(${MM}/${DD} $(date +%R)) Started copy_files" "debug"
      
      unset BASECPRESULT BKPFMT BUILDDIR CLEANCMD CPRESULT DIRCHK FILE SRCPATH SRCSVR SVR
      
      local BASECPRESULT=0
      local BKPFMT=".${DD}-${MM}-${YYYY}_${HH}${MM}"
      local BUILDDIR="${3}"
      local CPRESULT=0
      local DIRCHK=""
      local FILE="${4}"
      local SRCSVR="${2}"
      local SVR="${1}"
      
      # Setup source path to copy files from
      # /hamq/software/mq/client
      local SRCPATH="${SRCSVR}${SOURCEPATH}"
      
      #GVM#print_msg "BKPFMT=${BKPFMT}~nBUILDDIR=${BUILDDIR}~nFILE=${FILE}~nSRCSVR=${SRCSVR}\
      #GVM#~nSVR=${SVR}" "debug"
      print_msg "BKPFMT=${BKPFMT}~nBUILDDIR=${BUILDDIR}~nFILE=${FILE}~nSRCSVR=${SRCSVR}\
      ~nSVR=${SVR}" "debug"
      
      # Copy install and patch files from source to target
      if [[ -n ${FILE} ]]
        then
          # DATAPATH includes leading '/'
          # If remnants of previous tarballs remain, remove them.
          CLEANCMD='if [[ -d ${DATAPATH:=/var/mqm}/MQCV ]] ; then '
          CLEANCMD+='/bin/rm -dfR ${DATAPATH:=/var/mqm}/MQCV ; fi ; '
          CLEANCMD+='if [[ \$(ls ${DATAPATH:=/var/mqm} | grep -cE "MQCV-[0-9][.][0-9]+[.][0-9]+[-][0-9]+[.]tar[.]gz(.*)?" ) ]] ; then '
          CLEANCMD+='/bin/rm -f ${DATAPATH:=/var/mqm}/MQCV-*.*.*-*.tar.gz* ; fi ; '
          CLEANCMD+='if [[ -d ${DATAPATH:=/var/mqm}/BESClient ]] ; then '
          CLEANCMD+='/bin/rm -dfR ${DATAPATH:=/var/mqm}/BESClient ; fi'
          export CLEANCMD
          print_msg "\nCLEANCMD=${(e)CLEANCMD}" "debug"
      #GVM#    nexec -i -l ${SVR} "/bin/rm -dfR ${DATAPATH:=/var/mqm}/MQCV ; \
      #GVM#/bin/rm -dfR ${DATAPATH:=/var/mqm}/BESClient"
      #GVM#    nexec -i -l ${SVR} "/bin/rm -dfR ${DATAPATH:=/var/mqm}/MQCV ; \
      #GVM#/bin/rm -f ${DATAPATH:=/var/mqm}/MQCV-*.*.*-*.tar.gz ; /bin/rm -dfR ${DATAPATH:=/var/mqm}/BESClient"
          if (( DRYRUN ))
            then
              print_msg "nexec -i -l ${SVR} \"${(e)CLEANCMD}\"" "dryrun"
              print_msg "\ncp -bfuvs \"${BKPFMT}\" //${SRCPATH}/${FILE} \
      //${SVR}${DATAPATH}" "dryrun"
      
            else
              nexec -i -l ${SVR} "${(e)CLEANCMD}"
              cp -bfuvs "${BKPFMT}" //${SRCPATH}/${FILE} //${SVR}${DATAPATH}
              let CPRESULT=$?
          fi
      #GVM#  else
      #GVM#    # If tarball is missing on source server, check for build directory
      #GVM#    DIRCHK="$( ls -d //${SRCSVR}${BUILDDIR} )"
      #GVM#    DIRCHK="$( ls -d //${SRCSVR}${BUILDDIR} 2>/dev/null )"
      #GVM#    print_msg "DIRCHK=${DIRCHK}" "debug"
      #GVM#    if [[ -n ${DIRCHK} ]]
      #GVM#      then
      #GVM#        # BUILDDIR and DATAPATH include leading '/'
      #GVM#        if (( DRYRUN ))
      #GVM#          then
      #GVM#            print_msg "\ncp -puvr //${SRCSVR}${BUILDDIR}/* //${SVR}${DATAPATH}" "dryrun"
      #GVM#          else
      #GVM#            cp -puvr //${SRCSVR}${BUILDDIR}/* //${SVR}${DATAPATH}
      #GVM#            let CPRESULT=$?
      #GVM#        fi
      #GVM#      else
      #GVM#        ERRORDESC="ERROR 111: Could not copy patch ${PATCHVER} files from \
      #GVM#${SRCSVR}:${BUILDDIR} to ${SVR}"
      #GVM#
      #GVM#        let ERROR_CODE=111
      #GVM#        critical_error
      #GVM#    fi
      fi
      
      print_msg "CPRESULT=${CPRESULT}" "debug"
      
      # Verify copy success
      if [[ ${CPRESULT} != 0 ]]
        then
          ERRORDESC="ERROR 112: Failed to copy source files to ${SVR}"
          let ERROR_CODE=112
          critical_error
        else
      #GVM#    unpack_files ${SVR}
          unpack_files ${SVR} "${FILE}"
      fi
      
      print_msg "\n(${MM}/${DD} $(date +%R)) End copy_files" "debug"
      }
      ################################################################################
      # unpack_files
      ################################################################################
      unpack_files()
      {
      print_msg "\n(${MM}/${DD} $(date +%R)) Started unpack_files" "debug"
      
      unset ACTIONFILE BESDATAPATH CPPACTIONFILE CPRESULT OGNACTIONFILE RESULT RPMFILES
      unset SPATH TGT TFILE UNPACK
      
      local ACTIONFILE=""
      local BESDATAPATH='//${TGT}${DATAPATH}/BESClient'
      local CPPACTIONFILE=""
      local CPRESULT=0
      local OGNACTIONFILE=""
      local RESULT=99
      local RPMFILES=0
      local SPATH="//${SOURCESVR}${HABES}"
      local TGT="${1}"
      #GVM#local TFILE=""
      local TFILE="${2}"
      local UNPACK=""
      
      # Check for tarball on target server
      # (e) Perform parameter expansion, command substitution and arithmetic
      #     expansion on the result.
      #GVM#TFILE="$( ls //${TGT}${DATAPATH} 2>/dev/null | grep -iE "${(e)SOURCEFILES}$" | \
      #GVM#grep -i "${MQVERBASE}${PATCHVER}" )"
      if [[ ${#TFILE} == 0 ]]
        then
          TFILE="$( ls //${TGT}${DATAPATH} 2>/dev/null | grep -iE "${(e)SOURCEFILES}$" \
      | sed 's/[[:cntrl:]]*//g' )"
      
      fi
      
      print_msg "BESDATAPATH=${(e)BESDATAPATH}~nDATAPATH=${DATAPATH}~nSPATH=${SPATH}~nTGT=${TGT}~n\
      TFILE=${TFILE}" "debug"
      
      if [[ -n ${TFILE} ]]
        then
          # DATAPATH includes leading '/'
          if (( DRYRUN ))
            then
              print_msg "\nnexec -i -l ${TGT} \"${TAR} -C ${DATAPATH} -zxf ${DATAPATH}/${TFILE} \
      ; echo -e \\\"RESULT=\\\$?\\\"\"" "dryrun"
      
              let RESULT=0
            else
              UNPACK="$( nexec -i -l ${TGT} "${TAR} -C ${DATAPATH} -zxf ${DATAPATH}/${TFILE} \
      ; echo -e \"RESULT=\$?\"" )"
      
              let RESULT=$( echo -e "${UNPACK}" | grep "RESULT=" | \
      sed 's/[[:cntrl:]]*//g' | cut -f2 -d'=' )
      
              print_msg "UNPACK=${UNPACK}~nRESULT=${RESULT}" "debug"
          fi
          if [[ ${RESULT:=99} != 0 ]]
            then
              ERRORDESC="ERROR 113: Failed to unpack ${TFILE} on ${TGT}"
              let ERROR_CODE=113
              if [[ -n "${UNPACK}" ]] ; then print_msg "UNPACK=\n${UNPACK}" ; fi
              critical_error
            else
              # Force owner:group mqm:mqm for new installs
              if (( NEWINST ))
                then
                  if (( DRYRUN ))
                    then
                      print_msg "\nnexec -i -l ${TGT} \"${FINDCMD} ${DATAPATH} \
      ${FINDARGS}\"" "dryrun"
      
                    else
                      nexec -i -l ${TGT} "${FINDCMD} ${DATAPATH} ${FINDARGS}"
                  fi
              fi
          fi
        else
          if (( ! DRYRUN ))
            then
              ERRORDESC="ERROR 126: tar archive not found in ${DATAPATH} on ${TGT}"
              let ERROR_CODE=126
              critical_error
          fi
      fi
      
      # If BESAgent is not installed, ensure install files are available
      if [[ ${BESINSTALL} == 1 ]]
        then
          # Validate existence of actionsite.afxm and BESAgent RPM files
          BESFILES="$( find ${(e)BESDATAPATH} -type f -exec ls {} \; 2>/dev/null )"
          ACTIONFILE="$( echo -e "${BESFILES}" | grep -ic "/corp/${BESACTION}" )"
          CPPACTIONFILE="$( echo -e "${BESFILES}" | grep -ic "mn/${BESACTION}" )"
          OGNACTIONFILE="$( echo -e "${BESFILES}" | grep -ic "og/${BESACTION}" )"
          RPMFILES="$( echo -e "${BESFILES}" | grep -icE "${BESAGENTBASE}.*[.]rpm" )"
          print_msg "\nBESFILES=\n$( echo -e "${BESFILES}" | sed 's/\(^.*$\)/\\t \1/g' )\
      ~nACTIONFILE=${ACTIONFILE}~nCPPACTIONFILE=${CPPACTIONFILE}~nOGNACTIONFILE=\
      ${OGNACTIONFILE}~nRPMFILES=${RPMFILES}" "debug"
      
          # If any files are missing, retrieve from SOURCESVR
          if [[ ${RPMFILES} != 2 || ${ACTIONFILE} == 0 || ${CPPACTIONFILE} == 0 || \
      ${OGNACTIONFILE} == 0 ]]
      
            then
              # Retrieve BESAgent RPM file if not found
              if [[ ${RPMFILES} != 2 ]]
                then
                  if (( ! DRYRUN ))
                    then
      #GVM#                print_msg "\ncp -puv ${SPATH}/*.rpm ${(e)BESDATAPATH}/" "dryrun"
      #GVM#              else
      #GVM#                if [[ ! -d ${(e)BESDATAPATH} ]]
      #GVM#                  then
      #GVM#                    if (( DRYRUN ))
      #GVM#                      then
      #GVM#                        print_msg "nexec -i -l ${TGT} sh -c \"mkdir -p ${DATAPATH}/BESClient ; \
      #GVM#chown mqm:mqm ${DATAPATH}/BESClient\""
      #GVM#
      #GVM#                      else
      #GVM#                        nexec -i -l ${TGT} sh -c "mkdir -p ${DATAPATH}/BESClient ; \
      #GVM#chown mqm:mqm ${DATAPATH}/BESClient"
      #GVM#
      #GVM#                    fi
      #GVM#                fi
      #GVM#                cp -puv ${SPATH}/*.rpm ${(e)BESDATAPATH}/
      #GVM#                if [[ $? != 0 ]]
      #GVM#                  then
      #GVM#                    ERRORDESC="ERROR 114: Failed to copy BES Agent RPMs from \
      #GVM#${SOURCESVR} to ${TGT}"
                          ERRORDESC="ERROR 114: BES Agent RPMs not found on ${TGT}"
                          let ERROR_CODE=114
                          critical_error
      #GVM#                fi
      #GVM#            fi
              fi
              if (( ! PTC ))
                then
      #GVM#            # Retrieve actionsite.afxm file if not found
                  if [[ ${ACTIONFILE} == 0 ]]
                    then
                      if (( ! DRYRUN ))
                        then
      #GVM#                    print_msg "\ncp -puv ${SPATH}/corp/${BESACTION} \
      #GVM#${(e)BESDATAPATH}/corp/" "dryrun"
      #GVM#
      #GVM#                  else
      #GVM#                    if [[ ! -d ${(e)BESDATAPATH}/corp ]]
      #GVM#                      then
      #GVM#                        if (( DRYRUN ))
      #GVM#                          then
      #GVM#                            print_msg "nexec -i -l ${TGT} sh -c \"mkdir -p ${DATAPATH}/BESClient/corp ; \
      #GVM#chown mqm:mqm ${DATAPATH}/BESClient/corp\""
      #GVM#
      #GVM#                          else
      #GVM#                            nexec -i -l ${TGT} sh -c "mkdir -p ${DATAPATH}/BESClient/corp ; \
      #GVM#chown mqm:mqm ${DATAPATH}/BESClient/corp"
      #GVM#
      #GVM#                        fi
      #GVM#                    fi
      #GVM#                    cp -puv ${SPATH}/corp/${BESACTION} ${(e)BESDATAPATH}/corp/
      #GVM#                    if [[ $? != 0 ]]
      #GVM#                      then
      #GVM#                        ERRORDESC="ERROR 115: Failed to copy Corporate ${BESACTION} file \
      #GVM#from ${SOURCESVR} to ${TGT}"
                              ERRORDESC="ERROR 115: Corporate ${BESACTION} file not found on ${TGT}"
                              let ERROR_CODE=115
                              critical_error
      #GVM#                    fi
      #GVM#                fi
                  fi
                else
      #GVM#            # Retrieve mn/actionsite.afxm file if not found
                  if [[ ${CPPACTIONFILE} == 0 ]]
                    then
                      if (( ! DRYRUN ))
                        then
      #GVM#                    print_msg "\ncp -puv ${SPATH}/mn/${BESACTION} \
      #GVM#${(e)BESDATAPATH}/mn/" "dryrun"
      #GVM#
      #GVM#                  else
      #GVM#                    if [[ ! -d ${(e)BESDATAPATH}/mn ]]
      #GVM#                      then
      #GVM#                        if (( DRYRUN ))
      #GVM#                          then
      #GVM#                            print_msg "nexec -i -l ${TGT} sh -c \"mkdir -p ${DATAPATH}/BESClient/mn ; \
      #GVM#chown mqm:mqm ${DATAPATH}/BESClient/mn\""
      #GVM#
      #GVM#                          else
      #GVM#                            nexec -i -l ${TGT} sh -c "mkdir -p ${DATAPATH}/BESClient/mn ; \
      #GVM#chown mqm:mqm ${DATAPATH}/BESClient/mn"
      #GVM#
      #GVM#                        fi
      #GVM#                    fi
      #GVM#                    cp -puv ${SPATH}/mn/${BESACTION} ${(e)BESDATAPATH}/mn/
      #GVM#                    if [[ $? != 0 ]]
      #GVM#                      then
      #GVM#                        ERRORDESC="ERROR 127: Failed to copy PTC CPP ${BESACTION} \
      #GVM#file from ${SOURCESVR} to ${TGT}"
                              ERRORDESC="ERROR 127: PTC CPP ${BESACTION} file not found on ${TGT}"
                              let ERROR_CODE=127
                              critical_error
      #GVM#                    fi
      #GVM#                fi
                  fi
      #GVM#            # Retrieve og/actionsite.afxm file if not found
                  if [[ ${OGNACTIONFILE} == 0 ]]
                    then
                      if (( ! DRYRUN ))
                        then
      #GVM#                    print_msg "\ncp -puv ${SPATH}/og/${BESACTION} \
      #GVM#${(e)BESDATAPATH}/og/" "dryrun"
      #GVM#
      #GVM#                  else
      #GVM#                    if [[ ! -d ${(e)BESDATAPATH}/og ]]
      #GVM#                      then
      #GVM#                        if (( DRYRUN ))
      #GVM#                          then
      #GVM#                            print_msg "nexec -i -l ${TGT} sh -c \"mkdir -p ${DATAPATH}/BESClient/og ; \
      #GVM#chown mqm:mqm ${DATAPATH}/BESClient/og\""
      #GVM#
      #GVM#                          else
      #GVM#                            nexec -i -l ${TGT} sh -c "mkdir -p ${DATAPATH}/BESClient/og ; \
      #GVM#chown mqm:mqm ${DATAPATH}/BESClient/og"
      #GVM#
      #GVM#                        fi
      #GVM#                    fi
      #GVM#                    cp -puv ${SPATH}/og/${BESACTION} ${(e)BESDATAPATH}/og/
      #GVM#                    if [[ $? != 0 ]]
      #GVM#                      then
      #GVM#                        ERRORDESC="ERROR 128: Failed to copy PTC OGN ${BESACTION} \
      #GVM#file from ${SOURCESVR} to ${TGT}"
                              ERRORDESC="ERROR 128: PTC OGN ${BESACTION} file not found on ${TGT}"
                              let ERROR_CODE=128
                              critical_error
      #GVM#                    fi
      #GVM#                fi
                  fi
              fi
          fi
      fi
      
      print_msg "\n(${MM}/${DD} $(date +%R)) End unpack_files" "debug"
      }
      ################################################################################
      # install_bes
      ################################################################################
      install_bes()
      {
      print_msg "\n(${MM}/${DD} $(date +%R)) Started install_bes" "debug"
      
      unset BESINSTCMDS BESINSTOUT COPYBESCMD CPBES CPRESULT RESULT STARTBES TARGET
      
      local BESINSTCMDS=""
      local BESINSTOUT=""
      local COPYBESCMD=""
      local CPBES=""
      local CPRESULT=99
      local RESULT=99
      local STARTBES=""
      local TARGET="${1}"
      
      BESINSTCMDS="mkdir -p \"${BESCLIENTPATH}\" && chmod u+rwx,g+rx,o+rx \"${BESCLIENTPATH}\""
      BESINSTCMDS+=" ; ${RPM_CMD} -i ${DATAPATH}/BESClient/${BESAGENTRPM} 2>&1 | "
      BESINSTCMDS+="tee /tmp/besinstall.log ; echo -e \"RESULT=\$?\""
      
      print_msg "BESINSTCMDS=${BESINSTCMDS}~nTARGET=${TARGET}" "debug"
      
      if (( DRYRUN ))
        then
          print_msg "\nnexec -i -l ${TARGET} \"${BESINSTCMDS}\"" "dryrun"
        else
          if [[ ${ROLLBACK} == 1 || ${PATCHVER} == ${VER} ]]
            then
              unpack_files ${TARGET}
          fi
          BESINSTOUT="$( nexec -i -l ${TARGET} "${BESINSTCMDS}" )"
          BESINSTOUT="$( echo -e "${BESINSTOUT}" | sed 's/[[:cntrl:]]*//g' )"
          let RESULT="$( echo -e "${BESINSTOUT}" | grep "RESULT=" | \
      sed 's/[[:cntrl:]]*//g' | cut -f2 -d'=' )"
      
          print_msg "\nBESINSTOUT=\n${BESINSTOUT}~nRESULT=${RESULT}" "debug"
      fi
      
      if [[ ${RESULT:=99} != 0 ]]
        then
          ERRORDESC="ERROR 108: Failed to install ${BESAGENTRPM} on ${TARGET}"
          let ERROR_CODE=108
          if [[ -n "${BESINSTOUT}" ]] ; then print_msg "BESINSTOUT=\n${BESINSTOUT}" ; fi
          critical_error
        else
          # Copy actionsite.afxm file to /etc/opt/BEClient on TARGET
          if (( ! PTC ))
            then
              COPYBESCMD="cp ${DATAPATH}/BESClient/corp/${BESACTION} ${BESCLIENTPATH} 2>&1 && "
            elif (( CPP ))
              then
                COPYBESCMD="cp ${DATAPATH}/BESClient/mn/${BESACTION} ${BESCLIENTPATH} 2>&1 && "
              elif (( OGDEN ))
                then
                  COPYBESCMD="cp ${DATAPATH}/BESClient/og/${BESACTION} ${BESCLIENTPATH} 2>&1 && "
          fi
          COPYBESCMD+="echo -e \"RESULT=\$?\" ; chmod u+rw,g-rwx,o-rwx ${BESCLIENTPATH}/${BESACTION}"
          print_msg "\nCOPYBESCMD=${COPYBESCMD}" "debug"
          if (( DRYRUN ))
            then
              print_msg "\nnexec -i -l ${TARGET} \"${COPYBESCMD}\"" "dryrun"
            else
              CPBES="$( nexec -i -l ${TARGET} "${COPYBESCMD}" )"
              let CPRESULT="$( echo -e "${CPBES}" | grep "RESULT=" | \
      sed 's/[[:cntrl:]]*//g' | cut -f2 -d'=' )"
      
              print_msg "CPBES=${CPBES}~nCPRESULT=${CPRESULT}" "debug"
              if [[ ${CPRESULT:=99} != 0 ]]
                then
                  ERRORDESC="ERROR 109: Failed to copy ${BESACTION} to ${BESCLIENTPATH} \
      on ${TARGET}"
      
                  let ERROR_CODE=109
                  if [[ -n "${CPBES}" ]] ; then print_msg "CPBES=\n${CPBES}" ; fi
                  critical_error
              fi
          fi
          print_msg "STARTBESCMD=${STARTBESCMD}" "debug"
          if (( DRYRUN ))
            then
              print_msg "\nnexec -i -l ${TARGET} \"${STARTBESCMD}\"" "dryrun"
            else
              STARTBES="$( nexec -i -l ${TARGET} "${STARTBESCMD}" )"
              STARTBES="$( echo -e "${STARTBES}" | sed 's/[[:cntrl:]]*//g' )"
              print_msg "STARTBES=${STARTBES}" "debug"
              let BESSTATUS="$( echo -e "${STARTBES}" | grep -i "besclient" | \
      sed 's/[[:cntrl:]]*//g' | grep -ic "running" )"
      
              if [[ ${BESSTATUS:=0} == 0 ]]
                then
                  ERRORDESC="ERROR 110: Failed to start BESClient on ${TARGET}"
                  let ERROR_CODE=110
                  if [[ -n "${STARTBES}" ]] ; then print_msg "STARTBES=\n${STARTBES}\n\
      BESSTATUS=${BESSTATUS}" ; fi
      
                  critical_error
              fi
          fi
      fi
      
      print_msg "\n(${MM}/${DD} $(date +%R)) End install_bes" "debug"
      }
      
      1 Reply Last reply Reply Quote 0
      • greg-michaelG
        greg-michael @Michael Vincent
        last edited by

        @Michael-Vincent Part 4

        ################################################################################
        # install_mq
        ################################################################################
        install_mq()
        {
        print_msg "\n(${MM}/${DD} $(date +%R)) Started install_mq" "debug"
        
        unset INSTSERVER MQINSTCMD MQINSTOUT RESULT RPMS SETMQINSTCMD
        
        # Cannot use local INSTSERVER or it gets reset after calling rollback_mq
        INSTSERVER="${1}"
        local MQINSTCMD=""
        local MQINSTOUT=""
        local RPMS="${2}"
        local RESULT=99
        local SETMQINSTCMD="${SETMQINST}"
        
        if (( NEWINST ))
          then
            MQINSTCMD="${RPMINST} ${RPMS} 2>&1 | tee /tmp/mqinstall.log ; echo -e \"RESULT=\$?\""
          else
            #GVM#
            # If we're upgrading minor versions (9.2 -> 9.3) MAXCMDLVL will be < BASECMDLVL
            # so install base RPMs first.
            if [[ ${MAXCMDLVL} < ${BASECMDLVL} ]]
              then
                #GVM#        print_msg "Currently installed version is below v${MQVERBASE}${MQVERBASEMIN}. Proceeding with removal."
                print_msg "Currently installed version ${MQVERSION} is below v${MQVERBASE}${MQVERBASEMIN}. \
        Proceeding with replacement."
        
                export UNINSTALL=1
                rollback_mq ${INSTSERVER}
                export UNINSTALL=0
                # Reset environment variables
                env_check ${INSTSERVER}
                copy_files ${INSTSERVER} ${SOURCESVR} "${(e)SOURCEDIR}${PATCHVER}" "${TARFILE}"
            fi
            MQINSTCMD="${RPMUPDATE} ${RPMS} 2>&1 | tee /tmp/mqinstall.log ; echo -e \"RESULT=\$?\""
        fi
        
        #GVM## Prevent attempts to execute setmqinst if it doesn't exist
        #GVM#if [[ ! -f //${INSTSERVER}/${MQCVPATH}/bin/setmqinst ]]
        #GVM#  then
        #GVM#    SETMQINSTCMD=""
        #GVM#fi
        
        print_msg "\nMQINSTCMD=${MQINSTCMD}~n\nRPMS=${RPMS}~nINSTSERVER=${INSTSERVER}\
        ~nSETMQINSTCMD=${SETMQINSTCMD}" "debug"
        
        if (( DRYRUN ))
          then
        #GVM#    print_msg "\nnexec -i -l ${INSTSERVER} \"${MQLICENSE} ; ${SETMQINSTCMD}\"" "dryrun"
        #GVM#    print_msg "\nnexec -i -l ${INSTSERVER} \"${MQINSTCMD}\"" "dryrun"
            # Prevent attempts to execute setmqinst if it doesn't exist
            if [[ ! -f //${INSTSERVER}/${MQCVPATH}/bin/setmqinst ]]
              then
        #GVM#        SETMQINSTCMD=""
                print_msg "\nnexec -i -l ${INSTSERVER} \"${MQLICENSE}\"" "dryrun"
              else
                print_msg "\nnexec -i -l ${INSTSERVER} \"${MQLICENSE} ; ${SETMQINSTCMD}\"" "dryrun"
            fi
            print_msg "\nnexec -i -l ${INSTSERVER} \"${MQINSTCMD}\"" "dryrun"
          else
            # Prevent attempts to execute setmqinst if it doesn't exist
            if [[ -f //${INSTSERVER}/${MQCVPATH}/bin/setmqinst ]]
              then
                # Accept license and set Primary Instance
                MQLICOUT="$( nexec -i -l ${INSTSERVER} "${MQLICENSE} ; ${SETMQINSTCMD}" 2>/dev/null )"
                print_msg "\nMQLICOUT=\n${MQLICOUT}" "debug"
            fi
            # install MQ client
            MQINSTOUT="$( nexec -i -l ${INSTSERVER} "${MQINSTCMD}" )"
            let RESULT=$( echo -e "${MQINSTOUT}" | grep "RESULT=" | \
        sed 's/[[:cntrl:]]*//g' | cut -f2 -d '=' )
        
        #GVM#    print_msg "\nMQLICOUT=\n${MQLICOUT}~n\nMQINSTOUT=\n${MQINSTOUT:-'no output'}~n\
        #GVM#RESULT=${RESULT}" "debug"
            print_msg "\nMQINSTOUT=\n${MQINSTOUT:-'no output'}~nRESULT=${RESULT}" "debug"
        fi
        
        if (( ! DRYRUN ))
          then
            if [[ ${RESULT:=99} == 0 ]]
              then
                env_check ${INSTSERVER}
                print_msg "PATCHVER=${PATCHVER}~nVER=${VER}" "debug"
                # Validate installation
                if [[ ${EXISTING} != 1 || ${#INSTPATH} == 0 ]]
                  then
                    ERRORDESC="ERROR 117: Failed to set Primary Instance on ${INSTSERVER}"
                    let ERROR_CODE=117
                    if [[ -n "${MQLICOUT}" ]] ; then print_msg "MQLICOUT=\n${MQLICOUT}" ; fi
                    critical_error
                  # if installed version VER is below the patch version PATCHVER, install patch RPMs
        #GVM#          elif [[ ${PATCHVER} -gt ${VER} ]]
                  elif [[ ${BASECMDLVL}${PATCHVER} -gt ${MAXCMDLVL}${VER} ]]
                    then
                      # Validate proper installation
                      if [[ ${RPMCHKOUT} > 8 && ${RPMMQBASECNT} != 8 ]]
                        then
                          ERRORDESC="ERROR 137: Improper installation detected!"
                          ERRORDESC+=" Missing ${MQSeries}*-${MQVERBASE}${MQVERBASEMIN} RPMs!"
                          let ERROR_CODE=137
                          critical_error
                      fi
                      print_msg "Upgrading MQ Client version ${MQVERBASE}${VER} \
        found at ${INSTPATH} on ${INSTSERVER}"
        
                      install_mq ${host} "${RPMUPLIST}"
                      # Accept license and set Primary Instance
                      MQLICOUT="$( nexec -i -l ${host} "${MQLICENSE} ; ${SETMQINSTCMD}" )"
                      print_msg "\nMQLICOUT=\n${MQLICOUT}" "debug"
                fi
                # Validate license status
                if [ "x${LICCHK}" = "xLicense not accepted" ]
                  then
                    ERRORDESC="ERROR 118: Failed to install license on ${INSTSERVER}"
                    let ERROR_CODE=118
                    if [[ -n "${MQLICOUT}" ]] ; then print_msg "MQLICOUT=\n${MQLICOUT}" ; fi
                    critical_error
                fi
              else
                ERRORDESC="ERROR 116: Errors encountered during install/upgrade on ${INSTSERVER}"
                let ERROR_CODE=116
                if [[ -n "${MQINSTOUT}" ]] ; then print_msg "MQINSTOUT=\n${MQINSTOUT}" ; fi
                critical_error
            fi
        fi
        
        print_msg "\n(${MM}/${DD} $(date +%R)) End install_mq" "debug"
        }
        ################################################################################
        # rollback_mq
        ################################################################################
        rollback_mq()
        {
        print_msg "\n(${MM}/${DD} $(date +%R)) Started rollback_mq" "debug"
        
        #GVM#unset COUNT MQRPMS QSTRING RESULT RMFILES RMMQRPMS RMMQRPMSOUT RMSERVER
        unset COUNT _MQRPMSRB QSTRING RESULT RMFILES RMMQRPMS RMMQRPMSOUT RMSERVER
        unset RPMLIST SVRMINVER UNINSTOUT VERQUERY VERS
        
        local COUNT=0
        #GVM#local MQRPMS=""
        local _MQRPMSRB=""
        local QSTRING=""
        local RESULT=0
        local RMFILES=""
        local RMMQRPMS=""
        local RPMCHECKOUT=0
        local RPMLIST=""
        local RMSERVER="${1}"
        local SVRMINVER=0
        local UNINSTOUT=""
        local VERQUERY=""
        local VERS=""
        
        #GVM#MQRPMS="$( nexec -i -l ${RMSERVER} "${RPM_CMD} -qa | grep -iE \"${RPMBASE}.*_${MQINSTBASE}\" \
        # Generate listing of installed RPMs
        _MQRPMSRB="$( nexec -i -l ${RMSERVER} "${RPM_CMD} -qa | ${GREPNC} -iE \"${RPMBASE}.*_${MQINSTBASE}\" \
        | ${GREPNC} -iv \"${MQSERVERRPM}\"" | sed 's/[[:cntrl:]]*//g' )"
        
        VERQUERY='s/^${RPMBASE}.*_${MQINSTBASE}\(.*\)${RPMPLATFORM}/\1/g'
        #GVM#VERS="${MQINSTBASE}${MQVERBASE}${MQVERBASEMIN}"
        VERS="${MQINSTBASE}${MQVERBASEERE}${MQVERBASEMIN}"
        
        #GVM#SVRMINVER="$( echo -e "${MQRPMS}" | grep -iE "${RPMBASE}.*_${MQINSTBASE}" | \
        
        SVRMINVER="$( echo -e "${_MQRPMSRB}" | grep -iE "${RPMBASE}.*_${MQINSTBASE}" | \
        grep -vE "(${VERS})" | sed 's/[[:cntrl:]]*//g'| sed -e "${(e)VERQUERY}" | sort -u | \
        awk '{print substr($0,length($0),1)}' | head -n 1 )"
        
        #GVM#print_msg "\nMQRPMS=${MQRPMS}~nRMSERVER=${RMSERVER}~nSVRMINVER=${SVRMINVER}~n\
        
        print_msg "\n_MQRPMSRB=${_MQRPMSRB}~nRMSERVER=${RMSERVER}~nSVRMINVER=${SVRMINVER}~n\
        VERQUERY=${VERQUERY}~nVERS=${VERS}" "debug"
        
        # If roll back requested and PATCHVER is not higher than SVRMINVER, cannot roll back
        # := if SVRMINVER is null or unset, expand to 0 instead
        if [[ ! ${SVRMINVER:=0} -lt ${PATCHVER} && ${UNINSTALL} != 1 ]]
          then
            echo -e "${STARS}\nRollback requested and Patch Version ${PATCHVER} \
        is the only removeable version. Run ${NSH} with -U option to uninstall.\n\
        ${STARS}" | fold -sw 80
        
            usage
        fi
        
        # Perform Patch Removal or complete uninstall
        if (( UNINSTALL == 0 ))
          then
        #GVM#    if [[ ${FPVER} == 0 ]]
            if [[ ${VER} == 0 ]]
              then
                ERRORDESC="ERROR 133: Rollback requested, but no Fix Packs are installed \
        on server ${RMSERVER}"
        
                let ERROR_CODE=133
                critical_error
              else
                print_msg "Downgrading MQ Client version ${MQVERBASE}${VER} found at \
        ${INSTPATH} on ${RMSERVER}"
        
                # Build list of Patch RPMs to remove
        #GVM#        QSTRING="(${MQINSTBASE}${MQUPBASE}${FPVER}-${MQVERBASE}${FPVER})"
                QSTRING="(${MQINSTBASE}${MQUPBASE}${VER}-${MQVERBASE}${VER})"
                RMMQRPMS="${RPM_CMD} -ev \$( rpm -qa | ${GREPNC} -E \"${QSTRING}\" | \
        sed 's/[[:cntrl:]]*//g' ) 2>&1"
        
                COUNT="$( nexec -i -l ${SERVER} "rpm -qa | ${GREPNC} -cE \"${QSTRING}\"" )"
                if [[ ${COUNT} == 0 ]]
                  then
                    ERRORDESC="ERROR 131: No ${MQVERBASE}${PATCHVER} patches found on ${RMSERVER}"
                    let ERROR_CODE=131
                    critical_error
                fi
                print_msg "\nCOUNT=${COUNT}~nQSTRING=\n${QSTRING}~n\nRMMQRPMS=\n${RMMQRPMS}" "debug"
                if (( DRYRUN ))
                  then
                    print_msg "\nnexec -i -l ${RMSERVER} \"${RMMQRPMS}\" ; echo -e \"RESULT=\$?\"" "dryrun"
                  else
                    UNINSTOUT="$( nexec -i -l ${RMSERVER} "${RMMQRPMS} ; echo -e \"RESULT=\$?\"" )"
                    let RESULT=$( echo -e "${UNINSTOUT}" | grep "RESULT=" | \
        sed 's/[[:cntrl:]]*//g' | cut -f2 -d'=' )
        
                    print_msg "\nUNINSTOUT=${UNINSTOUT}~nRESULT=${RESULT}" "debug"
                    if [[ ${RESULT} != 0 ]]
                      then
                        ERRORDESC="ERROR 119: Errors encountered during uninstall/downgrade on ${RMSERVER}"
                        let ERROR_CODE=119
                        if [[ -n "${UNINSTOUT}" ]] ; then print_msg "UNINSTOUT=\n${UNINSTOUT}" ; fi
                        critical_error
                      else
                        # Set Primary Instance
                        if (( DRYRUN ))
                          then
                            print_msg "\nnexec -i -l ${RMSERVER} \"${SETMQINST}\"" "dryrun"
                          else
                            MQINSTOUT="$( nexec -i -l ${RMSERVER} "${SETMQINST}" )"
                            print_msg "\nMQINSTOUT=\n${MQINSTOUT}" "debug"
                        fi
                    fi
                fi
                env_check ${RMSERVER}
                # Validate that RPMs were uninstalled#
                if [[ ! ${VER} < ${PATCHVER} ]]
                  then
                    ERRORDESC="ERROR 120: Failed to remove ${MQVERBASE}${PATCHVER} RPMs on ${RMSERVER}"
                    let ERROR_CODE=120
                    critical_error
                  else
                    # Validate removal and Primary Instance setting
                    if [[ ${EXISTING} != 1 || ${#INSTPATH} == 0 ]]
                      then
                        ERRORDESC="ERROR 121: Failed to set Primary Instance on ${RMSERVER}"
                        let ERROR_CODE=121
                        if [[ -n "${MQINSTOUT}" ]] ; then print_msg "MQINSTOUT=\n${MQINSTOUT}" ; fi
                        critical_error
                    fi
                fi
            fi
          else
            # Removing MQ Client install
            #GVM#print_msg "Removing MQ Client found at ${INSTPATH} on ${RMSERVER}"
            print_msg "Removing MQ Client version ${MQVERSION} found at ${INSTPATH} on ${RMSERVER}"
            # -depth instructs find to process the directory contents before the directory
            RMFILES="${FINDCMD} ${APPPATH:=/usr/mqm} ${DATAPATH:=/var/mqm} /etc/opt/mqm "
            if (( PTC )) ; then RMFILES+="/opt/mqm " ; fi
            RMFILES+="-depth -name 'lost+found' -prune -o -path ${APPPATH:=/usr/mqm} "
            RMFILES+="-prune -o -path ${DATAPATH:=/var/mqm}/app* -prune -o -path ${DATAPATH:=/var/mqm} "
            RMFILES+="-prune -o -exec /bin/rm -df '{}' \;"
            QSTRING="${RPMBASE}.*_${MQINSTBASE}.*"
            COUNT="$( nexec -i -l ${RMSERVER} "rpm -qa | ${GREPNC} -cE \"${QSTRING}\"" | \
        sed 's/[[:cntrl:]]*//g' )"
        
            if [[ ${COUNT} == 0 ]]
              then
                ERRORDESC="ERROR 132: No ${RPMBASE}*_${MQINSTBASE}*.rpm RPMs found on ${RMSERVER}"
                let ERROR_CODE=132
                critical_error
            fi
        
        #GVM# Quiet output or get screens of periods and hashes
            if (( ! TAGCNT ))
              then
        #GVM#        fix_install ${RMSERVER} "${_MQRPMSRB}"
                RMMQRPMS="${RPM_CMD} -ev --allmatches --nodeps --noscripts --notriggers"
              else
                RMMQRPMS="${RPM_CMD} -ev --allmatches"
            fi
        #GVM#    if [ "x${(L)SVROS}" = "xsuse" ]
        #GVM#      then
        #GVM#        # -D --dry-run
        #GVM#        # --no-refresh (global)
        #GVM#        # -n --non-interactive (global)
        #GVM#        # -q --quiet (global)
        #GVM#        # -t --terse (global, implies --no-abbrev and --no-color)
        #GVM#        # -u --clean-deps
        #GVM#        # -v --verbose (global)
        #GVM#        #
                #GVM#RMMQRPMS="${ZYPPER} -n -q -t --no-refresh rm -u"
        #GVM#        RMMQRPMS="${ZYPPER} -n -t --no-refresh rm -u"
        #GVM#        if (( DRYRUN )) ; then RMMQRPMS+=" --dry-run" ; fi
        #GVM#    fi
        #GVM#    if [ "x${(L)SVROS}" = "xredhat" ]
        #GVM#      then
        #GVM#        # --color=always/never/auto
        #GVM#        # --comment=<comment>
        #GVM#        # -q --quiet
        #GVM#        # --setopt=<option>=<value> tsflags=test -- dry run, no exec
        #GVM#        # -v --verbose
        #GVM#        # -y --assumeyes
        #GVM#        # 
        #GVM#        #GVM#RMMQRPMS="${YUM} --color=never --comment=\"Removing MQ Client installation\" -q -y remove"
        #GVM#        RMMQRPMS="${YUM} --color=never --comment=\"Removing MQ Client installation\" -y remove"
        #GVM#        if (( DRYRUN )) ; then RMMQRPMS+=" --setopt=tsflags=test" ; fi
        #GVM#    fi
            # If variable is unset or null, substitute value to prevent removing all RPMs
            # sort dictionary-based, field sep '-', 2nd field, reverse order
        #GVM#    RMMQRPMS="${RPM_CMD} -ev --allmatches \$( rpm -qa | grep -iE \"${QSTRING:=\"_none_\"}\" ) 2>&1"
            if [[ ${#RMMQRPMS} == 0 ]]
              then
                ERRORDESC="ERROR 138: Failed to set package manager for ${RMSERVER}"
                let ERROR_CODE=138
                critical_error
              else
                RMMQRPMS+=" \$( rpm -qa | ${GREPNC} -iE \"${QSTRING:=\"_none_\"}\" | \
        sed 's/[[:cntrl:]]*//g' | sort -dt '-' -k 2r ) 2>/tmp/mquninstall.log"
        
                RMMQRPMS+=" ; let RESULT=\$? ; if [[ \${RESULT} == 0 ]] ; then ${RMFILES}"
                RMMQRPMS+=" ; else echo \"RMMQFAILED\" ; fi"
            fi
            print_msg "QSTRING=${QSTRING}~n\nRMMQRPMS=${RMMQRPMS}" "debug"
            if (( DRYRUN ))
              then
                print_msg "\nnexec -i -l ${RMSERVER} \"${RMMQRPMS}\"" "dryrun"
              else
                UNINSTOUT="$( nexec -i -l ${RMSERVER} "${RMMQRPMS}" )"
                let RPMCHECKOUT="$( echo -e "${UNINSTOUT}" | grep -ic "RMMQFAILED" )"
                print_msg "\nUNINSTOUT=\n${UNINSTOUT}~nRESULT=${RESULT}~nRPMCHECKOUT=\
        ${RPMCHECKOUT}" "debug"
        
                if [[ ${RPMCHECKOUT} != 0 ]]
                  then
                    ERRORDESC="ERROR 122: Failed to remove all MQ RPMs on ${RMSERVER}"
                    let ERROR_CODE=122
                    if [[ -n "${UNINSTOUT}" ]] ; then print_msg "UNINSTOUT=\n${UNINSTOUT}" ; fi
                    critical_error
                fi
            fi
        fi
        
        print_msg "\n(${MM}/${DD} $(date +%R)) End rollback_mq" "debug"
        }
        
        1 Reply Last reply Reply Quote 0
        • greg-michaelG
          greg-michael @Michael Vincent
          last edited by

          @Michael-Vincent Part 5

          ################################################################################
          # ptc_symlink
          ################################################################################
          ptc_symlink()
          {
          print_msg "\n(${MM}/${DD} $(date +%R)) Started ptc_symlink" "debug"
          
          unset BASELINKCMD DELLINKCHK DSSVR LINKCHK LINKCMDOUT
          
          local BASELINKCMD="${(e)LINKCMD}"
          local DELLINKCHK=""
          local DSSVR="${1}"
          local LINKCHK=""
          local LINKCMDOUT=""
          
          # Check for existence of /opt/mqm symbolic link to /usr/mqm/MQCV
          LINKCHK="$( find //${DSSVR}/opt -maxdepth 1 -type l -ls 2>/dev/null | grep -icE 'lrwx.*mqm[ \t]*->' )"
          
          print_msg "BASELINKCMD=${(e)BASELINKCMD}~nLINKCHK=${LINKCHK}~nOPTDIR=${OPTDIR}~n\
          UNINSTALL=${UNINSTALL}" "debug"
          
          if [[ ${UNINSTALL} == 1 && ${LINKCHK} == 1 ]]
            then
              # Uninstalling - remove symbolic link
              BASELINKCMD='find /opt -maxdepth 1 -type l -ilname '*mqm*' -exec /bin/rm -vf {} \;'
              if (( DRYRUN ))
                then
                  print_msg "\nnexec -i -l ${DSSVR} \"${(e)BASELINKCMD}\"" "dryrun"
                else
                  LINKCMDOUT="$( nexec -i -l ${DSSVR} ${(e)BASELINKCMD} )"
                  print_msg "BASELINKCMD=${(e)BASELINKCMD}~nLINKCMDOUT=${LINKCMDOUT}" "debug"
                  DELLINKCHK="$( ${LINKCHK} | grep -icE '^l.*mqm ->' )"
                  if [[ ${DELLINKCHK} != 0 ]]
                    then
                      ERRORDESC="ERROR 125: Failed to remove /opt/mqm symbolic link on ${DSSVR}"
                      let ERROR_CODE=125
                      if [[ -n "${LINKCMDOUT}" ]] ; then print_msg "LINKCMDOUT=\n${LINKCMDOUT}" ; fi
                      critical_error
                  fi
              fi
            elif [[ ${UNINSTALL} == 0 ]]
              then
                if [[ ${OPTDIR} == 1 ]]
                  then
                    # Force uninstallation of PTC MQ Client from /opt/mqm
                    export UNINSTALL=1
                    rollback_mq ${DSSVR}
                    # Reset UNINSTALL and OPTDIR values
                    export UNINSTALL=0
                    export OPTDIR=0
                    # Create symbolic link for /opt/mqm -> /usr/mqm/MQCV
                    ptc_symlink ${DSSVR}
                    # Reset environment checks
                    env_check ${DSSVR}
                  elif [[ ${LINKCHK} == 0 ]]
                    then
                      print_msg "Symbolic link not found in /opt/mqm on ${DSSVR} - creating it"
                      unset LINKCHK
                      if (( DRYRUN ))
                        then
                          print_msg "\nnexec -i -l ${DSSVR} \"${(e)BASELINKCMD} ; sleep 5\"" "dryrun"
                        else
                          LINKCMDOUT="$( nexec -i -l ${DSSVR} "${(e)BASELINKCMD} 2>/dev/null \
          ; echo -e \"RESULT=\$?\" ; sleep 5 ; ${FINDCMD} /opt -maxdepth 1 -type l -ilname '*mqm*' -ls 2>/dev/null" )"
          
                          let LINKCHK="$( find //${DSSVR}/opt -maxdepth 1 -type l -ls 2>/dev/null | \
          grep -icE 'l[wrx]{3}.*mqm ->' )"
          
                          print_msg "BASELINKCMD=${(e)BASELINKCMD}~nLINKCHK=${LINKCHK}~n\
          LINKCMDOUT=${LINKCMDOUT}" "debug"
          
                          if [[ ${LINKCHK} == 0 ]]
                            then
                              ERRORDESC="ERROR 124: Failed to create /opt/mqm symbolic link on ${DSSVR}"
                              let ERROR_CODE=124
                              if [[ -n "${LINKCMDOUT}" ]] ; then print_msg "LINKCMDOUT=\n${LINKCMDOUT}" ; fi
                              critical_error
                          fi
                      fi
                fi
          fi
          
          print_msg "\n(${MM}/${DD} $(date +%R)) End ptc_symlink" "debug"
          }
          ################################################################################
          # fix_install
          ################################################################################
          fix_install()
          {
          print_msg "\n(${MM}/${DD} $(date +%R)) Started fix_install" "debug"
          
          unset FIXFILE FIXRPMS FIXRPMSBASE FIXRPMSFP FIXSVR MQFIXCMD MQFIXCMDOUT
          
          local FIXFILE="${MQINSTBASE}${MQVERSION}.tar.gz"
          local FIXRPMS="${2}"
          local FIXRPMSBASE=""
          local FIXRPMSFP=""
          local FIXSVR="${1}"
          local MQFIXCMD=""
          local let MQFIXCMDOUT=99
          
          FIXRPMS="$( for rpm in $(echo -e "${FIXRPMS}") ; do echo -n "${rpm}${RPMSUFFIX} " ; done )"
          #GVM#FIXRPMSBASE="$( echo -e "${FIXRPMS}" | grep -ivE "(BES|${MQVERBASEERE}[^0])" | tr -s '\n' ' ' )"
          #GVM#FIXRPMSFP="$( echo -e "${FIXRPMS}" | grep -ivE "(BES|${MQVERBASEERE}0)" | tr -s '\n' ' ' )"
          FIXRPMSBASE="$( for rpm in $( echo -e "${FIXRPMS}" ) ; do echo -n "${DATAPATH}/MQCV/${rpm}" | \
          grep -ivE "(BES|${MQVERBASEERE}[^0])" ; done )"
          
          FIXRPMSBASE="$( echo -e "${FIXRPMSBASE}" | tr '\n' ' ' )"
          FIXRPMSFP="$( for rpm in $( echo -e "${FIXRPMS}" ) ; do echo -n "${DATAPATH}/MQCV/${rpm}" | \
          grep -ivE "(BES|${MQVERBASEERE}0)" ; done )"
          
          FIXRPMSFP="$( echo -e "${FIXRPMSFP}" | tr '\n' ' ' )"
          MQFIXCMD="${RPMINST} --force ${FIXRPMSFP} 2>&1 ; echo -e \"RESULT=\$?\""
          print_msg "FIXFILE=${FIXFILE}~n\nFIXRPMS=${FIXRPMS}~n\nFIXRPMSBASE=${FIXRPMSBASE}~n\
          \nFIXRPMSFP=${FIXRPMSFP}~nFIXSVR=${FIXSVR}~n\nMQFIXCMD=${MQFIXCMD}~nMQFIXCMD=${MQFIXCMD}" "debug"
          
          if (( DRYRUN ))
            then
              print_msg "copy_files ${FIXSVR} ${SOURCESVR} \"${(e)SOURCEDIR}${PATCHVER}\" \"${FIXFILE}\"" "dryrun"
              print_msg "MQFIXCMDOUT=\"\$( nexec -i -l ${FIXSVR} \"${MQFIXCMD}\" )\"" "dryrun"
            else
              copy_files ${FIXSVR} ${SOURCESVR} "${(e)SOURCEDIR}${PATCHVER}" "${FIXFILE}"
              MQFIXCMDOUT="$( nexec -i -l ${FIXSVR} "${MQFIXCMD}" )"
              print_msg "\nMQFIXCMDOUT=${MQFIXCMDOUT}" "debug"
              if [[ $( echo -e "${MQFIXCMDOUT}" | grep -i "RESULT=" | \
          sed 's/[[:cntrl:]]*//g' | cut -f2 -d'=' ) != 0 ]]
          
                then
                  ERRORDESC="ERROR 140: Errors detected after fixing install on ${FIXSVR}"
                  let ERROR_CODE=140
                  if [[ -n "${MQFIXCMDOUT}" ]] ; then print_msg "MQFIXCMDOUT=\n${MQFIXCMDOUT}" ; fi
                  critical_error
              fi
          fi
          
          print_msg "\n(${MM}/${DD} $(date +%R)) End fix_install" "debug"
          }
          ################################################################################
          # Main
          ################################################################################
          # Check for log path. Create if not found.
          if [[ -d '/tmp' ]]
            then
              export LOGPATH='/tmp'
            elif [[ -d '/C/Temp' ]]
              then
                export LOGPATH='/C/Temp'
          fi
          if [[ ! -d "${LOGPATH}" ]] ; then mkdir -p "${LOGPATH}" ; fi
          
          # Files
          LOGFILE="${LOGPATH}/${NSH}.${MMDD}"
          MAILFILE="${LOGPATH}/${NSH}.mail"
          TMPLOG="${LOGPATH}/${NSH}.$$.${MMDD}${YYYY}${HH}${MIN}.log"
          
          # Clean up prior log file
          if [[ -f ${TMPLOG} ]] ; then rm -f ${TMPLOG} ; fi
          
          print_msg "\n(${MM}/${DD} $(date +%R)) Started ${NSH}"
          
          # Validate number of arguments given
          if [[ ! $# -ge 2 ]] ; then let ERROR_CODE=0 ; usage ; fi
          
          # leading ':' enables quiet processing with '?' and ':' as values when problems
          # are encountered.
          # trailing ':' indicates that an option requires an argument.
          while getopts ":dhp:Rs:Uy" OPT
             do
               case "${OPT}" in
                   d|D) # Enable DEBUG
                        let DEBUG=1
                        print_msg "DEBUG MODE ENABLED"
                        print_msg "DEBUG=${DEBUG}" "debug"
                        ;;
                   h|H) # Help/usage
                        usage
                        ;;
                   p|P) # Patch version to install
                        if [[ $( awk -v num=${OPTARG} 'BEGIN {if (num ~ /[0-9]+/) { print "1" }}' ) == 1 ]]
                          then
                            let PATCHVER=${OPTARG}
                            print_msg "PATCHVER=${PATCHVER}" "debug"
                          else
                            ERRORDESC="ERROR 100: Unrecognized Patch Version: ${OPTARG}"
                            let ERROR_CODE=100
                            critical_error
                        fi
                        ;;
                     R) # Rollback/uninstall MQ Client
                        let ROLLBACK=1
                        print_msg "ROLLBACK PROCESSING"
                        print_msg "ROLLBACK=${ROLLBACK}" "debug"
                        ;;
                   s|S) # Host list
                        HOSTS="${OPTARG}"
                        if [[ $( echo -e "${HOSTS}" | awk '{if ($0 ~ /(,|;|:|\t)/) {print "1"} else {print "0"}}' ) -ge 1 ]]
                          then
                            HOSTS="$( echo -e "${HOSTS}" | tr -s ',:;\t' ' ' )"
                        fi
                        print_msg "HOSTS=${HOSTS}" "debug"
                        ;;
                     U) # Uninstall MQ Client
                        let UNINSTALL=1
                        print_msg "UNINSTALL PROCESSING"
                        print_msg "UNINSTALL=${UNINSTALL}" "debug"
                        ;;
                   y|Y) # Enable DRYRUN
                        let DRYRUN=1
                        print_msg "Executing DRYRUN"
                        print_msg "DRYRUN=${DRYRUN}" "debug"
                        ;;
                   \?) # Invalid option
                        print_msg "Invalid option ${OPTARG} provided"
                        usage
                        ;;
                   \:) # Missing required argument to option
                        print_msg "Option ${OPTARG} requires an argument."
                        usage
                        ;;
               esac
          done
          
          # remove processed options leaving what remains as $@
          shift $(( OPTIND - 1 ))
          if [[ -n "$@" ]] ; then print_msg "\$@=$@" "debug" ; fi
          
          # ROLLBACK and UNINSTALL are mutually exclusive
          if [[ ${UNINSTALL} == 1  && ${ROLLBACK} == 1 ]]
            then
              print_msg "Rollback and Uninstall options are mutually exclusive"
              usage
          fi
          
          # Check for tarball on source server
          # (e) Perform parameter expansion, command substitution and arithmetic expansion
          # on the result.
          #
          # Expected tar file name format: MQCV-9.2.0-X.tar.gz
          #
          TARBALL="$( ls //${SOURCESVR}${SOURCEPATH} 2>/dev/null | \
          grep -iE "${(e)SOURCEFILES}" | sed 's/[[:cntrl:]]*//g' | sort -d )"
          
          TARNUM=$( echo -e "${TARBALL}" | grep -icE "${(e)SOURCEFILES}" )
          
          #GVM#print_msg "\nTARBALL=\n$( echo -e "${TARBALL}" | sed 's/\(^.*$\)/\\t\1/g' )\
          #GVM#~nTARNUM=${TARNUM}" "debug"
          print_msg "~nTARBALL=\n$( echo -e "${TARBALL}" | sed 's/\(^.*$\)/\\t\1/g' )\
          ~nTARNUM=${TARNUM}" "debug"
          
          # If PATCHVER is not passed in as an argument, determine most recent patch level
          # based on tarball name on source server
          if [[ ${TARNUM} -ge 1 && ${PATCHVER} == 0 ]]
            then
              let PATCHVER="$( echo -e "${TARBALL}" | tail -n 1 | awk '{
          print substr($0,index($0,".tar.gz")-1,1) }' )"
          
              print_msg "PATCHVER=${PATCHVER}" "debug"
          fi
          
          # Validate PATCHVER is set and use it to set TARFILE
          if [[ ${PATCHVER} == 0 ]]
            then
              ERRORDESC="ERROR 101: Failed to set Patch Version"
              let ERROR_CODE=101
              critical_error
            else
          #GVM#    TARFILE="$( echo -e "${TARBALL}" | grep -iE "${MQVERBASE}${PATCHVER}" )"
          #GVM#    TARFILE="$( echo -e "${TARBALL}" | grep -iE "${MQVERBASEERE}${PATCHVER}" )"
              TARFILE="$( echo -e "${TARBALL}" | \
          grep -iE "${MQVERBASEERE}${PATCHVER}" | sed 's/[[:cntrl:]]*//g' | tail -n 1 )"
          #GVM#    print_msg "TARFILE=${TARFILE}" "debug"
              if [[ ! -n ${TARFILE} ]]
                then
                  ERRORDESC="ERROR 102: Failed to set TARFILE"
                  let ERROR_CODE=102
                  critical_error
                else
                  # (e) expand variable first
                  # #*- strip off all characters up to and including the first '-'
                  # /.tar.gz search and remove '.tar.gz'
                  # %-* print all characters up to and including the first '-'
                  # starts with MQCV-9.3.0-4.tar.gz
                  # ends with 9.3.0-
                  MQVERBASE="$( echo -e "${${${(e)TARFILE#*-}/.tar.gz}%-*}-" )"
                  # strip all '.' and '-' characters
                  typeset -i BASECMDLVL=$( echo -e "${MQVERBASE}" | tr -d '.-' )
                  MQUPBASE="U$( echo -e "${BASECMDLVL}" )"
                  print_msg "TARFILE=${TARFILE}~nBASECMDLVL=${BASECMDLVL}~nMQUPBASE=${MQUPBASE}\
          ~nMQVERBASE=${MQVERBASE}" "debug"
          
              fi
          fi
          
          # Build RPM lists
          if (( ! UNINSTALL ))
            then
              for rpm in ${MQRPMS}
                 do
                   RPMINSTLIST+="${DATAPATH}/MQCV/${rpm}${MQINSTBASE}${MQVERBASE}${MQVERBASEMIN}${RPMPLATFORM}\
          ${RPMSUFFIX} "
          
                   RPMUPLIST+="${DATAPATH}/MQCV/${rpm}${MQINSTBASE}${MQUPBASE}${PATCHVER}-\
          ${MQVERBASE}${PATCHVER}${RPMPLATFORM}${RPMSUFFIX} "
          
              done
              print_msg "\nRPMINSTLIST=${RPMINSTLIST}~n\nRPMUPLIST=${RPMUPLIST}" "debug"
          fi
          
          # Process hosts list one server at a time
          for host in ${HOSTS}
             do
               print_msg "Processing ${host}"
               # Validate environment
               env_check ${host}
               # If uninstalling or rolling back
               if (( ROLLBACK || UNINSTALL ))
                 then
                   # If no install is found
                   if [[ ${EXISTING} == 0 && ${NEWINST} == 0 ]]
                     then
                       print_msg "No installations of MQ Client found on ${host}"
                     # Verify requested version to rollback matches installed version
          #GVM#           elif (( PATCHVER < VER && MAJVER >= 9 ))
                     elif [[ ${BASECMDLVL}${PATCHVER} < ${MAXCMDLVL}${VER} && ${MAJVER} -ge 9 ]]
                       then
                         ERRORDESC="ERROR 103: Requested version to rollback \
          \"${MQVERBASE}${PATCHVER}\" is below installed version \"${MQVERBASE}${VER}\""
          
                         let ERROR_CODE=103
                         critical_error
                       else
                         # Perform rollback on host
                         rollback_mq ${host}
                   fi
                 # If host is already running requested patch version
          #GVM#       elif [[ ${PATCHVER} == ${VER} ]]
                 elif [[ ${BASECMDLVL}${PATCHVER} == ${MAXCMDLVL}${VER} ]]
                   then
                     print_msg "${host} is already running version ${MQVERBASE}${PATCHVER}"
                     if (( BESINSTALL )) ; then install_bes ${host} ; fi
                   else
                     # Install or apply Fix Pack
                     # Create /opt/mqm symbolic link for PTC environment
                     if (( PTC )) ; then ptc_symlink ${host} ; fi
                     # Copy files to target
                     # Avoid copying files twice if BASECMDLVL > MAXCMDLVL (9.3.0 > 9.2.0)
          #GVM#           if [[ ${ROLLBACK} == 0 && ${UNINSTALL} == 0 ]]
                     if [[ ${ROLLBACK} == 0 && ${UNINSTALL} == 0 && ${BASECMDLVL} > ${MAXCMDLVL} ]]
                       then
          #GVM#               copy_files ${host} ${SOURCESVR} "${SOURCEDIR}${PATCHVER}" "${TARFILE}"
                         copy_files ${host} ${SOURCESVR} "${(e)SOURCEDIR}${PATCHVER}" "${TARFILE}"
                     fi
                     # Install BESAgent if not installed
                     if (( BESINSTALL )) ; then install_bes ${host} ; fi
          #GVM#           if (( NEWINST ))
                     if [[ ${NEWINST} == 1 || ${MAXCMDLVL} < ${BASECMDLVL} ]]
                       then
                         # New install
                         install_mq ${host} "${RPMINSTLIST}"
                       else
                         # Fix Pack install
                         install_mq ${host} "${RPMUPLIST}"
                     fi
                     # Clean up RPMs and tarballs
                     # ':=' If unset or null, set DATAPATH to /var/mqm to prevent any possibility
                     # of acting on files in the / file system
                     if (( DRYRUN ))
                       then
          #GVM#               print_msg "\nnexec -i -l ${host} \"/bin/rm -dfR \
          #GVM#${DATAPATH:=/var/mqm}/MQCV ; /bin/rm -dfR ${DATAPATH:=/var/mqm}/BESClient\"" "dryrun"
                         print_msg "\nnexec -i -l ${host} \"/bin/rm -dfR \
          ${DATAPATH:=/var/mqm}/MQCV ; /bin/rm -f ${DATAPATH:=/var/mqm}/MQCV-*.*.*-*.tar.gz ; \
          /bin/rm -dfR ${DATAPATH:=/var/mqm}/BESClient\"" "dryrun"
          
                       else
          #GVM#               nexec -i -l ${host} "/bin/rm -dfR ${DATAPATH:=/var/mqm}/MQCV ; \
          #GVM#/bin/rm -dfR ${DATAPATH:=/var/mqm}/BESClient"
          #GVM#               nexec -i -l ${host} "/bin/rm -dfR ${DATAPATH:=/var/mqm}/MQCV ; \
          #GVM#/bin/rm -f ${DATAPATH:=/var/mqm}/MQCV-*.*.*-*.tar.gz ; /bin/rm -dfR ${DATAPATH:=/var/mqm}/BESClient"
                         nexec -i -l ${host} "${(e)CLEANCMD}"
                     fi
               fi
               # Skip copying log file for dry run
               if (( ! DRYRUN ))
                 then
                   if (( UNINSTALL ))
                     then
                       cp ${TMPLOG} //${host}${MQCVPATH}/${NSH}.${MMDD}${YYYY}${HH}${MIN}.uninstall.log
                     else
                       cp ${TMPLOG} //${host}${MQCVPATH}/${NSH}.${MMDD}${YYYY}${HH}${MIN}.log
                   fi
               fi
          done
          
          print_msg "\n(${MM}/${DD} $(date +%R)) Finished ${NSH}"
          #-------------------------------------------------------------------------------
          # Retention is listed below at 90 days for logs and datafiles. Ask user of
          # process for actual retention specifications and change accordingly.
          #-------------------------------------------------------------------------------
          CURRDIR="${PWD}"
          cd "${LOGPATH}"
          find -path "${LOGPATH}" \( -name ${NSH}'.*.log' -o -name 'delete.*' \) -mtime +90 \
          -exec /bin/rm -f {} \; 2>>${LOGPATH}/delete.${MMDD}
          
          cd "${CURRDIR}"
          
          # Process log files and exit
          critical_error
          #END
          
          Michael VincentM 1 Reply Last reply Reply Quote 0
          • Michael VincentM
            Michael Vincent @greg-michael
            last edited by

            @greg-michael

            I think something went wrong with the cut and pastes, from line 403 on it lexes as a string:

            6f87ede3-fe92-413e-88e4-4da88782d6d3-image.png

            greg-michaelG 1 Reply Last reply Reply Quote 0
            • MAPJe71M
              MAPJe71
              last edited by

              The following two lines in the ptc_symlink-function are the problem:

              LINKCMDOUT="$( nexec -i -l ${DSSVR} "${(e)BASELINKCMD} 2>/dev/null \
              ; echo -e \"RESULT=\$?\" ; sleep 5 ; ${FINDCMD} /opt -maxdepth 1 -type l -ilname '*mqm*' -ls 2>/dev/null" )"
              

              When you escape two additional double-quotes, refresh or save the file, the fix_install-function is listed
              e.g.

              LINKCMDOUT="$( nexec -i -l ${DSSVR} \"${(e)BASELINKCMD} 2>/dev/null \
              ; echo -e \"RESULT=\$?\" ; sleep 5 ; ${FINDCMD} /opt -maxdepth 1 -type l -ilname '*mqm*' -ls 2>/dev/null\" )"
              
              greg-michaelG 1 Reply Last reply Reply Quote 1
              • greg-michaelG
                greg-michael @MAPJe71
                last edited by greg-michael

                @MAPJe71 Interesting… I have a few other lines throughout the script that utilize the same syntax structure I believe. Why wouldn’t those functions be affected the same way? For example, lines #370-#375, lines #814-#815, lines #1271-#1272, line #1321, line #1333, and lines #1384-#1385.

                For what it’s worth, I’ll explain what the line is doing from an application perspective.

                This script runs in BMC’s TrueSight Server Automation as an NSH script. NSH is based on the ZShell. The syntax of the command is such that the subshell command “nexec” is doing a remote shell execution on a target server to create a symbolic link, echo the result with a “RESULT=” prefix, waits 5 seconds, and then does a find command to list out the contents of the /opt path looking for symbolic links.

                The output looks similar to this:

                RESULT=0
                nexec -i -l algebs.ds.cpr.ca "/bin/find /opt -type l -ilname '*mqm*' -ls"
                      867      0 lrwxrwxrwx   1  mqm      mqm            21 Nov  9  2021 /opt/mqm/bin -> /usr/mqm/MQSV9202/bin
                

                Thanks!

                MAPJe71M 1 Reply Last reply Reply Quote 0
                • greg-michaelG
                  greg-michael @Michael Vincent
                  last edited by

                  @Michael-Vincent said in Function List incomplete:

                  @greg-michael

                  I think something went wrong with the cut and pastes, from line 403 on it lexes as a string:

                  I went back and copied that section of pasted code separately from the forum post into a new Shell-formatted document in NP++ and it looked normal. Did you possibly miss a starting quote in the copy/paste from the forum into your NP++?

                  1 Reply Last reply Reply Quote 0
                  • MAPJe71M
                    MAPJe71 @greg-michael
                    last edited by

                    @greg-michael

                    Any part of the source that matches the commentExpr of the parser is skipped during the search for class, method and function definitions.
                    For the majority of the available parsers this feature is used to prevent detection of function definitions in text definitions (aka string literals). The detection of string literals highly depends on the proper i.e. quote balanced text definitions. Any improper definition can lead to all kinds of unexpected results.

                    For instance double quoted string literals start and end with a double quote and any double quote within must be escaped.

                    AFAICT a lot of the double quoted string definitions in the provided source contain un-escaped double quotes.

                    greg-michaelG 1 Reply Last reply Reply Quote 2
                    • greg-michaelG
                      greg-michael @MAPJe71
                      last edited by

                      @MAPJe71 said in Function List incomplete:

                      For instance double quoted string literals start and end with a double quote and any double quote within must be escaped.

                      This is true, except when using a subshell call : $( … ). The double quotes within the subshell execution are treated separately from the string literal definition. At least that’s the way I’ve learned to use them in Shell scripting.

                      AFAICT a lot of the double quoted string definitions in the provided source contain un-escaped double quotes.

                      For those strings within a string, yes, they are escaped. For those commands being executed within a subshell call, and the results being returned and stored as a String, no.

                      MAPJe71M 1 Reply Last reply Reply Quote 0
                      • MAPJe71M
                        MAPJe71 @greg-michael
                        last edited by MAPJe71

                        @greg-michael

                        those strings within a string

                        for the parser (presuming ... does not contain double quotes):
                        string_literal_name=" ... \" ... \" ... "
                        string_literal_name="${ ... \" ... \" ... }"
                        and those strings within a string within a string:
                        string_literal_name="${ ... \" ... \\\" ... \\\" ... \" ... }"

                        commands being executed within a sub shell call, and the results being returned and stored as a String

                        string_literal_name=${ ... }

                        The parser will see at least two string literals in the following line:
                        string_literal_name="${ part1 " part2 " part3 }"
                        i.e. "${ part1 " and " part3 }"

                        greg-michaelG 1 Reply Last reply Reply Quote 2
                        • greg-michaelG
                          greg-michael @MAPJe71
                          last edited by

                          @MAPJe71 said in Function List incomplete:

                          for the parser (presuming ... does not contain double quotes):
                          string_literal_name=" ... \" ... \" ... "
                          string_literal_name="${ ... \" ... \" ... }"
                          and those strings within a string within a string:
                          string_literal_name="${ ... \" ... \\\" ... \\\" ... \" ... }"

                          commands being executed within a sub shell call, and the results being returned and stored as a String

                          string_literal_name=${ ... }

                          The parser will see at least two string literals in the following line:
                          string_literal_name="${ part1 " part2 " part3 }"
                          i.e. "${ part1 " and " part3 }"

                          Is it safe to assume that your use of the curly braces in lieu of the parentheses is accidental?

                          MAPJe71M 1 Reply Last reply Reply Quote 0
                          • MAPJe71M
                            MAPJe71 @greg-michael
                            last edited by

                            @greg-michael Yes

                            1 Reply Last reply Reply Quote 0
                            • First post
                              Last post
                            The Community of users of the Notepad++ text editor.
                            Powered by NodeBB | Contributors