#!/bin/bash
# INSTALL
# This INSTALL script is meant to install niusrpriodistributioni 18.0.0f0 onto
# a Linux system.
#
#   Copyright 2004-2018,
#  National Instruments Corporation.
#  All Rights reserved.
#

kProductVersion="18.0.0f0"
kProductName="niusrpriodistributioni"
kProductStringSentence="NI USRP RIO distribution installer"
kProductStringBanner="NI USRP RIO distribution installer"

# Check if a value exists in a list
# returns  statusSuccess if value exists, statusFailure otherwise
in_array()
{
   value=$1
   shift
   for elem in $*
   do
      if [ "$value" = "$elem" ]; then
         return 0
      fi
   done
   return 1
}
rpmInstallerContentsPackageList=" ni-kal-17.5.1.49152-0+f0.noarch.rpm niusrprioi-18.0.0.49154-f2.x86_64.rpm ni-apal-errors-17.0.0.49152-0+f0.noarch.rpm ni-bds-17.5.0.49152-0+f0.noarch.rpm ni-bds-nikalmod-17.5.0.49152-0+f0.i386.rpm ni-bds-nikalmod-17.5.0.49152-0+f0.x86_64.rpm nifpgai-17.0.0-f0.i386.rpm nifpgai-17.0.0-f0.x86_64.rpm nifpgai-32bit-17.0.0-f0.x86_64.rpm nifpgaidsi-17.0.0-f1.i386.rpm nifpgaidsi-17.0.0-f1.x86_64.rpm nifpgaidsi-32bit-17.0.0-f1.x86_64.rpm nip2pi-17.5.0-f0.i386.rpm nip2pi-17.5.0-f0.x86_64.rpm nip2pi-32bit-17.5.0-f0.x86_64.rpm nip2pki-17.5.0-f0.i386.rpm nip2pki-17.5.0-f0.x86_64.rpm nirioi-17.0.0-f0.x86_64.rpm nirioki-17.0.0-f0.x86_64.rpm niusrprioki-18.0.0.49154-f2.x86_64.rpm ni-usrp-rio-rpc-18.0.0.49153-0+f1.i386.rpm ni-usrp-rio-rpc-18.0.0.49153-0+f1.x86_64.rpm"
rpmSkipSanityCheckList=""
dualModeRpmsList="nifpgai-17.0.0-f0.i386.rpm nifpgai-17.0.0-f0.x86_64.rpm nifpgai-32bit-17.0.0-f0.x86_64.rpm nifpgaidsi-17.0.0-f1.i386.rpm nifpgaidsi-17.0.0-f1.x86_64.rpm nifpgaidsi-32bit-17.0.0-f1.x86_64.rpm nirioi-17.0.0-f0.x86_64.rpm nip2pi-17.5.0-f0.i386.rpm nip2pi-17.5.0-f0.x86_64.rpm nip2pi-32bit-17.5.0-f0.x86_64.rpm"
if uname -p | grep i686 > /dev/null
then
debInstallerContentsPackageList="niapalerri_17.0.0.49152-0+f0_all.deb nibdski_17.5.0.49152-0+f0_all.deb ni-kal_17.5.1.49152-0+f0_all.deb nikali_17.5.1.49152-0+f0_all.deb ni-apal-errors_17.0.0.49152-0+f0_all.deb ni-bds_17.5.0.49152-0+f0_all.deb ni-bds-nikalmod_17.5.0.49152-0+f0_i386.deb nifpgai_17.0.0-f0_i386.deb nifpgai-32bit_17.0.0-f0_i386.deb nifpgaidsi_17.0.0-f1_i386.deb nifpgaidsi-32bit_17.0.0-f1_i386.deb nip2pi_17.5.0-f0_i386.deb nip2pi-32bit_17.5.0-f0_i386.deb nip2pki_17.5.0-f0_i386.deb ni-usrp-rio-rpc_18.0.0.49153-0+f1_i386.deb"
else
debInstallerContentsPackageList="niapalerri_17.0.0.49152-0+f0_all.deb nibdski_17.5.0.49152-0+f0_all.deb ni-kal_17.5.1.49152-0+f0_all.deb nikali_17.5.1.49152-0+f0_all.deb niusrprioi_18.0.0.49154-f2_amd64.deb ni-apal-errors_17.0.0.49152-0+f0_all.deb ni-bds_17.5.0.49152-0+f0_all.deb ni-bds-nikalmod_17.5.0.49152-0+f0_amd64.deb nifpgai_17.0.0-f0_amd64.deb nifpgaidsi_17.0.0-f1_amd64.deb nip2pi_17.5.0-f0_amd64.deb nip2pki_17.5.0-f0_amd64.deb nirioi_17.0.0-f0_amd64.deb nirioki_17.0.0-f0_amd64.deb niusrprioki_18.0.0.49154-f2_amd64.deb ni-usrp-rio-rpc_18.0.0.49153-0+f1_amd64.deb"
fi
dualModeDebsList="nifpgai_17.0.0-f0_i386.deb nifpgai_17.0.0-f0_amd64.deb nifpgai-32bit_17.0.0-f0_i386.deb nifpgaidsi_17.0.0-f1_i386.deb nifpgaidsi_17.0.0-f1_amd64.deb nifpgaidsi-32bit_17.0.0-f1_i386.deb nirioi_17.0.0-f0_amd64.deb nip2pi_17.5.0-f0_i386.deb nip2pi_17.5.0-f0_amd64.deb nip2pi-32bit_17.5.0-f0_i386.deb"
# Set the path
PATH=/bin:/usr/bin:/usr/X11R6/bin:/sbin:/usr/sbin:/usr/local/bin
export PATH

# General constants
kNo=0
kYes=1
kFalse=0
kTrue=1
statusSuccess=0
statusFail=1

# Additionally constants
kLicense="LICENSE.txt"
kPatents="PATENTS.txt"

kTarPackageName="$kProductName-$kProductVersion.tar.gz"
kTmpInstallSrcPath="/tmp/$kProductName-$kProductVersion.install"
kInstallationLog="/etc/natinst/$kProductName-$kProductVersion.plist"
kInstallerBinDir="$kTmpInstallSrcPath/bin"

# Error messages
eNotFound="Not found in current path"
eInvalidSel="Invalid selection."
eInstallAborted="Installer is aborted."
eInstallComplete="Installer is finished."
eVersionUnknown="Version cannot be determined"
eNoDiskSpace="There is insufficient free disk space to"

# configuration option defaults
# RPM is used by default if dpkg is unavailable
bUseRpm=$kTrue
bUseDpkg=$kFalse

niDistributionCheck()
{
   echo "National Instruments products support the following Linux distributions:"
   echo "   openSUSE"
   echo "   Red Hat Enterprise Linux Desktop + Workstation"
   echo "   Fedora"
   echo "   Scientific Linux"
   echo "   Debian"
   echo "   Ubuntu"
   echo "Refer to README.txt for the latest information at the time of release."
   echo "Refer to www.ni.com/linux for the most recent information about Linux"
   echo "support at National Instruments."
}

# versionCompare() - compares two RPM-style version numbers and returns 255, 0, 1
# to indicate if the first verison is less than, equal to, or greater than
# the second.  Version numbers can be specified with or without release
# suffixes.  Alpha, beta, etc. suffixes should always specified be in the
# release portion.
#
# Examples:
#  versionCompare 1.0  1.0.1
#  versionCompare 1.0-a1 1.0-a12
#  versionCompare 1.0.1-b1 1.0-1
#  versionCompare 2.2.3.4-99  2.2.4
#  versionCompare 8.0-b129 8.0-rc0
#  versionCompare 8.0-rc0 8.0-1
versionCompare()
{
   canonicalizeVersion()
   {
      canonicalVersion=`echo "$1" |
         $SED -e 's,\([0-9]\)\([A-Za-z]\),\1.000.\2,g' \
             -e 's,\([A-Za-z]\)\([0-9]\),\1.\2,g' \
             -e 's,^\([A-Za-z]\),---.\1,' \
             -e 's,\b\([0-9]\)\b,00\1,g' \
             -e 's,\b\([0-9][0-9]\)\b,0\1,g'`
   }

   local arg1 arg2 nResult firstVersion secondVersion resultVersion
   if [ "$1" = "$2" ]; then
      return 0;
   fi
   arg1=`echo "$1" | $SED 's,-.*$,,'`
   arg2=`echo "$2" | $SED 's,-.*$,,'`
   if [ "$1" != "$arg1" -o "$2" != "$arg2" ]; then
      versionCompare "$arg1" "$arg2" >/dev/null 2>&1
      nResult=$?
      if [ $nResult -ne 0 ]; then
         return $nResult
      fi
   fi
   canonicalizeVersion `echo "$1" | $SED 's,^.*-,,'`
   firstVersion="$canonicalVersion"
   canonicalizeVersion `echo "$2" | $SED 's,^.*-,,'`
   secondVersion="$canonicalVersion"
   resultVersion=`(echo "$firstVersion"; echo "$secondVersion") |
      LC_ALL=C sort -t. -k 1 -k 2 -k 3 -k 4 -k 5 -k 6 -k 7 -k 8 -k 9 -k 10 | head -1`
   if [ "$firstVersion" = "$resultVersion" ]; then
      return 255
   else
      return 1
   fi
}

# findutil gets the path to a utility
# Input: $1: name of utility to find
# Output: $FINDUTIL: path of found utility or empty string
# Returns: 0=success, nonzero=failure
FINDUTIL=""
findutil()
{
   # Validate inputs
   if [ -z $1 ]; then
      return $statusFail
   fi
   # Use which to locate the executable
   FINDUTIL=`which $1 --skip-alias 2> /dev/null`
   # If not found, display an error
   if [ -z "$FINDUTIL" ]; then
      STRING="$1"
      # Pad spaces to account for aesthetics
      while [ ${#STRING} -lt 10 ]; do
         STRING="$STRING "
      done
      echo "$STRING $eNotFound"
      return $statusFail
   fi
   return $statusSuccess
}

# rpmquery gets the version of a package from the RPM database
# Input: $1: package name to query
#        $RPM: path of RPM executable
# Output: $RPMQUERY: version string of package
# Returns: 0=success, nonzero=failure
RPMQUERY=""
rpmquery()
{
   # Validate inputs
   if [ -z "$RPM" -o -z "$1" ]; then
      return $statusFail
   fi
   # Query RPM database
   output=`$RPM -q --qf "[%{VERSION}\n]" $1 2> /dev/null`
   result=$?
   RPMQUERY=`echo $output | head -1`
   # If the RPM query failed, return an error
   return $result
}

# dpkgquery gets the version of a package from the dpkg database
# Input: $1: package name to query
#        $DPKG_QUERY: path of dpkg-query executable
# Output: $DPKGQUERY_RESULT: version string of package
# Returns: 0=success, nonzero=failure
DPKGQUERY_RESULT=""
dpkgquery()
{
   # Validate inputs
   if [ -z "$DPKG_QUERY" -o -z "$1" ]; then
      return $statusFail
   fi
   # Query with dpkg
   DPKGQUERY_RESULT=`$DPKG_QUERY -W -f='\${Version}\n' $1 2> /dev/null`
   return $?
}

# inputynq get a yes / no / quit response from the user
# Input: $1: Prompt string associated with input
#        $2: Default selection
# Output: $INPUT: character entered and accepted
# Returns: Nothing
INPUT=""
inputynq()
{
   inputynqLOOP=$kYes
   while [ $inputynqLOOP -eq $kYes ]; do
      echo -n "$1"
      read INPUT
      test -z "$INPUT" && INPUT="$2"
      case "$INPUT" in
      [YyNn])
         inputynqLOOP=$kNo
         ;;
      [Qq])
         cleanexit $statusFail
         ;;
      *)
         echo -n "$eInvalidSel  "
         ;;
      esac
   done
}

get_file_base()
{
   if [ -s "$CDPATH/$1" ]; then
      # installing from CD, or already expanded the packages in the current dir
      INSTALLSRCPATH="$CDPATH"
   elif [ -s "$kTmpInstallSrcPath/$1" ]; then
      # already exists due to previous call to this function
      INSTALLSRCPATH="$kTmpInstallSrcPath"
   elif [ -s "$CDPATH/$kTarPackageName" ]; then
      # installing from other directory (net or local copy from web or ftp)
      INSTALLSRCPATH="$kTmpInstallSrcPath"
      $TAR -x -C "$kTmpInstallSrcPath" -f "$CDPATH/$kTarPackageName" "$1" 1>/dev/null 2>&1
   else
      echo "You need to place $kTarPackageName in this directory."
      cleanexit $statusFail
   fi
}

get_dir_base()
{
   if [ -d "$CDPATH/$1" ]; then
      # installing from CD, or already expanded the packages in the current dir
      INSTALLSRCPATH="$CDPATH"
   elif [ -d "$kTmpInstallSrcPath/$1" ]; then
      # already exists due to previous call to this function
      INSTALLSRCPATH="$kTmpInstallSrcPath"
   elif [ -s "$CDPATH/$kTarPackageName" ]; then
      # installing from other directory (net or local copy from web or ftp)
      INSTALLSRCPATH="$kTmpInstallSrcPath"
      $TAR -x -C "$kTmpInstallSrcPath" -f "$CDPATH/$kTarPackageName" "$1/*" 1>/dev/null 2>&1
   else
      echo "You need to place $kTarPackageName in this directory."
      cleanexit $statusFail
   fi
}

# initNIDrivers attempt to start or stop all NI Drivers on the system.
#   This is done by searching for all init scripts for the current run
#   level that are just links in /etc/init.d to a natinst location.
# Input: $1: init action, start or stop are the only valid options
# Output: Nothing
# Returns: statusSuccess or statusFail
initNIDrivers ()
{
   initAction=$1
   if [ "$initAction" = "start" ]; then
      sortCommand="$SORT"
   elif [ "$initAction" = "stop" ]; then
      sortCommand="$SORT -r"
   else
      echo "initNIDrivers unknown action: $initAction"
      return $statusFail
   fi

   currentRunLevel="`$RUNLEVEL | $AWK '{ print $2}'`"
   if [ -d /etc/rc${currentRunLevel}.d ]; then
      currentRunLevelDir=/etc/rc${currentRunLevel}.d
   elif [ -d /etc/init.d/rc${currentRunLevel}.d ]; then
      currentRunLevelDir=/etc/init.d/rc${currentRunLevel}.d
   else
      return $statusFail
   fi

   for strInitModule in `ls ${currentRunLevelDir}/S* | $sortCommand`; do
      strInitModule=${strInitModule##*\/}
      strInitModule=${strInitModule#S[0-9][0-9]}
      if [ `ls -al /etc/init.d/$strInitModule 2> /dev/null | $GREP -wc natinst` -ne 0 ]; then
         /etc/init.d/$strInitModule $initAction >/dev/null 2>&1
         nReturnValue=$?
         if [ $nReturnValue -ne 0 ]; then
            return $nReturnValue
         fi
      fi
   done

   return $statusSuccess
}

reloadNIDrivers ()
{
   initNIDrivers stop
   nReturnValue=$?
   if [ $nReturnValue -ne 0 ]; then
      return $nReturnValue
   fi
   initNIDrivers start
   return $?
}

# getNIShareDir returns the path to the NI Share Dir
# Input: $1: Install Prefix: (eg /usr/local)
# Output: strNIShareDir: path to the NI Share dir
# Returns: 0=success, nonzero=failure
getNIShareDir()
{
   if [ -z "$1" ] ; then
      strInstallPrefix="/usr/local"
   else
      strInstallPrefix="$1"
   fi

   strNIShareDir=""
   if [ -e "/etc/natinst/share/share.dir" ] ; then
      strNIShareDir="`cat /etc/natinst/share/share.dir 2>/dev/null`"
      if [ -d "$strNIShareDir" ] ; then
         return $statusSuccess
      else
         strNIShareDir=""
      fi
   fi

   # Attempt to locate the old style of NI Share Directory.
   strOldNIShareDir=""
   if [ -d "$strInstallPrefix/share/natinst" ] ; then
      strOldNIShareDir="$strInstallPrefix/share/natinst"
   elif [ -d "/usr/local/share/natinst" ] ; then
      strOldNIShareDir="/usr/local/share/natinst"
   elif [ -n "$NI_SHARED_PATH" ] && [ -d "$NI_SHARED_PATH" ] ; then
      strOldNIShareDir="$NI_SHARED_PATH"
   elif [ -n "$NISHAREPATH" ] && [ -d "$NISHAREPATH" ] ; then
      strOldNIShareDir="$NISHAREPATH"
   fi

   # Attempt to locate the new style of NI Share Directory.
   strNewNIShareDir=""
   if [ -d "$strInstallPrefix/natinst/share" ] ; then
      strNewNIShareDir="$strInstallPrefix/natinst/share"
   elif [ -d "/usr/local/natinst/share" ] ; then
      strNewNIShareDir="/usr/local/share/natinst"
   fi

   # If the new style NI Share Dir was not found, create one.
   if [ -z "$strNewNIShareDir" ] ; then
      strNewNIShareDir="$strInstallPrefix/natinst/share"
      mkdir -p "$strNewNIShareDir"
   fi

   # If the old style NI Share Dir matches the new style NI Share Dir, disregard it.
   if [ -n "$strOldNIShareDir" ] && [ "$strOldNIShareDir" = "$strNewNIShareDir" ] ; then
      strOldNIShareDir=""
   fi

   # If the strOldNIShareDir variable is still set, we may need to shift
   # some of the contents from this old style directory to the new style one.
   if [ -n "$strOldNIShareDir" ] ; then
      # Preserve the "errors" subdirectory if it exists and is not a link.
      if [ -d "$strOldNIShareDir/errors" ] && [ ! -L "$strOldNIShareDir/errors" ] ; then
         cp -rpu "$strOldNIShareDir/errors" "$strNewNIShareDir/errors"
         # Delete the old "errors" subdirectory.
         rm -rf "$strOldNIShareDir/errors"
         # Create the link from the old "errors" subdirectory to the new one.
         ln -s -f "$strNewNIShareDir/errors" "$strOldNIShareDir/errors"
      fi
      # Preserve the "Licenses" subdirectory if it exists and is not a link.
      if [ -d "$strOldNIShareDir/Licenses" ] && [ ! -L "$strOldNIShareDir/Licenses" ] ; then
         cp -rpu "$strOldNIShareDir/Licenses" "$strNewNIShareDir/Licenses"
         # Delete the old "Licenses" subdirectory.
         rm -rf "$strOldNIShareDir/Licenses"
         # Create the link from the old "Licenses" subdirectory to the new one.
         ln -s -f "$strNewNIShareDir/Licenses" "$strOldNIShareDir/Licenses"
      fi
   fi

   # Make sure that we create the share.dir file in the etc subdir.
   if [ ! -d "$strNewNIShareDir/etc" ] ; then
      mkdir "$strNewNIShareDir/etc"
   fi

   # Create the share.dir file.
   if [ -e "$strNewNIShareDir/etc/share.dir" ] ; then
      rm -f "$strNewNIShareDir/etc/share.dir"
   fi
   echo "$strNewNIShareDir" > "$strNewNIShareDir/etc/share.dir"

   if [ ! -d  "/etc/natinst" ] ; then
      # Create the "/etc/natinst" directory if necessary.
      mkdir -p "/etc/natinst"
   elif [ -e "/etc/natinst/share" ] ; then
      # Remove the share link if it exists.
      rm -f "/etc/natinst/share"
   fi

   # Create the "/etc/natinst/share" link.
   ln -s -f "$strNewNIShareDir/etc" "/etc/natinst/share"

   # We have succeeded.
   strNIShareDir="$strNewNIShareDir"
   return $statusSuccess
}

# getRpmTransactionColor figures out whether the system RPM is configured
# for colored transactions or uncolored transactions.  This impacts
# which style of 32-bit compatibility library gets installed on the
# system.
# Input: None
# Output: rpmTransactionColor
# Returns: 0=uncolored (i.e. use only arch as install hint)
#          1=Elf32 permitted
#          2=Elf64 permitted
#          3=Elf32 and Elf64 permitted
getRpmTransactionColor()
{
   rpmTransactionColor=$($RPM --showrc | grep _transaction_color | cut --fields=2)
   return $rpmTransactionColor
}

# packageAlreadyInstalled figures out if a package is already installed
# Input: $1: rpmPartBasename
#        $2: rpmArch
# Output: None
# Returns: statusSuccess if the package is already installed
#          statusFail if the is not already installed
packageAlreadyInstalled()
{
   if [ $bUseDpkg -eq $kTrue ]; then
      debPartBasename=$1
      dpkgQueryCommand="$DPKG_QUERY -W -f=\'\${Package}.\${Version}.\${Architecture}\' $debPartBaseName"

      if $dpkgQueryCommand >/dev/null 2>&1; then
         return $statusSuccess
      else
         return $statusFail
      fi
   else
      rpmPartBasename=$1
      rpmPartArch=$2

      if [ "$rpmPartArch" = "noarch" ]; then
         # If the package to be installed is noarch, we allow
         # it to match against any architecture of an already-
         # installed package
         rpmPackageQuery="$rpmPartBasename"
      else
         # Architecture-specific packages are only ever allowed to
         # upgrade same-arch packages, so we're more restrictive
         # in this check
         rpmPackageQuery="$rpmPartBasename.$rpmPartArch"
      fi

      if [ $bUseRpm -eq $kTrue ]; then
         rpmQueryCommand="$RPM -q $rpmPartBasename.$rpmPartArch"
      else
         rpmQueryCommand="$kInstallerBinDir/rpmq -q $rpmPartBasename.$rpmPartArch"
      fi

      if $rpmQueryCommand >/dev/null 2>&1; then
         return $statusSuccess
      else
         return $statusFail
      fi
   fi
}

# packageShouldBeInstalled determines whether or not a package should be
# installed based on the following logic:
#
#   1) If a package is already installed that provides the same functionality
#      under a different name, the package should not be installed because it
#      has been obsoleted
#
#   2) If a package is already installed that provides the same functionality
#      under the same name, and the version of the currently installed package
#      is less than the package pending installation, then the pending
#      package should be installed
#
#   3) Otherwise, there is no currently installed package providing the
#     functionality, so the package should be installed
#
# Input: $1: rpmPartBasename or debPartBasename
# Output: None
# Returns: statusSuccess if the package should be installed
#          statusFail the package should not be installed
packageShouldBeInstalled()
{
   if [ $bUseDpkg -eq $kTrue ]; then
      # CAR 235649: We need to handle obsoletion in the case of a debian
      # distribution
      debPartBasename=$1
      if getDebInfo $debPartBasename > /dev/null 2>&1; then
         strInstalledVersion=$strDebFileVersion
         debPart=`ls $kTmpInstallSrcPath/debian/${debPartBasename}*`
         getDebFileInfo $debPart
         strPendingVersion=$strDebFileVersion
         versionCompare $strPendingVersion $strInstalledVersion >/dev/null 2>&1
         nReturnValue=$?
         if [ $nReturnValue -eq 1 ]; then
            return $statusSuccess
         fi
      else
         return $statusSuccess
      fi
   else
      rpmPartBasename=$1

      if packageHasBeenObsoleted $rpmPartBasename; then
         return $statusFail
      elif getRpmInfo $rpmPartBasename; then
         strInstalledVersion=$strRpmFileVersion
         strInstalledRelease=$strRpmFileRelease

         rpmPart=`ls $kTmpInstallSrcPath/rpms/${rpmPartBasename}*`

         getRpmFileInfo $rpmPart
         strPendingVersion=$strRpmFileVersion
         strPendingRelease=$strRpmFileRelease

         versionCompare $strPendingVersion-$strPendingRelease $strInstalledVersion-$strInstalledRelease >/dev/null 2>&1
         nReturnValue=$?
         if [ $nReturnValue -eq 1 ]; then
            return $statusSuccess
         fi
      else
         return $statusSuccess
      fi
   fi
   return $statusFail
}

# getRpmFileInfo gets the version of a package from the RPM file
# Input: $1: package name to query
#        $RPM: path of RPM executable
# Output: $strRpmFileVersion: version string of package
#         $strRpmFileRelease: release string of the package
# Returns: 0=success, nonzero=failure
getRpmFileInfo ()
{
   getRpmInfo $1 p
   return $?
}

# getArchSpecRpmInfo gets the version of an architecture specific package
# from the RPM database
# Input: $1: package name to query
#        $2: package architecture
#        $RPM: path of RPM executable
# Output: $strRpmFileVersion: version string of package
#         $strRpmFileRelease: release string of the package
# Returns: 0=success, nonzero=failure
getArchSpecRpmInfo ()
{
   getRpmInfo $1.$2
   return $?
}

# getDebFileInfo get version of package from the debian package file
# Input: $1: package name to query
#        $dpkg: path to dpkg binary
# Output: $strDebFileVersion
# Returns: 0=success, non-zero=failure
getDebFileInfo ()
{
   getDebInfo $1 p
   return $?
}

# getRpmInfo gets the version of a package from the RPM database
# Input: $1: package name to query
#        $2: rpm query options, optional (used by getRpmFileInfo)
#        $RPM: path of RPM executable
# Output: $strRpmFileVersion: version string of the package
#         $strRpmFileRelease: release string of the package
# Returns: 0=success, nonzero=failure
getRpmInfo ()
{
   if [ -n "$2" ]; then
      queryFlag="-q$2"
   else
      queryFlag="-q"
   fi

   if [ $bUseRpm -eq $kTrue ]; then
      strRpmFileInfo="`$RPM $queryFlag --queryformat "[%{VERSION}:%{RELEASE}\n]" "$1" 2>/dev/null`"
   else
      strRpmFileInfo="`$kInstallerBinDir/rpmq $queryFlag --queryformat "[%{VERSION}:%{RELEASE}\n]" "$1" 2>/dev/null`"
   fi

   if [ $? -ne 0 ] ; then
      strRpmFileVersion=""
      strRpmFileRelease=""
      return $statusFail
   fi

   strRpmFileVersion="`echo "$strRpmFileInfo" | head -1 | sed -e 's/^\([^:]*\):\([^:]*\)$/\1/'`"
   strRpmFileRelease="`echo "$strRpmFileInfo" | head -1 | sed -e 's/^\([^:]*\):\([^:]*\)$/\2/'`"
   return $statusSuccess
}

getDebInfo ()
{
   if [ $bUseDpkg -eq $kTrue ]; then
      if [ -n "$2" ]; then
         strDebFileInfo="`$DPKG -I "$1" | grep "Version: " | awk '{print $2}'`"
      else
         strDebFileInfo="`$DPKG_QUERY -W -f='${Version}' "$1" `"
         # dpkg query still finds packages after they're uninstalled
         $DPKG_QUERY -s "$1" | grep "Status:" | grep "installed" > /dev/null
      fi
   fi

   if [ $? -ne 0 ] ; then
      strDebFileVersion=""
      return $statusFail
   fi

   strDebFileVersion="$strDebFileInfo"
   #Version contains both version and release
   return $statusSuccess
}

# packageHasBeenObsoleted determines if an already-installed package obsoletes
# the package up for install
# Input: $1: package name to query
#        $RPM: path of RPM executable
# Output: none
# Returns: 0=success, nonzero=failure
packageHasBeenObsoleted ()
{
   local realRPM
   local strPackagesThatObsoleteList=""
   local -a strPackagesThatObsoleteArr

   if [ $bUseRpm -eq $kTrue ]; then
      realRPM=$RPM
   else
      realRPM=$kInstallerBinDir/rpmq
   fi

   # Read all the matching packages into an array.
   # The most common case of having multiple packages match is having the same
   # package in different bitnesses.
   strPackagesThatObsoleteList=`$realRPM -q --whatprovides --queryformat "%{NAME} " "$1" 2>/dev/null`

   # Our query failed, no package providing "$1" installed
   if [ $? -ne 0 ]; then
      return $statusFail
   fi

   # Read the string list into a bash array so we can iterate over it
   IFS=' ' read -a strPackagesThatObsoleteArr <<< $strPackagesThatObsoleteList
   for installedPkg in "${strPackagesThatObsoleteArr[@]}"; do
      # The package that provides $1 has the same name, this is an
      # upgrade/downgrade case, therefore not an obsoletion
      if [ "$installedPkg" = "$1" ]; then
         continue
      fi
      # At this point we know this installed package provides "$1", but
      # doesn't have the same name, lets do a sanity check to make sure it is
      # marking "$1" in its obsoletes
      if ! $realRPM -q --queryformat "[%{OBSOLETES}\n]" "$installedPkg" | grep "$1" >/dev/null 2>&1; then
         echo "Error: Installed package "$installedPkg" provides "$1", but does not mark it as obsolete."
         cleanexit $statusFail
      fi
      # Definitely an obsoletion
      return $statusSuccess
   done
   # We didn't detect the obsoletion case for any of the matching packages
   return $statusFail
}

# pendingPackageSanityCheck performs a sanity check of an package prior to installation
#
# This function will print errors and exit in the case where a pending package fails a check
#
# Input: $1: package name to check
# Output: none
# Returns: 0=success, nonzero=failure
pendingPackageSanityCheck ()
{
   local realRPM

   local package=$1
   local packageBasename=${package%-*-*}
   local packageExtName=${package%.*}
   local packageArchName=${packageExtName##*.}
   local packagePath=$kTmpInstallSrcPath/rpms/$1

   if [ $bUseRpm -eq $kTrue ]; then
      realRPM=$RPM
   else
      realRPM=$kInstallerBinDir/rpmq
   fi

   # Checking to see if there is a newer version of the package already
   # installed on the system of a different bitness.
   # On RHEL 7 and Centos, a higher different bitness will cause the
   # package we are looking at to fail to install properly.

   # If we are already installed we can assume that RPM did the correct
   # action. The script later on will flag this package not installable
   if packageAlreadyInstalled $packageBasename $packageArchName; then
      return $statusSuccess
   fi

   # Check versions form the package onto what is already installed.
   if getRpmFileInfo $packagePath; then
      pendingVersion=$strRpmFileVersion
      pendingRelease=$strRpmFileRelease

      # Checking to see if there is some other version installed.
      for bitness in x86_64 i386
      do
         # Going from x86_64 or i386 to noarch is a valid upgrade case
         # and required for transitional packages
         if [ "$bitness" == "$packageArchName" ] || [ "$packageArchName" == "noarch" ]; then
            continue
         fi
         if getArchSpecRpmInfo $packageBasename $bitness; then
            bitnessVersion=$strRpmFileVersion
            bitnessRelease=$strRpmFileRelease

            # If we find a different architecture and we are on a uncolored system (openSUSE)
            # then fail the install.
            # Two issues will occur if the install is allowed to continue.
            # 1. If the bitness on the system is lower than the one in the installer then
            #    the install will silently upgrade over the other bitness.
            # 2. If the bitness on the system is higher than the one in the installer then
            #    the install will fail because RPM won't be able to install over the higher version.
            getRpmTransactionColor
            if [ $rpmTransactionColor -eq 0 ]; then
               echo "Error: $packageBasename.$bitness ($bitnessVersion-$bitnessRelease) that is installed is incompatible with the pending $packageBasename.$packageArchName ($pendingVersion-$pendingRelease) package."
               cleanexit $statusFail
            fi

            versionCompare $pendingVersion-$pendingRelease $bitnessVersion-$bitnessRelease >/dev/null 2>&1
            nReturnValue=$?

            # If we find a version that is greater but a different architecture, fail the install.
            # RPM will fail anyways, this allows us to send out a more descriptive error.
            if [ $nReturnValue -eq 255 ]; then
               echo "Error: $packageBasename.$bitness ($bitnessVersion-$bitnessRelease) is a higher version than the included $packageBasename.$packageArchName ($pendingVersion-$pendingRelease) in this installer."
               echo "The versions of $packageBasename.$bitness and $packageBasename.$packageArchName should match."
               echo "Please install $packageBasename.$packageArchName ($bitnessVersion-$bitnessRelease) onto the system and re-run this installer."
               cleanexit $statusFail
            fi
         fi
      done
   else
      # This should never happen. If this happens then there is likely something wrong with the package
      # included in the installer distribution.
      echo "Error: Failed to query version information for $package."
      cleanexit $statusFail
   fi

   trimmedProvides="`$realRPM -qp --queryformat "%{PROVIDES}\n" "$packagePath" | grep -v $packageBasename | grep -v ".*\.so.*" | grep -v ".*\.mxe" 2>/dev/null`"

   # Package does not specify any extra provides
   if [ ! -n "$trimmedProvides" ]; then
      return $statusSuccess
   fi

   obsoletedPackages="`$realRPM -qp --queryformat "[%{OBSOLETES}\n]" "$packagePath"`"

   for providedPart in $trimmedProvides
   do
      for obsoletePart in $obsoletedPackages
      do
         if [ "$providedPart" = "$obsoletePart" ]; then
            continue 2
         fi
      done

      echo "Error: package $package is providing '$providedPart', but is not marking it obsolete."
      cleanexit $statusFail
   done

   return $statusSuccess
}

# wasUpgraded checks if the passed package was upgraded during this
#    installation.
# Input: $1: package name to query
#        $upgradePackageList: list of packages that were installed
# Output: none
# Returns: 0=success, nonzero=failure
wasUpgraded ()
{
   queryPackage=$1

   for upgradedPackage in $upgradePackageList
   do
      upgradedPackage=${upgradedPackage##*\/}
      if [ "$upgradedPackage" = "$queryPackage" ]; then
         return $statusSuccess
      fi
   done
   return $statusFail
}

# wasInstalled checks if the passed package was installed/upgraded during this
#    installation.
# Input: $1: package name to query
#        $installPackageList: list of packages that were installed
# Output: none
# Returns: 0=success, nonzero=failure
wasInstalled ()
{
   queryPackage=$1

   for installedPackage in $installPackageList
   do
      installedPackage=${installedPackage##*\/}
      if [ "$installedPackage" = "$queryPackage" ]; then
         return $statusSuccess
      fi
   done
   return $statusFail
}

# isInstallableFSType checks to see if the path passed in is on an fstype that
#    we can install to.  The only fstype that we don't like is vfat since
#    symbolic links don't work there.
# Input: $1: path to check fstype
# Output: None
# Returns: $statusSuccess if it is a supported fstype
#          $statusFail if it is not supported
isInstallableFSType()
{
   directoryPassed=$1
   directoryCalledFrom=`pwd`
   nReturnValue=$statusSuccess

   directoryToCheck=$directoryPassed
   continueLoop=$kYes
   while [ $continueLoop -eq $kYes ]; do
      if [ -e $directoryToCheck ]; then
         continueLoop=$kFalse
         break
      fi

      directoryToCheck=${directoryToCheck%/*}

      if [ "" = "$directoryToCheck" ]; then
         directoryToCheck="/"
         continueLoop=$kFalse
      fi
   done

   cd "$directoryToCheck"
   directoryFSType=`find . -maxdepth 0 -name . -printf %F`
   if [ "vfat" = "$directoryFSType" ]; then
      echo "$directoryPassed located on a vfat filesystem."
      nReturnValue=$statusFail
   fi
   cd "$directoryCalledFrom"

   return $nReturnValue
}

# cleanexit performs script cleanup and quits
# Input: $1: exit code
# Output: None
# Returns: Nothing
cleanexit ()
{
   if [ -z $RM ]; then
      exit $statusFail
   fi
   # Clean up temporary directories
   rm -rf "$kTmpInstallSrcPath"

   # Display an exit message based on exit code
   if [ $1 -ne 0 ]; then
      echo ""
      echo "$eInstallAborted"
   else
      echo ""
      echo "$eInstallComplete"
   fi

   exit $1
}

# cleanwoexit performs script cleanup w/o exiting
# Input: None
# Output: None
# Returns: Nothing
cleanwoexit ()
{
   if [ ! -z "$RM" ]; then
      # Clean up temporary directories
      rm -rf "$kTmpInstallSrcPath"
   fi
}

# freespace determines free disk space in K of a volume
# Input: $1: valid path on the volume to check
# Output: $FREESPACE: free space of volume (in K)
#                   : 0 if failure
# Returns: 0=success. nonzero=failure
freespace ()
{
   FREESPACE=0
   # DF, TAIL, and AWK are needed
   if [ -z "$DF" -o -z "$TAIL" -o -z "$AWK" ]; then
      return $statusFail
   fi
   FREESPACE=`$DF -k $1 | $TAIL -1`
   if [[ "$FREESPACE" = [[:space:]]* ]]; then
      FREESPACE=`echo $FREESPACE | $AWK '{print $3}'`
   else
      FREESPACE=`echo $FREESPACE | $AWK '{print $4}'`
   fi
   return $statusSuccess
}

# getInstallDir prompts the user to select an installation path
# Input: $1: default path
# Output: $installationDir: the path as selected by the user
# Returns: 0=success, nonzero=failure
getInstallDir ()
{
   olddir="`pwd`"
   while :
   do
      echo ""
      dir=$1
      echo -n "[Default $dir, or 'q' to quit] "
      read ans
      if [ ! -z "$ans" ]; then
         dir=$ans
      fi
      echo ""
      case "$dir" in
          /*) ;;
       [qQ]*) exit $statusFail ;;
           *) echo "Directory must begin with /"
              continue ;;
      esac
      if [ -f "$dir" ]; then
         echo "That path already exists as a regular file!"
         echo "A directory path is required."
         continue
      fi
      if [ ! -d "$dir" ]; then
         echo -n "$dir does not exist.  Create? [Yn] "
         read ans
         test -z "$ans" && ans=y
         case "$ans" in
            [yY]*) mkdir -p $dir ;;
            [qQ]*) echo "Aborted."; exit $statusFail ;;
         esac
      else
         cd "$dir"
         if touch foo 2>/dev/null; then
            rm -f foo
            break
         else
            echo ""
            echo "Cannot write to $dir."
         fi
      fi
   done
   installationDir="$dir"
   cd "$olddir"
   echo ""

   return $statusSuccess
}

parseArguments()
{
   promptUser=$kTrue
   licenseAcceptedByUser=$kFalse
   lvSupportInstallSelection=""
   noDepChecking=$kFalse
   noPromptRpmInstall=$kFalse

   while [ "$1" != "" ]; do
      case $1 in
         --no-prompt)
            promptUser=$kFalse
            ;;
         --accept-license)
            licenseAcceptedByUser=$kTrue
            ;;
         --install-labview-support)
            if [ -n "$lvSupportInstallSelection" ]; then
               echo "Only specify install-labview-support or no-install-labview-support, not both." > /dev/stderr
               exit $statusFail
            else
               lvSupportInstallSelection=$kTrue
            fi
            ;;
         --no-install-labview-support)
            if [ -n "$lvSupportInstallSelection" ]; then
               echo "Only specify install-labview-support or no-install-labview-support, not both." > /dev/stderr
               exit $statusFail
            else
               lvSupportInstallSelection=$kFalse
            fi
            ;;
         --nodeps)
            noDepChecking=$kTrue
            ;;
         --no-prompt-rpm)
            #automatically selects RPM when both rpm and dpkg are available
            noPromptRpmInstall=$kTrue
            ;;
         *)
            echo "Unrecognized Option: $1" > /dev/stderr
            exit $statusFail
            ;;
      esac
      shift
   done

   if [ $promptUser -eq $kFalse ] && [ $licenseAcceptedByUser -eq $kFalse ]; then
      echo "If --no-prompt option is used then --accept-license must also be used!"
      exit $statusFail
   fi

   if [ $noDepChecking -eq $kTrue ]; then
      RPMOpts=--nodeps
      echo "*****************************************************************************"
      echo "   Warning: --nodeps is an unsupported option."
      echo "            Installing without dependency checking is dangerous."
      echo "            Only use this option if you know what you are doing."
      echo "*****************************************************************************"
   else
      RPMOpts=""
   fi
}

# Perform cleanup if a Ctrl+C or kill signal is received
trap "cleanexit 1" SIGINT SIGTERM

#
# Display software information
#
echo ""
echo "*****************************************************************************"
echo "  $kProductStringBanner"
echo "     version $kProductVersion for Linux"
echo "*****************************************************************************"
echo ""

currentdir="`pwd`"

#
# Verify root user
#
if [ $EUID -ne 0 ]; then
   echo "This script must be run as root."
   echo "$eInstallAborted"
   # Not a cleanexit call because cleanexit uses $RM, which has
   # not been set yet
   exit $statusFail
fi

originalArguments=$*
parseArguments $*

#
# Display the list of Linux distributions officially supported by National Instruments
#
niDistributionCheck
echo ""

if [ `uname -m` != x86_64 ]; then
echo "This installer does not support 32-bit kernels."
cleanexit $statusFail
fi

if [ "$promptUser" -eq $kTrue ]; then
   inputynq "Continue? [Yn] " 'Y'
   case "$INPUT" in
   [Yy])
      ;;
   [Nn])
      cleanexit $statusFail
      ;;
   esac
   echo ""
fi

# Clean up any stale contents
if [ -d "$kTmpInstallSrcPath" ] ; then
  rm -rf "$kTmpInstallSrcPath"
fi
mkdir -p "$kTmpInstallSrcPath"

#
# Verify tools used during install
#
echo "Checking required install tools..."

RETURN=0

findutil "awk"
let "RETURN+=$?"
AWK=$FINDUTIL

findutil "cat"
let "RETURN+=$?"
CAT=$FINDUTIL

findutil "chown"
let "RETURN+=$?"
CHOWN=$FINDUTIL

findutil "dirname"
let "RETURN+=$?"
DIRNAME=$FINDUTIL

findutil "df"
let "RETURN+=$?"
DF=$FINDUTIL

findutil "du"
let "RETURN+=$?"
DU=$FINDUTIL

findutil "grep"
let "RETURN+=$?"
GREP=$FINDUTIL

findutil "gzip"
let "RETURN+=$?"
GZIP=$FINDUTIL

findutil "head"
let "RETURN+=$?"
HEAD=$FINDUTIL

findutil "install"
let "RETURN+=$?"
INSTALL=$FINDUTIL

findutil "ln"
let "RETURN+=$?"
LN=$FINDUTIL

findutil "ls"
let "RETURN+=$?"
LS=$FINDUTIL

findutil "mkdir"
let "RETURN+=$?"
MKDIR=$FINDUTIL

if [ ! -n "$PAGER" ]; then
   findutil "more"
   let "RETURN+=$?"
   PAGER=$FINDUTIL
fi

findutil "rm"
let "RETURN+=$?"
RM=$FINDUTIL

findutil "rmdir"
let "RETURN+=$?"
RMDIR=$FINDUTIL

findutil "runlevel"
let "RETURN+=$?"
RUNLEVEL=$FINDUTIL

findutil "sed"
let "RETURN+=$?"
SED=$FINDUTIL

findutil "sort"
let "RETURN+=$?"
SORT=$FINDUTIL

findutil "tail"
let "RETURN+=$?"
TAIL=$FINDUTIL

findutil "tar"
let "RETURN+=$?"
TAR=$FINDUTIL

findutil "wc"
let "RETURN+=$?"
WC=$FINDUTIL

findutil "zcat"
let "RETURN+=$?"
ZCAT=$FINDUTIL

# Quit if there was an error
if [ "$RETURN" -ne 0 ]; then
   cleanexit $RETURN
fi

CDPATH="`dirname $0`"
case "$CDPATH" in
    /*) ;;
     .) CDPATH="`pwd`" ;;
     *) CDPATH="`pwd`/$CDPATH" ;;
esac

#
# Verify installation tools
#
echo "Checking installer tool versions..."

# Note: Because RPM keeps reintroducing problems with package relocation, we just
# don't do package relocation with RPM. If a non-default installation path is
# selected, we do a TAR install.
rpmNone=0
rpmRejected=1
rpmLimited=2
RPMTYPE=$rpmNone

installerContentsPackageList=$rpmInstallerContentsPackageList

### Re-evaluate the following code when we decide to start using dpkg
### There is still uncommented functionality in the other files; however,
### since this is the main determiner for dpkg the rest should not be used
# # Locate Dpkg
 findutil "dpkg"
 RETURN=$?
 DPKG=$FINDUTIL
 if [ $RETURN -eq 0 ]; then
    echo "dpkg found"
    bUseDpkg=$kTrue
    installerContentsPackageList=$debInstallerContentsPackageList
    findutil "dpkg-query"
    RETURN=$?
    DPKG_QUERY=$FINDUTIL
 fi

# Locate RPM and determine its version
findutil "rpm"
RETURN=$?
RPM=$FINDUTIL
if [ $RETURN -eq 0 ]; then
   # Try getting the version through an RPM query
   rpmquery "rpm"
   RPMVER=$RPMQUERY
   # Alternatively, try the command line
   if [[ "$RPMVER" != [[:digit:]]* ]]; then
      RPMVER=`$RPM --version | $SED -e 's/.* //'`
   fi
   RPMVERMESSAGE=""

   # Make sure the RPM database is accessible
   if [ -d /var/lib/rpm ]; then
      case "$RPMVER" in
      [0123]\.*)
         RPMTYPE=$rpmRejected
         RPMVERMESSAGE="is less than version 4.0 and will not be used"
         ;;
      [[:digit:]]*)
         RPMTYPE=$rpmLimited
         RPMVERMESSAGE="can be used with a default installation path"
         ;;
      *)
         RPMTYPE=$rpmRejected
         RPMVER="$eVersionUnknown"
         RPMVERMESSAGE="and will not be used"
         ;;
      esac
   else
      RPMTYPE=$rpmRejected
      RPMVERMESSAGE="is not installed correctly and will not be used"
   fi

   echo "rpm        $RPMVER $RPMVERMESSAGE"
else
   RPMTYPE=$rpmNone
fi

# Determine tar version
TARVER=""
# Try getting the version through a query
if [ "$RPMTYPE" -ne $rpmNone ]; then
   if [ $bUseDpkg ]; then
      dpkgquery "tar"
      TARVER=$DPKGQUERY_RESULT
   else
      rpmquery "tar"
      TARVER=$RPMQUERY
   fi
fi
# Alternatively, try the command line
if [[ "$TARVER" != [[:digit:]]* ]]; then
   TARVER=`$TAR --version | $HEAD -1 | $SED -e 's/.* //'`
fi
# Give up on version, but continue installing
if [[ "$TARVER" != [[:digit:]]* ]]; then
   TARVER="$eVersionUnknown"
fi
echo "tar        $TARVER"

#
# Decide what installation method to use
#
if [ "$bUseDpkg" -eq $kTrue -a $($ZCAT "$CDPATH/$kTarPackageName" | $TAR -t | $GREP "debian" | $WC -l) -gt 0 ]; then
   if [ "$RPMTYPE" -ne "$rpmNone" ]; then
      if [ "$noPromptRpmInstall" -eq "$kTrue"  ]; then
         echo ""
         echo "Setting rpm as package manager for this installation"
         INSTALLDEB=$kNo
         INSTALLRPM=$kYes
         bUseDpkg=$kNo
      else
         if [ $promptUser -eq $kTrue ]; then
            inputynq "Both rpm and dpkg are available on this system. Continue using Dpkg? [Yn] " 'Y'
            case "$INPUT" in
               [Yy])
                  INSTALLDEB=$kYes
                  INSTALLRPM=$kNo
               ;;
               [Nn])
                  echo ""
                  echo "Setting rpm as package manager for this installation"
                  INSTALLDEB=$kNo
                  INSTALLRPM=$kYes
                  bUseDpkg=$kNo
               ;;
            esac
            echo ""
         else
            INSTALLDEB=$kYes
            INSTALLRPM=$kNo
         fi
      fi
   else
      INSTALLDEB=$kYes
      INSTALLRPM=$kNo
   fi
else
   INSTALLDEB=$kNo
   if [ "$RPMTYPE" -eq "$rpmNone" -o "$RPMTYPE" -eq "$rpmRejected" ]; then
      INSTALLRPM=$kNo
   else
      INSTALLRPM=$kYes
   fi
fi
#
# Verify required dependencies
#
echo "Checking dependencies..."
RETURN=0
GLIBCVER=""
# Try getting the version through an RPM query
if [ "$RPMTYPE" -eq "$rpmNone" -o "$bUseDpkg" -eq "$kTrue" ]; then
   # Try the command line
   findutil "ldd"
   if [ $? -eq 0 ]; then
      GLIBCVER=`$FINDUTIL --version | $HEAD -1 | $SED -e 's/.* //'`
   fi
else
   rpmquery "glibc"
   if [ $? -eq 0 ]; then
      GLIBCVER=$RPMQUERY
   else
      findutil "ldd"
      if [ $? -eq 0 ]; then
         GLIBCVER=`$FINDUTIL --version | $HEAD -1 | $SED -e 's/.* //'`
         if [ $noDepChecking -eq $kFalse ]; then
            echo "Warning: glibc was not found in the rpm database, but"
            echo "         it appears to be installed on your system."
            echo "         This most likely means you are not using a RPM based"
            echo "         Linux distribution, and need to manually populate your"
            echo "         RPM database, or install with the --nodeps option."
            exit $statusFail
         fi
      fi
   fi
fi

GLIBCVERMESSAGE=""

case "$GLIBCVER" in
[0-1]\.[[:digit:]]*\.[[:digit:]]*)
   GLIBCMESSAGE="is less than 2.2.4 and cannot be used"
   RETURN=1
   ;;
2\.[0-1]\.[[:digit:]]*)
   GLIBCMESSAGE="is less than 2.2.4 and cannot be used"
   RETURN=1
   ;;
2\.2\.[0-3])
   GLIBCMESSAGE="is less than 2.2.4 and cannot be used"
   RETURN=1
   ;;
[[:digit:]]*)
   ;;
*)
   GLIBCVER="$eVersionUnknown"
   GLIBCMESSAGE=""
   RETURN=1
   ;;
esac
echo "glibc      $GLIBCVER $GLIBCMESSAGE"

XVER=""
# Try getting the version through an RPM query
if [ "$RPMTYPE" -ne "$rpmNone" -a "$bUseDpkg" -eq "$kFalse" ]; then
   rpmquery "XFree86"
   XVER=$RPMQUERY
fi

#
# Unpack install files
#
echo "Unpacking install files to $kTmpInstallSrcPath..."

# Clear out and create an empty temporary install directory
$RM -rf $kTmpInstallSrcPath
$MKDIR -p $kTmpInstallSrcPath

# Check for enough free disk space to unpack the files
# Get size of unpacked files in KB
UNPACKSPACE=`$ZCAT "$CDPATH/$kTarPackageName" 2>/dev/null | $WC -c`
let "UNPACKSPACE/=1024"
let "UNPACKSPACE+=1"
# Guess on file system bloat (1/6)
let "UNPACKSPACE+=$UNPACKSPACE/6"
# Determine free disk space in KB on destination volume
freespace "$kTmpInstallSrcPath"
ACTUALSPACE=$FREESPACE
# Quit if there isn't enough free disk space
if [ $ACTUALSPACE -lt $UNPACKSPACE ]; then
   echo "$eNoDiskSpace unpack the files."
   cleanexit $statusFail
fi
# Unpack the files from the TZ package
if [ -f "$CDPATH/$kTarPackageName" ]; then
   $TAR -zxvf "$CDPATH/$kTarPackageName" -C $kTmpInstallSrcPath 1>/dev/null 2>/dev/null
else
   echo "Unable to access $CDPATH/$kTarPackageName."
   cleanexit $statusFail
fi
echo ""
#
# Source the nikal installerUtility for preinstallation checks
#
. $kTmpInstallSrcPath/bin/installerUtility.sh
if ! nikalInstallationCheck; then
   cleanexit $statusFail
fi
#
# Display license agreement before installing
#

if [ "$licenseAcceptedByUser" -eq $kFalse ]; then
   get_file_base $kLicense
   $PAGER "$CDPATH/$kLicense"
fi

echo ""
echo "By installing this software, you are acknowledging acceptance of the terms"
echo "of the included license file ("$kLicense"). "
echo ""

if [ $licenseAcceptedByUser -eq $kFalse ]; then
   if [ "$promptUser" -eq "$kTrue" ]; then
      inputynq "Do you accept the license? [ynq] " ' '
      case "$INPUT" in
      [Yy])
         ;;
      [Nn])
         echo "You must accept the license to install this software."
         cleanexit $statusFail
         ;;
      [Qq])
         cleanexit $statusFail
         ;;
      esac
      echo ""
   fi
fi

#
# Search for existing installation
#

INSTALLDEFPATH="/usr/local"
INSTALLSELPATH=$INSTALLDEFPATH

#
# Get installation directory
#
# Don't actually offer to relocate for the user
GETINSTALLPATH=$kNo
if ! isInstallableFSType $INSTALLSELPATH; then
   cleanexit $statusFail
fi

while [ "$GETINSTALLPATH" -eq "$kYes" ]; do
   echo -n "[Default $INSTALLSELPATH, or q to quit] "
   read TEMPINSTALLSELPATH
   case "$TEMPINSTALLSELPATH" in
   "")
      GETINSTALLPATH=$kNo
      ;;
   [Qq])
      cleanexit $statusFail
      ;;
   *[[:space:]]*)
      echo "Path cannot contain spaces"
      ;;
   */..*)
      echo "Path cannot contain relative (\"/..\") components"
      ;;
   \/*)
      INSTALLSELPATH=$TEMPINSTALLSELPATH
      GETINSTALLPATH=$kNo
      ;;
   *)
      echo "Path must begin with a '/'"
      ;;
   esac
   if [ $GETINSTALLPATH -eq $kNo ]; then
      # Trim trailing '/' characters from path
      INSTALLSELPATH=`echo $INSTALLSELPATH | $SED -e 's/\/*$//'`
      # Verify input
      echo "Files will be installed to $INSTALLSELPATH/natinst"
      inputynq "Is $INSTALLSELPATH/natinst correct? [Ynq] " 'Y'
      case "$INPUT" in
      [Yy])
         ;;
      [Nn])
         GETINSTALLPATH=$kYes
         ;;
      esac
   fi
   if [ $GETINSTALLPATH -eq $kNo ]; then
      if [ -f $INSTALLSELPATH ]; then
         echo "$INSTALLSELPATH is a regular file."
         echo "Please enter another install path."
         GETINSTALLPATH=$kYes
      elif [ -e $INSTALLSELPATH -a ! -w $INSTALLSELPATH ]; then
         echo "$INSTALLSELPATH is not writable."
         echo "Please enter another install path."
         GETINSTALLPATH=$kYes
      elif ! isInstallableFSType $INSTALLSELPATH; then
         echo "Please enter another install path."
         GETINSTALLPATH=$kYes
      elif [ ! -e $INSTALLSELPATH ]; then
         # Create the installation directory
         $MKDIR -p $INSTALLSELPATH
      fi
   fi
done
echo ""

#
# Handle bad RPM for custom install paths
#
# If RPM install was done with a good RPM, then RPM was upgraded to a bad RPM (4.1.x)
if [ "$INSTALLRPM" -eq "$kYes" -a "$RPMTYPE" -eq "$rpmLimited" -a "$INSTALLSELPATH" != "$INSTALLDEFPATH" ]; then
   echo "Due to package relocation problems in many versions of RPM, an RPM install"
   echo "cannot be performed to $INSTALLSELPATH."
   echo "You may select one of the following options:"
   echo "   [Rr] RPM installation to $INSTALLDEFPATH"
   echo "   [Qq] Quit the installation"
   INPUTLOOP=$kYes
   while [ $INPUTLOOP -eq $kYes ]; do
      echo -n "[Rtq] "
      read INPUT
      test -z "$INPUT" && INPUT='R'
      case "$INPUT" in
      [RrTtQq])
         INPUTLOOP=$kNo
         ;;
      *)
         echo -n "$eInvalidSel  "
         ;;
      esac
   done
   case "$INPUT" in
   [Rr])
      INSTALLSELPATH=$INSTALLDEFPATH
      ;;
   [Qq])
      cleanexit $statusFail
      ;;
   esac
   echo ""
fi

installationStatus=$statusSuccess

echo ""
echo ""
echo ""
echo ""
#
# Summarize actions for user
#
echo "$kProductStringSentence version $kProductVersion"
if [ $INSTALLDEB -eq $kTrue ]; then
   echo "is about to be installed using dpkg at $INSTALLSELPATH/natinst"
else
   echo "is about to be installed using rpm at $INSTALLSELPATH/natinst"
fi
echo ""
if [ $promptUser -eq $kTrue ]; then
   inputynq "Would you like to continue? [Yn] " 'Y'
   case "$INPUT" in
   [Yy])
      ;;
   [Nn])
       cleanexit $statusFail
      ;;
   esac
   echo ""
fi

bRebootRequired=$kFalse

initNIDrivers stop
if [ $? -ne 0 ] ; then
   bRebootRequired=$kTrue
fi

echo "Installing $kProductStringSentence version $kProductVersion..."
getNIShareDir
# dynamically generated script installing Debian packages... 
if [ $bUseDpkg -eq $kTrue ]; then
# Define component locations
if [ -e /etc/natinst/nikal/nikal.dir ]; then
   nikalDir=`cat /etc/natinst/nikal/nikal.dir`
fi
if [ -e /etc/natinst/.nicore/nicore.dir ]; then
   nicoreDir=`cat /etc/natinst/.nicore/nicore.dir`
fi
if [ -e /etc/natinst/nibds/nibds.dir ]; then
   nibdsDir=`cat /etc/natinst/nibds/nibds.dir`
fi
if [ -e /etc/natinst/nibds/nibds.dir ]; then
   nibdsDir=`cat /etc/natinst/nibds/nibds.dir`
fi
if [ -e /etc/natinst/nibds/nibds.dir ]; then
   nibdsDir=`cat /etc/natinst/nibds/nibds.dir`
fi
if [ -e /etc/natinst/nifpga/nifpga.dir ]; then
   nifpgaDir=`cat /etc/natinst/nifpga/nifpga.dir`
fi
if [ -e /etc/natinst/nifpga/nifpga.dir ]; then
   nifpgaDir=`cat /etc/natinst/nifpga/nifpga.dir`
fi
if [ -e /etc/natinst/nifpga/nifpga.dir ]; then
   nifpgaDir=`cat /etc/natinst/nifpga/nifpga.dir`
fi
if [ -e /etc/natinst/nifpga/nifpga.dir ]; then
   nifpgaDir=`cat /etc/natinst/nifpga/nifpga.dir`
fi
if [ -e /etc/natinst/nifpga/nifpga.dir ]; then
   nifpgaDir=`cat /etc/natinst/nifpga/nifpga.dir`
fi
if [ -e /etc/natinst/nifpga/nifpga.dir ]; then
   nifpgaDir=`cat /etc/natinst/nifpga/nifpga.dir`
fi
if [ -e /etc/natinst/nip2p/nip2p.dir ]; then
   nip2pDir=`cat /etc/natinst/nip2p/nip2p.dir`
fi
if [ -e /etc/natinst/nip2p/nip2p.dir ]; then
   nip2pDir=`cat /etc/natinst/nip2p/nip2p.dir`
fi
if [ -e /etc/natinst/nip2p/nip2p.dir ]; then
   nip2pDir=`cat /etc/natinst/nip2p/nip2p.dir`
fi
if [ -e /etc/natinst/nip2p/nip2p.dir ]; then
   nip2pDir=`cat /etc/natinst/nip2p/nip2p.dir`
fi
if [ -e /etc/natinst/nip2p/nip2p.dir ]; then
   nip2pDir=`cat /etc/natinst/nip2p/nip2p.dir`
fi
if [ -e /etc/natinst/nirio/nirio.dir ]; then
   nirioDir=`cat /etc/natinst/nirio/nirio.dir`
fi
if [ -e /etc/natinst/nirio/nirio.dir ]; then
   nirioDir=`cat /etc/natinst/nirio/nirio.dir`
fi
if [ -e /etc/natinst/nirio/nirio.dir ]; then
   nirioDir=`cat /etc/natinst/nirio/nirio.dir`
fi
if [ -e /etc/natinst/nirio/nirio.dir ]; then
   nirioDir=`cat /etc/natinst/nirio/nirio.dir`
fi
if [ -e /etc/natinst/share/share.dir ]; then
   shareDir=`cat /etc/natinst/share/share.dir`
fi

installPackageList=""
upgradePackageList=""
tempInstallList=""
for packageName in $installerContentsPackageList
do
   packageBasename=${packageName%_[0-9]*-*}
   packageExtName=${packageName%.*}
   packageArchName=${packageExtName##*.}
   if [ "$packageArchName" = "amd64" ] && [ "`uname -m`" != "x86_64" ]; then
      # Skip all 64-bit parts on non-64-bit systems
      continue
   elif in_array $packageName $dualModeDebsList ; then
      # All dual-mode packages get installed
      :
   elif [ "`uname -m`" = "x86_64" ]; then
      for dupPackageName in $installerContentsPackageList
      do
         if [ "$packageName" = "$dupPackageName" ]; then
            # skip self in list
            continue
         fi
         dupPackageBasename=${dupPackageName%_*-*}
         if [ "$dupPackageBasename" = "$packageBasename" ]; then
            dupPackageExtName=${dupPackageName%.*}
            dupPackageArchName=${dupPackageExtName##*.}
            if [ "$dupPackageArchName" = "amd64" ]; then
               # if available, favor a native package on 64-bit systems over this
               continue 2
            fi
         fi
      done
   fi
   tempInstallList="$tempInstallList $packageName"
done
installerContentsPackageList="$tempInstallList"
for packageName in $installerContentsPackageList
do
   packageBasename=${packageName%_[0-9]*-*}
   if packageShouldBeInstalled $packageBasename; then
      installPackageList="$installPackageList $kTmpInstallSrcPath/debian/$packageName"
      if packageAlreadyInstalled $packageBasename; then
         upgradePackageList="$upgradePackageList $kTmpInstallSrcPath/debian/$packageName"
      fi
   else
      echo "Skipping $packageName installation, same or newer already installed."
   fi
done
instutil="/usr/local/natinst/nikal/bin/ni-kalInstallerUtility.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
for instutil in "$nicoreDir/bin/"ni_apal_errorsInstallerUtility{64,}.sh;
do
   if [ -e "$instutil" ]; then
      source "$instutil"
   fi
done
for instutil in "$nibdsDir/bin/"ni_bdsInstallerUtility{64,}.sh;
do
   if [ -e "$instutil" ]; then
      source "$instutil"
   fi
done
instutil="/usr/local/natinst/nibds/bin/ni_bds_nikalmodInstallerUtility.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nibds/bin/ni_bds_nikalmodInstallerUtility.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nifpga/bin/nifpgaiInstallerUtility64.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nifpga/bin/nifpgaiInstallerUtility.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nifpga/bin/nifpgaiInstallerUtility.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
for instutil in "$nifpgaDir/bin/"nifpgaidsiInstallerUtility{64,}.sh;
do
   if [ -e "$instutil" ]; then
      source "$instutil"
   fi
done
for instutil in "$nifpgaDir/bin/"nifpgaidsiInstallerUtility{64,}.sh;
do
   if [ -e "$instutil" ]; then
      source "$instutil"
   fi
done
for instutil in "$nifpgaDir/bin/"nifpgaidsi_32bitInstallerUtility{64,}.sh;
do
   if [ -e "$instutil" ]; then
      source "$instutil"
   fi
done
instutil="/usr/local/natinst/nip2p/bin/nip2piInstallerUtility64.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nip2p/bin/nip2piInstallerUtility.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nip2p/bin/nip2piInstallerUtility.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nip2p/bin/nip2pkiInstallerUtility64.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nip2p/bin/nip2pkiInstallerUtility.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nirio/bin/nirioiInstallerUtility64.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nirio/bin/nirioiInstallerUtility.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nirio/bin/nirioiInstallerUtility.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nirio/bin/niriokiInstallerUtility64.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/niusrp/bin/niusrpriokiInstallerUtility64.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
for instutil in "$shareDir/bin/"ni_usrp_rio_errorsInstallerUtility{64,}.sh;
do
   if [ -e "$instutil" ]; then
      source "$instutil"
   fi
done
# Call each of the preUninstall functions if that part is being upgraded

echo -n "Pre Installation ."
preUninstall=
if wasUpgraded ni-kal_17.5.1.49152-0+f0_all.deb; then
   if declare -f ni_kalPreUninstall > /dev/null; then
      preUninstall=ni_kalPreUninstall
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall >/tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: ni-kal pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded nikali_17.5.1.49152-0+f0_all.deb; then
   if declare -f nikaliPreUninstall > /dev/null; then
      preUninstall=nikaliPreUninstall
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall >/tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: nikali pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded niusrprioi_18.0.0.49154-f2_amd64.deb; then
   if declare -f niusrprioiPreUninstall64 > /dev/null; then
      preUninstall=niusrprioiPreUninstall64
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall >/tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: niusrprioi pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded ni-apal-errors_17.0.0.49152-0+f0_all.deb; then
   if declare -f ni_apal_errorsPreUninstall > /dev/null; then
      preUninstall=ni_apal_errorsPreUninstall
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall >/tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: ni-apal-errors pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded ni-bds_17.5.0.49152-0+f0_all.deb; then
   if declare -f ni_bdsPreUninstall > /dev/null; then
      preUninstall=ni_bdsPreUninstall
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall >/tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: ni-bds pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded ni-bds-nikalmod_17.5.0.49152-0+f0_amd64.deb; then
   if declare -f ni_bds_nikalmodPreUninstall > /dev/null; then
      preUninstall=ni_bds_nikalmodPreUninstall
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall >/tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: ni-bds-nikalmod pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded ni-bds-nikalmod_17.5.0.49152-0+f0_i386.deb; then
   if declare -f ni_bds_nikalmodPreUninstall > /dev/null; then
      preUninstall=ni_bds_nikalmodPreUninstall
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall >/tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: ni-bds-nikalmod pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded nifpgai_17.0.0-f0_amd64.deb; then
   if declare -f nifpgaiPreUninstall64 > /dev/null; then
      preUninstall=nifpgaiPreUninstall64
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall >/tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: nifpgai pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded nifpgai_17.0.0-f0_i386.deb; then
   if declare -f nifpgaiPreUninstall > /dev/null; then
      preUninstall=nifpgaiPreUninstall
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall >/tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: nifpgai pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded nifpgai-32bit_17.0.0-f0_i386.deb; then
   if declare -f nifpgai_32bitPreUninstall > /dev/null; then
      preUninstall=nifpgai_32bitPreUninstall
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall >/tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: nifpgai-32bit pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded nifpgaidsi_17.0.0-f1_amd64.deb; then
   if declare -f nifpgaidsiPreUninstall > /dev/null; then
      preUninstall=nifpgaidsiPreUninstall
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall >/tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: nifpgaidsi pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded nifpgaidsi_17.0.0-f1_i386.deb; then
   if declare -f nifpgaidsiPreUninstall > /dev/null; then
      preUninstall=nifpgaidsiPreUninstall
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall >/tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: nifpgaidsi pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded nifpgaidsi-32bit_17.0.0-f1_i386.deb; then
   if declare -f nifpgaidsi_32bitPreUninstall > /dev/null; then
      preUninstall=nifpgaidsi_32bitPreUninstall
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall >/tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: nifpgaidsi-32bit pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded nip2pi_17.5.0-f0_amd64.deb; then
   if declare -f nip2piPreUninstall64 > /dev/null; then
      preUninstall=nip2piPreUninstall64
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall >/tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: nip2pi pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded nip2pi_17.5.0-f0_i386.deb; then
   if declare -f nip2piPreUninstall > /dev/null; then
      preUninstall=nip2piPreUninstall
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall >/tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: nip2pi pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded nip2pi-32bit_17.5.0-f0_i386.deb; then
   if declare -f nip2pi_32bitPreUninstall > /dev/null; then
      preUninstall=nip2pi_32bitPreUninstall
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall >/tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: nip2pi-32bit pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded nip2pki_17.5.0-f0_amd64.deb; then
   if declare -f nip2pkiPreUninstall64 > /dev/null; then
      preUninstall=nip2pkiPreUninstall64
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall >/tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: nip2pki pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded nip2pki_17.5.0-f0_i386.deb; then
   if declare -f nip2pkiPreUninstall > /dev/null; then
      preUninstall=nip2pkiPreUninstall
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall >/tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: nip2pki pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded nirioi_17.0.0-f0_amd64.deb; then
   if declare -f nirioiPreUninstall64 > /dev/null; then
      preUninstall=nirioiPreUninstall64
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall >/tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: nirioi pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded nirioi_17.0.0-f0_i386.deb; then
   if declare -f nirioiPreUninstall > /dev/null; then
      preUninstall=nirioiPreUninstall
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall >/tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: nirioi pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded nirioi-32bit_17.0.0-f0_i386.deb; then
   if declare -f nirioi_32bitPreUninstall > /dev/null; then
      preUninstall=nirioi_32bitPreUninstall
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall >/tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: nirioi-32bit pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded nirioki_17.0.0-f0_amd64.deb; then
   if declare -f niriokiPreUninstall64 > /dev/null; then
      preUninstall=niriokiPreUninstall64
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall >/tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: nirioki pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded niusrprioki_18.0.0.49154-f2_amd64.deb; then
   if declare -f niusrpriokiPreUninstall64 > /dev/null; then
      preUninstall=niusrpriokiPreUninstall64
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall >/tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: niusrprioki pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded ni-usrp-rio-rpc_18.0.0.49153-0+f1_amd64.deb; then
   if declare -f ni_usrp_rio_rpcPreUninstall > /dev/null; then
      preUninstall=ni_usrp_rio_rpcPreUninstall
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall >/tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: ni-usrp-rio-rpc pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded ni-usrp-rio-rpc_18.0.0.49153-0+f1_i386.deb; then
   if declare -f ni_usrp_rio_rpcPreUninstall > /dev/null; then
      preUninstall=ni_usrp_rio_rpcPreUninstall
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall >/tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: ni-usrp-rio-rpc pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

echo ""


# Perform the installation with the package list
if [ $INSTALLDEB -eq $kYes ]; then
   if [ -n "$installPackageList" ]; then
      $DPKG -Gi $installPackageList
      if [ $? -ne 0 ]; then
         echo "Error installing $kProductStringSentence $kProductVersion."
         cleanexit $statusFail
      fi
   fi
fi

# create installation log file
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
<dict>
   <key>NIDistributionName</key>
   <string>$kProductName-$kProductVersion</string>
   <key>NIInstallationDate</key>
   <date>2018-06-17T18:47:00Z</date>
   <key>NIDistributionContents</key>
   <array>" > $kInstallationLog

# add parts to the installation log list
for packageName in $installerContentsPackageList
do
   echo -n "      <dict>
         <key>NIPartName</key>
         <string>$packageName</string>
         <key>NIInstallationStatus</key>
         <string>" >> $kInstallationLog

   if wasUpgraded $packageName; then
      echo -n "upgraded" >> $kInstallationLog
   elif wasInstalled $packageName; then
      echo -n "installed" >> $kInstallationLog
   else
      echo -n "skipped" >> $kInstallationLog
   fi

   echo "</string>
      </dict>" >> $kInstallationLog
done

# Post-process driver
# Define component locations for new installation
if [ -e /etc/natinst/nikal/nikal.dir ]; then
   nikalDir=`cat /etc/natinst/nikal/nikal.dir`
fi
if [ -e /etc/natinst/.nicore/nicore.dir ]; then
   nicoreDir=`cat /etc/natinst/.nicore/nicore.dir`
fi
if [ -e /etc/natinst/nibds/nibds.dir ]; then
   nibdsDir=`cat /etc/natinst/nibds/nibds.dir`
fi
if [ -e /etc/natinst/nibds/nibds.dir ]; then
   nibdsDir=`cat /etc/natinst/nibds/nibds.dir`
fi
if [ -e /etc/natinst/nibds/nibds.dir ]; then
   nibdsDir=`cat /etc/natinst/nibds/nibds.dir`
fi
if [ -e /etc/natinst/nifpga/nifpga.dir ]; then
   nifpgaDir=`cat /etc/natinst/nifpga/nifpga.dir`
fi
if [ -e /etc/natinst/nifpga/nifpga.dir ]; then
   nifpgaDir=`cat /etc/natinst/nifpga/nifpga.dir`
fi
if [ -e /etc/natinst/nifpga/nifpga.dir ]; then
   nifpgaDir=`cat /etc/natinst/nifpga/nifpga.dir`
fi
if [ -e /etc/natinst/nifpga/nifpga.dir ]; then
   nifpgaDir=`cat /etc/natinst/nifpga/nifpga.dir`
fi
if [ -e /etc/natinst/nifpga/nifpga.dir ]; then
   nifpgaDir=`cat /etc/natinst/nifpga/nifpga.dir`
fi
if [ -e /etc/natinst/nifpga/nifpga.dir ]; then
   nifpgaDir=`cat /etc/natinst/nifpga/nifpga.dir`
fi
if [ -e /etc/natinst/nip2p/nip2p.dir ]; then
   nip2pDir=`cat /etc/natinst/nip2p/nip2p.dir`
fi
if [ -e /etc/natinst/nip2p/nip2p.dir ]; then
   nip2pDir=`cat /etc/natinst/nip2p/nip2p.dir`
fi
if [ -e /etc/natinst/nip2p/nip2p.dir ]; then
   nip2pDir=`cat /etc/natinst/nip2p/nip2p.dir`
fi
if [ -e /etc/natinst/nip2p/nip2p.dir ]; then
   nip2pDir=`cat /etc/natinst/nip2p/nip2p.dir`
fi
if [ -e /etc/natinst/nip2p/nip2p.dir ]; then
   nip2pDir=`cat /etc/natinst/nip2p/nip2p.dir`
fi
if [ -e /etc/natinst/nirio/nirio.dir ]; then
   nirioDir=`cat /etc/natinst/nirio/nirio.dir`
fi
if [ -e /etc/natinst/nirio/nirio.dir ]; then
   nirioDir=`cat /etc/natinst/nirio/nirio.dir`
fi
if [ -e /etc/natinst/nirio/nirio.dir ]; then
   nirioDir=`cat /etc/natinst/nirio/nirio.dir`
fi
if [ -e /etc/natinst/nirio/nirio.dir ]; then
   nirioDir=`cat /etc/natinst/nirio/nirio.dir`
fi
if [ -e /etc/natinst/share/share.dir ]; then
   shareDir=`cat /etc/natinst/share/share.dir`
fi

# Source each of the installerUtility.sh scripts to get their functions and
# defines
# debpartlist is  ni-kal_17.5.1.49152-0+f0_all.deb nikali_17.5.1.49152-0+f0_all.deb niusrprioi_18.0.0.49154-f2_amd64.deb ni-apal-errors_17.0.0.49152-0+f0_all.deb ni-bds_17.5.0.49152-0+f0_all.deb ni-bds-nikalmod_17.5.0.49152-0+f0_amd64.deb ni-bds-nikalmod_17.5.0.49152-0+f0_i386.deb nifpgai_17.0.0-f0_amd64.deb nifpgai_17.0.0-f0_i386.deb nifpgai-32bit_17.0.0-f0_i386.deb nifpgaidsi_17.0.0-f1_amd64.deb nifpgaidsi_17.0.0-f1_i386.deb nifpgaidsi-32bit_17.0.0-f1_i386.deb nip2pi_17.5.0-f0_amd64.deb nip2pi_17.5.0-f0_i386.deb nip2pi-32bit_17.5.0-f0_i386.deb nip2pki_17.5.0-f0_amd64.deb nip2pki_17.5.0-f0_i386.deb nirioi_17.0.0-f0_amd64.deb nirioi_17.0.0-f0_i386.deb nirioi-32bit_17.0.0-f0_i386.deb nirioki_17.0.0-f0_amd64.deb niusrprioki_18.0.0.49154-f2_amd64.deb ni-usrp-rio-rpc_18.0.0.49153-0+f1_amd64.deb ni-usrp-rio-rpc_18.0.0.49153-0+f1_i386.deb
instutil="/usr/local/natinst/nikal/bin/ni-kalInstallerUtility.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
for instutil in "$nicoreDir/bin/"ni_apal_errorsInstallerUtility{64,}.sh;
do
   if [ -e "$instutil" ]; then
      source "$instutil"
   fi
done
for instutil in "$nibdsDir/bin/"ni_bdsInstallerUtility{64,}.sh;
do
   if [ -e "$instutil" ]; then
      source "$instutil"
   fi
done
instutil="/usr/local/natinst/nibds/bin/ni_bds_nikalmodInstallerUtility.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nibds/bin/ni_bds_nikalmodInstallerUtility.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nifpga/bin/nifpgaiInstallerUtility64.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nifpga/bin/nifpgaiInstallerUtility.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nifpga/bin/nifpgaiInstallerUtility.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
for instutil in "$nifpgaDir/bin/"nifpgaidsiInstallerUtility{64,}.sh;
do
   if [ -e "$instutil" ]; then
      source "$instutil"
   fi
done
for instutil in "$nifpgaDir/bin/"nifpgaidsiInstallerUtility{64,}.sh;
do
   if [ -e "$instutil" ]; then
      source "$instutil"
   fi
done
for instutil in "$nifpgaDir/bin/"nifpgaidsi_32bitInstallerUtility{64,}.sh;
do
   if [ -e "$instutil" ]; then
      source "$instutil"
   fi
done
instutil="/usr/local/natinst/nip2p/bin/nip2piInstallerUtility64.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nip2p/bin/nip2piInstallerUtility.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nip2p/bin/nip2piInstallerUtility.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nip2p/bin/nip2pkiInstallerUtility64.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nip2p/bin/nip2pkiInstallerUtility.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nirio/bin/nirioiInstallerUtility64.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nirio/bin/nirioiInstallerUtility.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nirio/bin/nirioiInstallerUtility.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nirio/bin/niriokiInstallerUtility64.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/niusrp/bin/niusrpriokiInstallerUtility64.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
for instutil in "$shareDir/bin/"ni_usrp_rio_errorsInstallerUtility{64,}.sh;
do
   if [ -e "$instutil" ]; then
      source "$instutil"
   fi
done

# Call each of the postInstall functions

echo -n "Post Installation ."
postInstall=
if wasInstalled ni-kal_17.5.1.49152-0+f0_all.deb; then
   if declare -f ni_kalPostInstall > /dev/null; then
      postInstall=ni_kalPostInstall
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: ni-kal post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled nikali_17.5.1.49152-0+f0_all.deb; then
   if declare -f nikaliPostInstall > /dev/null; then
      postInstall=nikaliPostInstall
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: nikali post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled niusrprioi_18.0.0.49154-f2_amd64.deb; then
   if declare -f niusrprioiPostInstall > /dev/null; then
      postInstall=niusrprioiPostInstall
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: niusrprioi post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled ni-apal-errors_17.0.0.49152-0+f0_all.deb; then
   if declare -f ni_apal_errorsPostInstall > /dev/null; then
      postInstall=ni_apal_errorsPostInstall
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: ni-apal-errors post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled ni-bds_17.5.0.49152-0+f0_all.deb; then
   if declare -f ni_bdsPostInstall > /dev/null; then
      postInstall=ni_bdsPostInstall
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: ni-bds post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled ni-bds-nikalmod_17.5.0.49152-0+f0_amd64.deb; then
   if declare -f ni_bds_nikalmodPostInstall > /dev/null; then
      postInstall=ni_bds_nikalmodPostInstall
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: ni-bds-nikalmod post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled ni-bds-nikalmod_17.5.0.49152-0+f0_i386.deb; then
   if declare -f ni_bds_nikalmodPostInstall > /dev/null; then
      postInstall=ni_bds_nikalmodPostInstall
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: ni-bds-nikalmod post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled nifpgai_17.0.0-f0_amd64.deb; then
   if declare -f nifpgaiPostInstall64 > /dev/null; then
      postInstall=nifpgaiPostInstall64
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: nifpgai post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled nifpgai_17.0.0-f0_i386.deb; then
   if declare -f nifpgaiPostInstall > /dev/null; then
      postInstall=nifpgaiPostInstall
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: nifpgai post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled nifpgai-32bit_17.0.0-f0_i386.deb; then
   if declare -f nifpgai_32bitPostInstall > /dev/null; then
      postInstall=nifpgai_32bitPostInstall
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: nifpgai-32bit post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled nifpgaidsi_17.0.0-f1_amd64.deb; then
   if declare -f nifpgaidsiPostInstall > /dev/null; then
      postInstall=nifpgaidsiPostInstall
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: nifpgaidsi post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled nifpgaidsi_17.0.0-f1_i386.deb; then
   if declare -f nifpgaidsiPostInstall > /dev/null; then
      postInstall=nifpgaidsiPostInstall
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: nifpgaidsi post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled nifpgaidsi-32bit_17.0.0-f1_i386.deb; then
   if declare -f nifpgaidsi_32bitPostInstall > /dev/null; then
      postInstall=nifpgaidsi_32bitPostInstall
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: nifpgaidsi-32bit post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled nip2pi_17.5.0-f0_amd64.deb; then
   if declare -f nip2piPostInstall64 > /dev/null; then
      postInstall=nip2piPostInstall64
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: nip2pi post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled nip2pi_17.5.0-f0_i386.deb; then
   if declare -f nip2piPostInstall > /dev/null; then
      postInstall=nip2piPostInstall
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: nip2pi post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled nip2pi-32bit_17.5.0-f0_i386.deb; then
   if declare -f nip2pi_32bitPostInstall > /dev/null; then
      postInstall=nip2pi_32bitPostInstall
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: nip2pi-32bit post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled nip2pki_17.5.0-f0_amd64.deb; then
   if declare -f nip2pkiPostInstall64 > /dev/null; then
      postInstall=nip2pkiPostInstall64
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: nip2pki post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled nip2pki_17.5.0-f0_i386.deb; then
   if declare -f nip2pkiPostInstall > /dev/null; then
      postInstall=nip2pkiPostInstall
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: nip2pki post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled nirioi_17.0.0-f0_amd64.deb; then
   if declare -f nirioiPostInstall64 > /dev/null; then
      postInstall=nirioiPostInstall64
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: nirioi post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled nirioi_17.0.0-f0_i386.deb; then
   if declare -f nirioiPostInstall > /dev/null; then
      postInstall=nirioiPostInstall
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: nirioi post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled nirioi-32bit_17.0.0-f0_i386.deb; then
   if declare -f nirioi_32bitPostInstall > /dev/null; then
      postInstall=nirioi_32bitPostInstall
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: nirioi-32bit post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled nirioki_17.0.0-f0_amd64.deb; then
   if declare -f niriokiPostInstall64 > /dev/null; then
      postInstall=niriokiPostInstall64
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: nirioki post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled niusrprioki_18.0.0.49154-f2_amd64.deb; then
   if declare -f niusrpriokiPostInstall64 > /dev/null; then
      postInstall=niusrpriokiPostInstall64
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: niusrprioki post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled ni-usrp-rio-rpc_18.0.0.49153-0+f1_amd64.deb; then
   if declare -f ni_usrp_rio_rpcPostInstall > /dev/null; then
      postInstall=ni_usrp_rio_rpcPostInstall
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: ni-usrp-rio-rpc post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled ni-usrp-rio-rpc-18.0.0.49153-0+f1_i386.deb; then
   if declare -f ni_usrp_rio_rpcPostInstall > /dev/null; then
      postInstall=ni_usrp_rio_rpcPostInstall
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: ni-usrp-rio-rpc post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

echo ""

# dynamically generated script installing RPM packages... 
else
# Define component locations
if [ -e /etc/natinst/nikal/nikal.dir ]; then
   nikalDir=`cat /etc/natinst/nikal/nikal.dir`
fi
if [ -e /etc/natinst/.nicore/nicore.dir ]; then
   nicoreDir=`cat /etc/natinst/.nicore/nicore.dir`
fi
if [ -e /etc/natinst/nibds/nibds.dir ]; then
   nibdsDir=`cat /etc/natinst/nibds/nibds.dir`
fi
if [ -e /etc/natinst/nibds/nibds.dir ]; then
   nibdsDir=`cat /etc/natinst/nibds/nibds.dir`
fi
if [ -e /etc/natinst/nibds/nibds.dir ]; then
   nibdsDir=`cat /etc/natinst/nibds/nibds.dir`
fi
if [ -e /etc/natinst/nifpga/nifpga.dir ]; then
   nifpgaDir=`cat /etc/natinst/nifpga/nifpga.dir`
fi
if [ -e /etc/natinst/nifpga/nifpga.dir ]; then
   nifpgaDir=`cat /etc/natinst/nifpga/nifpga.dir`
fi
if [ -e /etc/natinst/nifpga/nifpga.dir ]; then
   nifpgaDir=`cat /etc/natinst/nifpga/nifpga.dir`
fi
if [ -e /etc/natinst/nifpga/nifpga.dir ]; then
   nifpgaDir=`cat /etc/natinst/nifpga/nifpga.dir`
fi
if [ -e /etc/natinst/nifpga/nifpga.dir ]; then
   nifpgaDir=`cat /etc/natinst/nifpga/nifpga.dir`
fi
if [ -e /etc/natinst/nifpga/nifpga.dir ]; then
   nifpgaDir=`cat /etc/natinst/nifpga/nifpga.dir`
fi
if [ -e /etc/natinst/nip2p/nip2p.dir ]; then
   nip2pDir=`cat /etc/natinst/nip2p/nip2p.dir`
fi
if [ -e /etc/natinst/nip2p/nip2p.dir ]; then
   nip2pDir=`cat /etc/natinst/nip2p/nip2p.dir`
fi
if [ -e /etc/natinst/nip2p/nip2p.dir ]; then
   nip2pDir=`cat /etc/natinst/nip2p/nip2p.dir`
fi
if [ -e /etc/natinst/nip2p/nip2p.dir ]; then
   nip2pDir=`cat /etc/natinst/nip2p/nip2p.dir`
fi
if [ -e /etc/natinst/nip2p/nip2p.dir ]; then
   nip2pDir=`cat /etc/natinst/nip2p/nip2p.dir`
fi
if [ -e /etc/natinst/nirio/nirio.dir ]; then
   nirioDir=`cat /etc/natinst/nirio/nirio.dir`
fi
if [ -e /etc/natinst/nirio/nirio.dir ]; then
   nirioDir=`cat /etc/natinst/nirio/nirio.dir`
fi
if [ -e /etc/natinst/nirio/nirio.dir ]; then
   nirioDir=`cat /etc/natinst/nirio/nirio.dir`
fi
if [ -e /etc/natinst/nirio/nirio.dir ]; then
   nirioDir=`cat /etc/natinst/nirio/nirio.dir`
fi
if [ -e /etc/natinst/errors/errors.dir ]; then
   errorsDir=`cat /etc/natinst/errors/errors.dir`
fi

installPackageList=""
upgradePackageList=""
tempInstallList=""
getRpmTransactionColor

for packageName in $installerContentsPackageList
do
   packageBasename=${packageName%-*-*}
   packageExtName=${packageName%.*}
   packageArchName=${packageExtName##*.}
   if [ "$packageArchName" = "x86_64" ] && [ "`uname -m`" != "x86_64" ]; then
      # Skip all 64-bit parts on non-64-bit systems
      continue
   elif in_array $packageName $dualModeRpmsList && [ "`uname -m`" == "x86_64" ]; then
      # If RPM allows installation of i386 packages, don't install x86_64 packages tagged -32bit
      if [ $(($rpmTransactionColor & 1)) -eq 1 ] && [ "$packageArchName" == "x86_64" ] && (echo $packageName | grep -q 32bit); then
         continue
      fi

      # If RPM doesn't allow installation of i386 packages, don't install i386 packages
      if [ ! $(($rpmTransactionColor & 1)) -eq 1 ] && [ "$packageArchName" != "x86_64" -a "$packageArchName" != "noarch" ]; then
         continue
      fi
   elif [ "`uname -m`" = "x86_64" ]; then
      for dupPackageName in $installerContentsPackageList
      do
         if [ "$packageName" = "$dupPackageName" ]; then
            # skip self in list
            continue
         fi
         dupPackageBasename=${dupPackageName%-*-*}
         if [ "$dupPackageBasename" = "$packageBasename" ]; then
            dupPackageExtName=${dupPackageName%.*}
            dupPackageArchName=${dupPackageExtName##*.}
            if [ "$dupPackageArchName" = "x86_64" ]; then
               # if available, favor a native package on 64-bit systems over this
               continue 2
            fi
         fi
      done
   fi
   tempInstallList="$tempInstallList $packageName"
done
installerContentsPackageList="$tempInstallList"
for packageName in $installerContentsPackageList
do
   if in_array $packageName $rpmSkipSanityCheckList; then
      # Skip sanity check on $packageName
      true
   else
      pendingPackageSanityCheck $packageName
   fi
   packageBasename=${packageName%-*-*}
   packageExtName=${packageName%.*}
   packageArchName=${packageExtName##*.}
   if packageShouldBeInstalled $packageBasename; then
      installPackageList="$installPackageList $kTmpInstallSrcPath/rpms/$packageName"
      if packageAlreadyInstalled $packageBasename $packageArchName; then
         upgradePackageList="$upgradePackageList $kTmpInstallSrcPath/rpms/$packageName"
      fi
   else
      echo "Skipping $packageName installation, same or newer already installed."
   fi
done
instutil="/usr/local/natinst/nikal/bin/ni-kalInstallerUtility.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
for instutil in "$nicoreDir/bin/"ni_apal_errorsInstallerUtility{64,}.sh;
do
   if [ -e "$instutil" ]; then
      source "$instutil"
   fi
done
for instutil in "$nibdsDir/bin/"ni_bdsInstallerUtility{64,}.sh;
do
   if [ -e "$instutil" ]; then
      source "$instutil"
   fi
done
instutil="/usr/local/natinst/nibds/bin/ni_bds_nikalmodInstallerUtility.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nifpga/bin/nifpgaiInstallerUtility64.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nifpga/bin/nifpgaiInstallerUtility.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="$nifpgaDir/bin/"nifpgaidsiInstallerUtility.sh
if [ -e "$instutil" ]; then
   source "$instutil"
fi
for instutil in "$nifpgaDir/bin/"nifpgaidsiInstallerUtility{64,}.sh;
do
   if [ -e "$instutil" ]; then
      source "$instutil"
   fi
done
instutil="$nifpgaDir/bin/"nifpgaidsiInstallerUtility.sh
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nip2p/bin/nip2piInstallerUtility.sh"
instutil="/usr/local/natinst/nip2p/bin/nip2piInstallerUtility64.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nip2p/bin/nip2piInstallerUtility.sh"
instutil="/usr/local/natinst/nip2p/bin/nip2pkiInstallerUtility.sh"
instutil="/usr/local/natinst/nip2p/bin/nip2pkiInstallerUtility64.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nirio/bin/nirioiInstallerUtility.sh"
instutil="/usr/local/natinst/nirio/bin/nirioiInstallerUtility64.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nirio/bin/nirioiInstallerUtility.sh"
instutil="/usr/local/natinst/nirio/bin/niriokiInstallerUtility64.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/niusrp/bin/niusrpriokiInstallerUtility64.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
for instutil in "$errorsDir/bin/"ni_usrp_rio_errorsInstallerUtility{64,}.sh;
do
   if [ -e "$instutil" ]; then
      source "$instutil"
   fi
done
# Call each of the preUninstall functions if that part is being upgraded

echo -n "Pre Installation ."
preUninstall=
if wasUpgraded ni-kal-17.5.1.49152-0+f0.noarch.rpm; then
   if declare -f ni_kalPreUninstall > /dev/null; then
      preUninstall=ni_kalPreUninstall
   fi
   if declare -f ni_kalPreUninstall64 > /dev/null; then
      preUninstall=ni_kalPreUninstall64
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall > /tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: ni-kal pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded niusrprioi-18.0.0.49154-f2.x86_64.rpm; then
   if declare -f niusrprioiPreUninstall > /dev/null; then
      preUninstall=niusrprioiPreUninstall
   fi
   if declare -f niusrprioiPreUninstall64 > /dev/null; then
      preUninstall=niusrprioiPreUninstall64
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall > /tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: niusrprioi pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded ni-apal-errors-17.0.0.49152-0+f0.noarch.rpm; then
   if declare -f ni_apal_errorsPreUninstall > /dev/null; then
      preUninstall=ni_apal_errorsPreUninstall
   fi
   if declare -f ni_apal_errorsPreUninstall64 > /dev/null; then
      preUninstall=ni_apal_errorsPreUninstall64
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall > /tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: ni-apal-errors pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded ni-bds-17.5.0.49152-0+f0.noarch.rpm; then
   if declare -f ni_bdsPreUninstall > /dev/null; then
      preUninstall=ni_bdsPreUninstall
   fi
   if declare -f ni_bdsPreUninstall64 > /dev/null; then
      preUninstall=ni_bdsPreUninstall64
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall > /tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: ni-bds pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded ni-bds-nikalmod-17.5.0.49152-0+f0.i386.rpm; then
   if declare -f ni_bds_nikalmodPreUninstall > /dev/null; then
      preUninstall=ni_bds_nikalmodPreUninstall
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall > /tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: ni-bds-nikalmod pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded ni-bds-nikalmod-17.5.0.49152-0+f0.x86_64.rpm; then
   if declare -f ni_bds_nikalmodPreUninstall > /dev/null; then
      preUninstall=ni_bds_nikalmodPreUninstall
   fi
   if declare -f ni_bds_nikalmodPreUninstall64 > /dev/null; then
      preUninstall=ni_bds_nikalmodPreUninstall64
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall > /tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: ni-bds-nikalmod pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded nifpgai-17.0.0-f0.i386.rpm; then
   if declare -f nifpgaiPreUninstall > /dev/null; then
      preUninstall=nifpgaiPreUninstall
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall > /tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: nifpgai pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded nifpgai-17.0.0-f0.x86_64.rpm; then
   if declare -f nifpgaiPreUninstall > /dev/null; then
      preUninstall=nifpgaiPreUninstall
   fi
   if declare -f nifpgaiPreUninstall64 > /dev/null; then
      preUninstall=nifpgaiPreUninstall64
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall > /tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: nifpgai pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded nifpgai-32bit-17.0.0-f0.x86_64.rpm; then
   if declare -f nifpgaiPreUninstall > /dev/null; then
      preUninstall=nifpgaiPreUninstall
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall > /tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: nifpgai pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded nifpgaidsi-17.0.0-f1.i386.rpm; then
   if declare -f nifpgaidsiPreUninstall > /dev/null; then
      preUninstall=nifpgaidsiPreUninstall
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall > /tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: nifpgaidsi pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded nifpgaidsi-17.0.0-f1.x86_64.rpm; then
   if declare -f nifpgaidsiPreUninstall > /dev/null; then
      preUninstall=nifpgaidsiPreUninstall
   fi
   if declare -f nifpgaidsiPreUninstall64 > /dev/null; then
      preUninstall=nifpgaidsiPreUninstall64
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall > /tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: nifpgaidsi pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded nifpgaidsi-32bit-17.0.0-f1.x86_64.rpm; then
   if declare -f nifpgaidsiPreUninstall > /dev/null; then
      preUninstall=nifpgaidsiPreUninstall
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall > /tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: nifpgaidsi pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded nip2pi-17.5.0-f0.i386.rpm; then
   if declare -f nip2piPreUninstall > /dev/null; then
      preUninstall=nip2piPreUninstall
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall > /tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: nip2pi pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded nip2pi-17.5.0-f0.x86_64.rpm; then
   if declare -f nip2piPreUninstall > /dev/null; then
      preUninstall=nip2piPreUninstall
   fi
   if declare -f nip2piPreUninstall64 > /dev/null; then
      preUninstall=nip2piPreUninstall64
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall > /tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: nip2pi pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded nip2pi-32bit-17.5.0-f0.x86_64.rpm; then
   if declare -f nip2piPreUninstall > /dev/null; then
      preUninstall=nip2piPreUninstall
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall > /tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: nip2pi pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded nip2pki-17.5.0-f0.i386.rpm; then
   if declare -f nip2pkiPreUninstall > /dev/null; then
      preUninstall=nip2pkiPreUninstall
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall > /tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: nip2pki pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded nip2pki-17.5.0-f0.x86_64.rpm; then
   if declare -f nip2pkiPreUninstall > /dev/null; then
      preUninstall=nip2pkiPreUninstall
   fi
   if declare -f nip2pkiPreUninstall64 > /dev/null; then
      preUninstall=nip2pkiPreUninstall64
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall > /tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: nip2pki pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded nirioi-17.0.0-f0.i386.rpm; then
   if declare -f nirioiPreUninstall > /dev/null; then
      preUninstall=nirioiPreUninstall
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall > /tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: nirioi pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded nirioi-17.0.0-f0.x86_64.rpm; then
   if declare -f nirioiPreUninstall > /dev/null; then
      preUninstall=nirioiPreUninstall
   fi
   if declare -f nirioiPreUninstall64 > /dev/null; then
      preUninstall=nirioiPreUninstall64
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall > /tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: nirioi pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded nirioi-32bit-17.0.0-f0.x86_64.rpm; then
   if declare -f nirioiPreUninstall > /dev/null; then
      preUninstall=nirioiPreUninstall
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall > /tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: nirioi pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded nirioki-17.0.0-f0.x86_64.rpm; then
   if declare -f niriokiPreUninstall > /dev/null; then
      preUninstall=niriokiPreUninstall
   fi
   if declare -f niriokiPreUninstall64 > /dev/null; then
      preUninstall=niriokiPreUninstall64
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall > /tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: nirioki pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded niusrprioki-18.0.0.49154-f2.x86_64.rpm; then
   if declare -f niusrpriokiPreUninstall > /dev/null; then
      preUninstall=niusrpriokiPreUninstall
   fi
   if declare -f niusrpriokiPreUninstall64 > /dev/null; then
      preUninstall=niusrpriokiPreUninstall64
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall > /tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: niusrprioki pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded ni-usrp-rio-rpc-18.0.0.49153-0+f1.i386.rpm; then
   if declare -f ni_usrp_rio_rpcPreUninstall > /dev/null; then
      preUninstall=ni_usrp_rio_rpcPreUninstall
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall > /tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: ni-usrp-rio-rpc pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

preUninstall=
if wasUpgraded ni-usrp-rio-rpc-18.0.0.49153-0+f1.x86_64.rpm; then
   if declare -f ni_usrp_rio_rpcPreUninstall > /dev/null; then
      preUninstall=ni_usrp_rio_rpcPreUninstall
   fi
   if declare -f ni_usrp_rio_rpcPreUninstall64 > /dev/null; then
      preUninstall=ni_usrp_rio_rpcPreUninstall64
   fi
   if [ "$preUninstall" != "" ]; then
      if ! $preUninstall > /tmp/${preUninstall}.log 2>&1; then
         echo ""
         echo "Warning: ni-usrp-rio-rpc pre uninstallation failed! /tmp/${preUninstall}.log follows:"
         cat /tmp/${preUninstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

echo ""


RPMOpts="$RPMOpts -Uvh"
# Perform the installation with the package list
if [ $INSTALLRPM -eq $kYes ]; then
   if [ -n "$installPackageList" ]; then
      $RPM $RPMOpts $installPackageList
      if [ $? -ne 0 ]; then
         echo "Error installing $kProductStringSentence $kProductVersion."
         cleanexit $statusFail
      fi
   fi
fi

# create installation log file
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
<dict>
   <key>NIDistributionName</key>
   <string>$kProductName-$kProductVersion</string>
   <key>NIInstallationDate</key>
   <date>2018-06-17T18:47:11Z</date>
   <key>NIDistributionContents</key>
   <array>" > $kInstallationLog

# add parts to the installation log list
for packageName in $installerContentsPackageList
do
   echo -n "      <dict>
         <key>NIPartName</key>
         <string>$packageName</string>
         <key>NIInstallationStatus</key>
         <string>" >> $kInstallationLog

   if wasUpgraded $packageName; then
      echo -n "upgraded" >> $kInstallationLog
   elif wasInstalled $packageName; then
      echo -n "installed" >> $kInstallationLog
   else
      echo -n "skipped" >> $kInstallationLog
   fi

   echo "</string>
      </dict>" >> $kInstallationLog
done

# Post-process driver
# Define component locations for new installation
if [ -e /etc/natinst/nikal/nikal.dir ]; then
   nikalDir=`cat /etc/natinst/nikal/nikal.dir`
fi
if [ -e /etc/natinst/.nicore/nicore.dir ]; then
   nicoreDir=`cat /etc/natinst/.nicore/nicore.dir`
fi
if [ -e /etc/natinst/nibds/nibds.dir ]; then
   nibdsDir=`cat /etc/natinst/nibds/nibds.dir`
fi
if [ -e /etc/natinst/nibds/nibds.dir ]; then
   nibdsDir=`cat /etc/natinst/nibds/nibds.dir`
fi
if [ -e /etc/natinst/nibds/nibds.dir ]; then
   nibdsDir=`cat /etc/natinst/nibds/nibds.dir`
fi
if [ -e /etc/natinst/nifpga/nifpga.dir ]; then
   nifpgaDir=`cat /etc/natinst/nifpga/nifpga.dir`
fi
if [ -e /etc/natinst/nifpga/nifpga.dir ]; then
   nifpgaDir=`cat /etc/natinst/nifpga/nifpga.dir`
fi
if [ -e /etc/natinst/nifpga/nifpga.dir ]; then
   nifpgaDir=`cat /etc/natinst/nifpga/nifpga.dir`
fi
if [ -e /etc/natinst/nifpga/nifpga.dir ]; then
   nifpgaDir=`cat /etc/natinst/nifpga/nifpga.dir`
fi
if [ -e /etc/natinst/nifpga/nifpga.dir ]; then
   nifpgaDir=`cat /etc/natinst/nifpga/nifpga.dir`
fi
if [ -e /etc/natinst/nifpga/nifpga.dir ]; then
   nifpgaDir=`cat /etc/natinst/nifpga/nifpga.dir`
fi
if [ -e /etc/natinst/nip2p/nip2p.dir ]; then
   nip2pDir=`cat /etc/natinst/nip2p/nip2p.dir`
fi
if [ -e /etc/natinst/nip2p/nip2p.dir ]; then
   nip2pDir=`cat /etc/natinst/nip2p/nip2p.dir`
fi
if [ -e /etc/natinst/nip2p/nip2p.dir ]; then
   nip2pDir=`cat /etc/natinst/nip2p/nip2p.dir`
fi
if [ -e /etc/natinst/nip2p/nip2p.dir ]; then
   nip2pDir=`cat /etc/natinst/nip2p/nip2p.dir`
fi
if [ -e /etc/natinst/nip2p/nip2p.dir ]; then
   nip2pDir=`cat /etc/natinst/nip2p/nip2p.dir`
fi
if [ -e /etc/natinst/nirio/nirio.dir ]; then
   nirioDir=`cat /etc/natinst/nirio/nirio.dir`
fi
if [ -e /etc/natinst/nirio/nirio.dir ]; then
   nirioDir=`cat /etc/natinst/nirio/nirio.dir`
fi
if [ -e /etc/natinst/nirio/nirio.dir ]; then
   nirioDir=`cat /etc/natinst/nirio/nirio.dir`
fi
if [ -e /etc/natinst/nirio/nirio.dir ]; then
   nirioDir=`cat /etc/natinst/nirio/nirio.dir`
fi
if [ -e /etc/natinst/errors/errors.dir ]; then
   errorsDir=`cat /etc/natinst/errors/errors.dir`
fi

# Source each of the installerUtility.sh scripts to get their functions and
# defines
instutil="/usr/local/natinst/nikal/bin/ni-kalInstallerUtility.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
for instutil in "$nicoreDir/bin/"ni_apal_errorsInstallerUtility{64,}.sh;
do
   if [ -e "$instutil" ]; then
      source "$instutil"
   fi
done
for instutil in "$nibdsDir/bin/"ni_bdsInstallerUtility{64,}.sh;
do
   if [ -e "$instutil" ]; then
      source "$instutil"
   fi
done
instutil="/usr/local/natinst/nibds/bin/ni_bds_nikalmodInstallerUtility.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nibds/bin/ni_bds_nikalmodInstallerUtility.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nifpga/bin/nifpgaiInstallerUtility.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nifpga/bin/nifpgaiInstallerUtility64.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nifpga/bin/nifpgaiInstallerUtility.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
for instutil in "$nifpgaDir/bin/"nifpgaidsiInstallerUtility{64,}.sh;
do
   if [ -e "$instutil" ]; then
      source "$instutil"
   fi
done
for instutil in "$nifpgaDir/bin/"nifpgaidsiInstallerUtility{64,}.sh;
do
   if [ -e "$instutil" ]; then
      source "$instutil"
   fi
done
for instutil in "$nifpgaDir/bin/"nifpgaidsiInstallerUtility{64,}.sh;
do
   if [ -e "$instutil" ]; then
      source "$instutil"
   fi
done
instutil="/usr/local/natinst/nip2p/bin/nip2piInstallerUtility.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nip2p/bin/nip2piInstallerUtility64.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nip2p/bin/nip2piInstallerUtility.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nip2p/bin/nip2pkiInstallerUtility.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nip2p/bin/nip2pkiInstallerUtility64.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nirio/bin/nirioiInstallerUtility.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nirio/bin/nirioiInstallerUtility64.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nirio/bin/nirioiInstallerUtility.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
instutil="/usr/local/natinst/nirio/bin/niriokiInstallerUtility64.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi
for instutil in "$errorsDir/bin/"ni_usrp_rio_errorsInstallerUtility{64,}.sh;
do
   if [ -e "$instutil" ]; then
      source "$instutil"
   fi
done
instutil="/usr/local/natinst/niusrp/bin/niusrpriokiInstallerUtility64.sh"
if [ -e "$instutil" ]; then
   source "$instutil"
fi

# Call each of the postInstall functions

echo -n "Post Installation ."
postInstall=
if wasInstalled ni-kal-17.5.1.49152-0+f0.noarch.rpm; then
   if declare -f ni_kalPostInstall > /dev/null; then
      postInstall=ni_kalPostInstall
   fi
   if declare -f ni_kalPostInstall64 > /dev/null; then
      postInstall=ni_kalPostInstall64
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: ni-kal post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled niusrprioi-18.0.0.49154-f2.x86_64.rpm; then
   if declare -f niusrprioiPostInstall > /dev/null; then
      postInstall=niusrprioiPostInstall
   fi
   if declare -f niusrprioiPostInstall64 > /dev/null; then
      postInstall=niusrprioiPostInstall64
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: niusrprioi post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled ni-apal-errors-17.0.0.49152-0+f0.noarch.rpm; then
   if declare -f ni_apal_errorsPostInstall > /dev/null; then
      postInstall=ni_apal_errorsPostInstall
   fi
   if declare -f ni_apal_errorsPostInstall64 > /dev/null; then
      postInstall=ni_apal_errorsPostInstall64
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: ni-apal-errors post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled ni-bds-17.5.0.49152-0+f0.noarch.rpm; then
   if declare -f ni_bdsPostInstall > /dev/null; then
      postInstall=ni_bdsPostInstall
   fi
   if declare -f ni_bdsPostInstall64 > /dev/null; then
      postInstall=ni_bdsPostInstall64
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: ni-bds post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled ni-bds-nikalmod-17.5.0.49152-0+f0.i386.rpm; then
   if declare -f ni_bds_nikalmodPostInstall > /dev/null; then
      postInstall=ni_bds_nikalmodPostInstall
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: ni-bds-nikalmod post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled ni-bds-nikalmod-17.5.0.49152-0+f0.x86_64.rpm; then
   if declare -f ni_bds_nikalmodPostInstall > /dev/null; then
      postInstall=ni_bds_nikalmodPostInstall
   fi
   if declare -f ni_bds_nikalmodPostInstall64 > /dev/null; then
      postInstall=ni_bds_nikalmodPostInstall64
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: ni-bds-nikalmod post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled nifpgai-17.0.0-f0.i386.rpm; then
   if declare -f nifpgaiPostInstall > /dev/null; then
      postInstall=nifpgaiPostInstall
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: nifpgai post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled nifpgai-17.0.0-f0.x86_64.rpm; then
   if declare -f nifpgaiPostInstall > /dev/null; then
      postInstall=nifpgaiPostInstall
   fi
   if declare -f nifpgaiPostInstall64 > /dev/null; then
      postInstall=nifpgaiPostInstall64
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: nifpgai post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled nifpgai-32bit-17.0.0-f0.x86_64.rpm; then
   if declare -f nifpgaiPostInstall > /dev/null; then
      postInstall=nifpgaiPostInstall
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: nifpgai post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled nifpgaidsi-17.0.0-f1.i386.rpm; then
   if declare -f nifpgaidsiPostInstall > /dev/null; then
      postInstall=nifpgaidsiPostInstall
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: nifpgaidsi post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled nifpgaidsi-17.0.0-f1.x86_64.rpm; then
   if declare -f nifpgaidsiPostInstall > /dev/null; then
      postInstall=nifpgaidsiPostInstall
   fi
   if declare -f nifpgaidsiPostInstall64 > /dev/null; then
      postInstall=nifpgaidsiPostInstall64
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: nifpgaidsi post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled nifpgaidsi-32bit-17.0.0-f1.x86_64.rpm; then
   if declare -f nifpgaidsiPostInstall > /dev/null; then
      postInstall=nifpgaidsiPostInstall
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: nifpgaidsi post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled nip2pi-17.5.0-f0.i386.rpm; then
   if declare -f nip2piPostInstall > /dev/null; then
      postInstall=nip2piPostInstall
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: nip2pi post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled nip2pi-17.5.0-f0.x86_64.rpm; then
   if declare -f nip2piPostInstall > /dev/null; then
      postInstall=nip2piPostInstall
   fi
   if declare -f nip2piPostInstall64 > /dev/null; then
      postInstall=nip2piPostInstall64
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: nip2pi post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled nip2pi-32bit-17.5.0-f0.x86_64.rpm; then
   if declare -f nip2piPostInstall > /dev/null; then
      postInstall=nip2piPostInstall
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: nip2pi post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled nip2pki-17.5.0-f0.i386.rpm; then
   if declare -f nip2pkiPostInstall > /dev/null; then
      postInstall=nip2pkiPostInstall
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: nip2pki post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled nip2pki-17.5.0-f0.x86_64.rpm; then
   if declare -f nip2pkiPostInstall > /dev/null; then
      postInstall=nip2pkiPostInstall
   fi
   if declare -f nip2pkiPostInstall64 > /dev/null; then
      postInstall=nip2pkiPostInstall64
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: nip2pki post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled nirioi-17.0.0-f0.i386.rpm; then
   if declare -f nirioiPostInstall > /dev/null; then
      postInstall=nirioiPostInstall
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: nirioi post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled nirioi-17.0.0-f0.x86_64.rpm; then
   if declare -f nirioiPostInstall > /dev/null; then
      postInstall=nirioiPostInstall
   fi
   if declare -f nirioiPostInstall64 > /dev/null; then
      postInstall=nirioiPostInstall64
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: nirioi post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled nirioi-32bit-17.0.0-f0.x86_64.rpm; then
   if declare -f nirioiPostInstall > /dev/null; then
      postInstall=nirioiPostInstall
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: nirioi post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled nirioki-17.0.0-f0.x86_64.rpm; then
   if declare -f niriokiPostInstall > /dev/null; then
      postInstall=niriokiPostInstall
   fi
   if declare -f niriokiPostInstall64 > /dev/null; then
      postInstall=niriokiPostInstall64
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: nirioki post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled niusrprioki-18.0.0.49154-f2.x86_64.rpm; then
   if declare -f niusrpriokiPostInstall > /dev/null; then
      postInstall=niusrpriokiPostInstall
   fi
   if declare -f niusrpriokiPostInstall64 > /dev/null; then
      postInstall=niusrpriokiPostInstall64
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: niusrprioki post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled ni-usrp-rio-rpc-18.0.0.49153-0+f1.i386.rpm; then
   if declare -f ni_usrp_rio_rpcPostInstall > /dev/null; then
      postInstall=ni_usrp_rio_rpcPostInstall
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: ni-usrp-rio-rpc post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

postInstall=
if wasInstalled ni-usrp-rio-rpc-18.0.0.49153-0+f1.x86_64.rpm; then
   if declare -f ni_usrp_rio_rpcPostInstall > /dev/null; then
      postInstall=ni_usrp_rio_rpcPostInstall
   fi
   if declare -f ni_usrp_rio_rpcPostInstall64 > /dev/null; then
      postInstall=ni_usrp_rio_rpcPostInstall64
   fi
   if [ "$postInstall" != "" ]; then
      if ! $postInstall > /tmp/${postInstall}.log 2>&1; then
         echo ""
         echo "Warning: ni-usrp-rio-rpc post installation failed! /tmp/${postInstall}.log follows:"
         cat /tmp/${postInstall}.log
         installationStatus=$statusFail
      fi
   fi
fi
echo -n "."

echo ""

fi
# LVSupport installation
# End of LVSupport installation
# close out the installation log file
echo "   </array>
</dict>
</plist>" >> $kInstallationLog

if [ -e /usr/local/lib/LabVIEW-8.0/liblvrtdark.so.8.0 ]; then
   ln -sf LabVIEW-8.0/liblvrtdark.so.8.0 /usr/local/lib/liblvrtdark.so.8.0
   ln -sf liblvrtdark.so.8.0 /usr/local/lib/liblvrtdark.so
   /sbin/ldconfig
fi
if [ -x /usr/local/bin/updateNIDrivers ]; then
  echo "Updating modversions database to include newly installed drivers..."
  if ! /usr/local/bin/updateNIDrivers --no-prompt 2>&1 ; then
    installationStatus=$statusFail
  fi
fi
distStatus=$statusSuccess
failedDists=
if [ -d $kTmpInstallSrcPath/dists ]; then
   for childDist in `ls $kTmpInstallSrcPath/dists`;
   do
      childDistVersion=`$GREP '^kProductVersion=' $kTmpInstallSrcPath/dists/$childDist/INSTALL | $SED 's/kProductVersion="\(.*\)"$/\1/'`
      childDistString=`$GREP '^kProductStringSentence=' $kTmpInstallSrcPath/dists/$childDist/INSTALL | $SED 's/kProductStringSentence="\(.*\)"$/\1/'`

      installChild=$kTrue

      if [ $promptUser -eq $kTrue ]; then
         echo ""
         echo -n "Would you like to install $childDistString ($childDistVersion)? [Yn] "
         read ans
         test -z "$ans" && ans=y

         case "$ans" in
              [nN]*) echo "$childDistString will not be installed."
                     installChild=$kFalse
                     ;;
              [yY]*)
                     installChild=$kTrue
                     ;;
         esac
      else
         echo ""
         echo "Installing $childDistString ($childDistVersion)"
      fi

      if [ $installChild -eq $kTrue ]; then

         # Transfer arguments to child distribution
         (
            cd "$kTmpInstallSrcPath/dists/$childDist"
            /bin/sh ./INSTALL $originalArguments
            exit $?
         )
         if [ $? -ne $statusSuccess ]; then
            distStatus=$statusFail
            failedDists="$failedDists $childDistString"
         fi

         echo ""
      fi

   done
fi

if [ $installationStatus -eq $statusSuccess ]
then
  DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  cp ${DIR}/UNINSTALL /usr/local/bin/niusrprio_uninstall
  sed -i 's/echo "$eInstallComplete"/echo "$eInstallComplete"; rm $0/g' /usr/local/bin/niusrprio_uninstall
  #TODO: Remove this when deb postinst issues are resolved in RIO
  mkdir -p /var/local/natinst/nirio/etc
  chmod 0777 /var/local/natinst/nirio/etc
fi

if [ $bRebootRequired -ne $kTrue ]; then
  reloadNIDrivers
  if [ $? -ne 0 ] ; then
    bRebootRequired=$kTrue
  fi
fi

if [ $installationStatus -eq $statusSuccess ]
then
    echo "Starting USRP-RIO PCIe daemon/service..."
    DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
    cp ${DIR}/niusrprio_pcie /usr/local/bin
    if ! niusrprio_pcie start /tmp/niusrprio_pcie.log 2>&1; then
        echo "Warning: niusrprio_pcie installation failed! /tmp/niusrprio_pcie.log follows:"
        cat /tmp/niusrprio_pcie.log
        installationStatus=$statusFail
    fi
fi

#
# Finish installation
#
echo ""
echo "FOR PATENTS COVERING NATIONAL INSTRUMENTS PRODUCTS, REFER TO"
echo "THE $kPatents FILE ON $CDPATH AND/OR"
echo "www.ni.com/patents"

if [ $bRebootRequired -eq $kTrue ]; then
   echo ""
   echo "******************************************************************************"
   echo "* A reboot is required before attempting to use the"
   echo "* $kProductStringSentence software."
   echo "******************************************************************************"
   if [ $promptUser -eq $kTrue ]; then
      while :
      do
         echo -n "Would you like to reboot now? [yes|no] "
         read rebootConfirm 
         if [ "$rebootConfirm" != "yes" ] && [ "$rebootConfirm" != "no" ]; then
            echo "Please input yes or no."
         else
            break
         fi
      done
      if [ "$rebootConfirm" = "yes" ]; then
         cleanwoexit
         echo ""
         if [ $installationStatus -eq $statusSuccess ]; then
            echo "$kProductStringSentence Installation completed successfully."
         else
            echo "$kProductStringSentence Installation completed with errors."
         fi
         if [ $distStatus -ne $statusSuccess ]; then
            echo "WARNING: The following related products failed to install: $failedDists"
         fi
         echo ""
         echo "Rebooting...."
         reboot
         exit $installationStatus
      fi
   fi
   echo ""
   if [ $installationStatus -eq $statusSuccess ]; then
      echo "$kProductStringSentence Installation completed successfully."
   else
      echo "$kProductStringSentence Installation completed with errors."
   fi
   if [ $distStatus -ne $statusSuccess ]; then
      echo "WARNING: The following related products failed to install: $failedDists"
   fi
   echo ""
   cleanwoexit
   echo "Please reboot manually before attempting to use "
   echo "$kProductStringSentence software."
   echo ""
else
   echo ""
   if [ $installationStatus -eq $statusSuccess ]; then
      echo "$kProductStringSentence Installation completed successfully."
   else
      echo "$kProductStringSentence Installation completed with errors."
   fi
   if [ $distStatus -ne $statusSuccess ]; then
      echo "WARNING: The following related products failed to install: $failedDists"
   fi
   echo ""
   cleanwoexit
fi

exit $installationStatus

