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 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