Friday, October 14, 2005

[UNIX] Solaris 10 Package Lists

#! /bin/sh
#
# create package lists from cluster table of content
# for solaris 10
#
# see Solaris 10 package list
# http://docs.sun.com/app/docs/doc/817-0545/6mgbberia?a=view
#


TOC=/var/sadm/system/admin/.clustertoc
if [ ! -f $TOC ]; then
 echo "CLuster toc cannot be found at $TOC\n"
 exit 1
fi



TMPFILE=.tmp_$$


awk '
BEGIN {
 dist[1]="SUNWCrnet";  # reduced networking
 dist[2]="SUNWCreq";  # core
 dist[3]="SUNWCuser";  # end user
 dist[4]="SUNWCprog";  # developer
 dist[5]="SUNWCall";  # entire distribution
 dist[6]="SUNWCXall";  # entire distribution (plus OEM)
 comma=","
}
{
 split($0,var,"=")
 if ( var[1] ~ /CLUSTER$/  ) { 
  cluster=var[2]
  p2c[cluster]=""
 }

 # setup child and parent relationship
 if ( var[1] == "SUNW_CSRMEMBER" ) {
  child=var[2]

  # avoid duplicate
  if ( c2p[child] == cluster ) {
   next
  }

  c2p[child]=cluster
  if ( p2c[cluster] == "" ) {
   p2c[cluster]=child
  } else {
   p2c[cluster]=sprintf("%s%s%s",p2c[cluster],comma,child)
  }
 }
}
END {
 for ( i=1 ; i<=5 ; ++i ) {

  aCluster=dist[i]
  split(p2c[aCluster],svar1,comma)
  for ( j in svar1 ) {
   aChild=svar1[j]

   # if child is cluster, go one level down
   if ( aChild ~ /^SUNWC/ ) {
    split(p2c[aChild],svar2,comma)
    for ( k in svar2 ) {
     aGrandChild=svar2[k]
     printf("%s:%s:%s\n",aCluster,aChild,aGrandChild)
    }
   } else {
    printf("%s:%s\n",aCluster,aChild)
   }
  }
 }
}' $TOC > $TMPFILE


#
# each cluster distribution file will contain all the package names
#
for c in SUNWCrnet SUNWCreq SUNWCuser SUNWCprog SUNWCall SUNWCXall
do
 egrep "^$c" $TMPFILE | awk -F: '{print $NF}' | sort > $c
done
rm -r $TMPFILE



tree() 
{
 # big is the superset cluster
 # small is the immediate subset of the 'big'
 big=$1
 small=$2
 level=$3

 # work out the indentation
 level=`expr $level - 1`
 while [ $level -gt 0 ]; do
  echo "  \c"
  level=`expr $level - 1`
 done

 # create 'pkginfo' database for output reference
 # diff between superset cluster and subset cluster
 echo "[$big]"
 (echo "DB_START" ; pkginfo ; echo "DB_END" ; diff $big $small | egrep "^< ") | nawk -v level=$3 '
  /DB_START/,/DB_END/ {
          if ( NF >= 3 ) {
                  pkg=$2
                  desc=$3
                  for(i=4;i<=NF;++i) {
                          desc=sprintf("%s %s",desc,$i)
                  }
                  db[pkg]=desc
   }
   next
         }
  {
   # indentation for level
   ident=""
   for ( i=0;i< level;++i ) { 
    ident="  "ident
   }

   # ensure description having same indentation
   nspace=25-length($2)-length(ident)
   space=""
   for ( i=1;i<=nspace;++i ) { 
    space=" "space
   }
   printf("%s%s%s/* %s */\n",ident,$2,space,db[$2])
  }'
}

depend="Dependency"
tree SUNWCXall SUNWCall  1 >  $depend
tree SUNWCall  SUNWCprog 2 >> $depend
tree SUNWCprog SUNWCuser 3 >> $depend
tree SUNWCuser SUNWCreq  4 >> $depend
tree SUNWCreq  SUNWCrnet  5 >> $depend
tree SUNWCrnet   /dev/null 6 >> $depend

0 Comments:

Post a Comment

<< Home