Dave asked me to post a copy of the Solaris Package Companion.  Some basic 
information on the tool and the script itself is included below (the script 
would not attach for some reason).  I have since started down a different patch 
and have developed a different tool (still in the works) that will provide a 
faster and more comprehensive response that the Companion, but it will (as a 
tradeoff) take more disk space.  I will post that one as well once it is done.

Glenn

---

The Solaris Package Companion (or spc.sh) is a small shell script that will:

   * display a list of packages for a specified metacluster
   * display a list of packages for a specified cluster
   * display a list of dependencies for a specified package
   * display the metaclusters in which a package can be found
   * display the cluster in which a package can be found (if any)

So far, I have tested this script with Nevada (SPARC) and it appears to do a 
decent job.  It certainly helps to speed up the process.  That said, there are 
a few known issues:

   * only immediate package dependencies are determined
     [this should be fixed in a later version]

   * package descriptions are not shown for those packages that
     are architecture specific, e.g. SUNWcakr -> SUNWcakr.u

   * only tested on Nevada SPARC (so far)

   * not all error handling is in (yet)

To use "spc.sh", you will need to specify a directory location of a Solaris OS 
distribution.  For my testing, I had been using:

/export/install/images/nv/combined.nvs_wos/latest/Solaris_11/Product

This parameter can be specified using the "-s" option or by editing the code to 
change the BASEDIR
global variable (BASEDIR was set for the examples below).  This script will 
create a processed version of the .clustertoc in your current directory.  This 
will be used to more quickly parse content and get results.  If you want to do 
package dependency checks or get descriptions, the script goes back out to the 
source (-s option) to get that information -- so it will take a little longer.

Some examples...

This example shows that SUNWzoner is not in the Reduced Networking or Core 
metaclusters:

blackhole$ $HOME/spc.sh -s -p SUNWzoner
SUNWCXall
SUNWCall
SUNWCprog
SUNWCuser

This example shows that SUNWzoner is a part of the SUNWCzone cluster (which is 
useful when building JumpStart profiles - specifying the cluster and not the 
individual packages):

blackhole$ $HOME/spc.sh -P SUNWzoner
SUNWCzone

This example shows that the SUNWCzone cluster includes both SUNWzoner and 
SUNWzoneu:

blackhole$ ./spc.sh -c SUNWCzone
SUNWzoner
SUNWzoneu

This example shows the listing of declared dependencies for the SUNWzoner and 
SUNWzoneu packages:

blackhole$ $HOME/spc.sh -d -v SUNWzoner SUNWzoneu
SUNWcakr
SUNWcar
SUNWckr                  Core Solaris Kernel (Root)
SUNWcnetr                Core Solaris Network Infrastructure (Root)
SUNWcsd                  Core Solaris Devices
SUNWcsl                  Core Solaris, (Shared Libs)
SUNWcsr                  Core Solaris, (Root)
SUNWcsu                  Core Solaris, (Usr)
SUNWkvm
SUNWluu                  Live Upgrade (usr)
SUNWluzone               Live Upgrade (zones support)
SUNWlxml                 The XML library
SUNWpool                 Resource Pools
SUNWtecla                Tecla command-line editing library
SUNWzfsu                 ZFS (Usr)
SUNWzoner                Solaris Zones (Root)

--- spc.sh BEGIN

#! /usr/bin/sh
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#

#
# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.

#
# Solaris Package Companion
#
# The goal of this script is to troll around the Solaris OS distribution
# to collection package, cluster, and metacluster information that is
# otherwise not available.  This script can be used to determine declared
# package dependencies, mappings between packages and clusters and meta-
# clusters, and related functions that are often useful when building
# reduced or minimal OS configurations.
#
# Feedback and enhancements are very much requested and can be sent to:
# glenn<.>brunette<@>sun<.>com
#

##############################################################################
# HOUSEKEEPING
##############################################################################

umask 022

PATH=/usr/bin:/usr/sbin
export PATH

##############################################################################
# GLOBAL VARIABLES
##############################################################################

# This parameter governs whether this program will display package
# descriptions along with their names (on = 1, off = 0).

SHOW_DESC=0

# This parameter governs whether this program will calculate and
# process package dependencies (on = 1, off = 0).

SHOW_DEPEND=0

# For those who do not want to have to specify the '-s' option with every
# invokation of this command, just uncomment BASEDIR and set its value
# accordingly.

# BASEDIR="/export/install/images/nv/combined.nvs_wos/latest/Solaris_11/Product"

##############################################################################
# Function: processClusterTOC
##############################################################################

processClusterTOC()
{
   if [ ! -f ${P_CTOC} ]; then

      touch ${P_CTOC}

      exec 3<&0
      exec < ${R_CTOC}

      inCluster=0
      mCluster=0
      pkgList=""

      while read line; do

         if [ ${inCluster} -eq 0 ]; then
            token=`echo ${line} | awk -F= '$1 == "CLUSTER" { print $2 }'`
            if [ ! -z "${token}" ]; then
               clusterName="${token}"
               inCluster=1
            else
               token=`echo ${line} | awk -F= '$1 == "METACLUSTER" { print $2 }'`
               if [ ! -z "${token}" ]; then
                  clusterName="${token}"
                  inCluster=1
                  mCluster=1
               fi
            fi
         elif [ "${line}" = "END" ]; then
            if [ ${mCluster} -eq 0 ]; then
               echo "CLUSTER: ${clusterName} ${pkgList}" >> ${P_CTOC}
            else
               echo "METACLUSTER: ${clusterName} ${pkgList}" >> ${P_CTOC}
            fi
            clusterName=""
            pkgList=""
            token=""
            inCluster=0
            mCluster=0
         else
            member=`echo ${line} | awk -F= '$1 == "SUNW_CSRMEMBER" { print $2 
}'`
            if [ ! -z "${member}" ]; then
               pkgList="${pkgList} ${member}"
            fi
         fi
      done

      exec 0<&3
      exec 3<&-
   fi
}

##############################################################################
# Function: getPackageDependencyList
##############################################################################

getPackageDependencyList()
{
   dependList=""

   for pkg in $*; do
      dependFile="${BASEDIR}/${pkg}/install/depend"
      export dependFile
      if [ -f ${dependFile} ]; then
         dependPkg=`grep "^P" ${dependFile} | awk '{ print $2 }'`
         dependList="${dependList} ${dependPkg}"
      fi
   done
   echo ${dependList}
}

##############################################################################
# Function: getPackagesDetails
##############################################################################

getPackageDetails()
{
   for pkg in $*; do
      printf "%-25s%s\n" "${pkg}" \
         "`pkgparam -d ${BASEDIR} ${pkg} NAME 2>/dev/null`"
   done
}

##############################################################################
# Function: getPackages
##############################################################################

getPackages()
{
   dList=""
   if [ ${SHOW_DEPEND} -eq 1 ]; then
      dList="`getPackageDependencyList $*`"
   fi

   echo $* ${dList}
}

##############################################################################
# Function: displayPackages
##############################################################################

displayPackages()
{
   masterList="`echo $* | xargs -n 1 echo | sort -u`"
   if [ ${SHOW_DESC} -eq 1 ]; then
      getPackageDetails ${masterList}
   else
      echo "${masterList}"
   fi
}

##############################################################################
# Function: getPackagesByCluster
##############################################################################

getPackagesByCluster()
{
   fullList=""
   export fullList

   for cName in $*; do
      line=""
      line=`grep "^CLUSTER: ${cName} " ${P_CTOC}`
      if [ -z "${line}" ]; then
         eval echo `gettext 'The specified cluster ${cName} was not found.'`
      else
         tmpList=`echo ${line} | cut -d" " -f3-`
         fullList="${fullList} ${tmpList}"
      fi
   done
   [ ! -z "${fullList}" ] && displayPackages `getPackages ${fullList}`
}

##############################################################################
# Function: getPackageDependencies
##############################################################################

getPackageDependencies()
{
   masterList="`getPackageDependencyList $*`"
   displayPackages ${masterList}
}

##############################################################################
# Function: getPackagesByMetaCluster
##############################################################################

getPackagesByMetaCluster()
{
   line=""
   line=`grep "^METACLUSTER: ${1} " ${P_CTOC}`
   if [ -z "${line}" ]; then
      eval echo `gettext 'The specified metacluster ${1} was not found.'`
   else
      mcPkgList=""
      for item in `echo ${line} | cut -d" " -f3-`; do
         if [ `echo ${item} | grep -c "^SUNWC"` -eq 1 ]; then
            mcPkgList="${mcPkgList} `getPackagesByCluster ${item}`"
         else
            mcPkgList="${mcPkgList} `getPackages ${item}`"
         fi
      done
      displayPackages ${mcPkgList}
   fi
}

##############################################################################
# Function: getClusterByPackage
##############################################################################

getClusterByPackage()
{
   grep "^CLUSTER: " ${P_CTOC} | grep "${1}" | nawk '{ print $2 }' | sort -u
}

##############################################################################
# Function: getMetaClustersByPackage
##############################################################################

getMetaClustersByPackage()
{
   if [ -z "${1}" ]; then
      gettext "getMetaClusterByPackage: No package name specified."
      exit
   fi

   cluster=""
   cluster="`getClusterByPackage $1`"

   if [ ! -z "${cluster}" ]; then
      # eval echo `gettext 'Package $1 is a member of cluster ${cluster}.'`
      keyList="${cluster}"
   else
      # eval echo `gettext 'Package $1 is not a member of a cluster.'`
      keyList="${1}"
   fi

   for key in ${keyList}; do
      grep "^METACLUSTER: " ${P_CTOC} | grep "${key}" |\
      nawk '{ print $2 }' | sort -u
   done | sort -u
}

##############################################################################
# Function: displayHelp
##############################################################################

helpMessage="
Solaris Package Companion

To specify which Solaris OS distribution to use.  This path should
be defined to the location of the Solaris OS 'Product' directory.
This option must be specified for all of the modes listed below:

   -s <pathToSolarisProductDirectory>

To display a list of packages for a specified cluster:

   -c <packageClusterList>

   -D [to include dependent packages]
   -v [to print package descriptions]

To display a list of dependencies for a specified package:

   -d <packageList>

   -v [to print package descriptions]

To display a list of packages for a specified metacluster:

   -m <metaClusterName>

   -D [to include dependent packages]
   -v [to print package descriptions]

To display the metaclusters in which a package can be found:

   -p <packageName>

To display the cluster in which a package can be found (if any):

   -P <packageName>

"

displayHelp()
{
   gettext "${helpMessage}"
   exit
}

##############################################################################
# MAIN ROUTINE
##############################################################################

MODE=""

while getopts cdDhmpPs:v\? v; do
   case ${v} in

      c) [ -z "${MODE}" ] && MODE="getPackagesByCluster" ;;
      d) [ -z "${MODE}" ] && MODE="getPackageDependencies" ;;
      D) SHOW_DEPEND=1 ;;
      h) displayHelp ;;
      m) [ -z "${MODE}" ] && MODE="getPackagesByMetaCluster" ;;
      p) [ -z "${MODE}" ] && MODE="getMetaClustersByPackage" ;;
      P) [ -z "${MODE}" ] && MODE="getClusterByPackage" ;;
      s) BASEDIR="${OPTARG}" ;;
      v) SHOW_DESC=1 ;;
      ?) displayHelp ;;
      *) displayHelp ;;
   esac
done

shift `expr $OPTIND - 1`

if [ -z "${BASEDIR}" ]; then
   gettext "Error: No Solaris OS distribution directory defined (-s).\n"
   exit
fi

if [ ! -d ${BASEDIR} ]; then
   gettext "Error: Could not find the Solaris OS distribution directory.\n"
   exit
fi

R_CTOC="${BASEDIR}/.clustertoc"
P_CTOC="$HOME/clustertoc.processed"
export BASEDIR R_CTOC P_CTOC

if [ ! -f ${R_CTOC} ]; then
   gettext "Error: Could not find the Solaris OS .clustertoc file.\n"
   exit
fi

if [ ! -z "${MODE}" ]; then
   if [ "${SHOW_DESC}" = "1" -o "${SHOW_DEPEND}" = "1" ]; then
      if [ "${MODE}" = "getMetaClustersByPackage" -o \
         "${MODE}" = "getClusterByPackage" ]; then
         gettext "Error: Invalid combination of command line options.\n"
         displayHelp
      fi
   fi

   if [ $# -ge 1 ]; then
      processClusterTOC
      ${MODE} $*
   else
      gettext "Error: A list of items to process was not found.\n"
      displayHelp
   fi
else
   gettext "Error: A processing mode was not selected.\n"
   displayHelp
fi

exit 0

--- spc.sh END
 
 
This message posted from opensolaris.org

Reply via email to