#!/bin/sh

# This script updates etc/commondirs, the list of directories in CSWcommon
# from the package. It is a superugly hack for time-to-time updates.

# The current workflow is
# - update the package CSWcommon
# - call this script
# - commit etc/commondirs, so cswproto removes the right directories
# The workflow in the future may look like this:
# - Update etc/commondirs
# - Build CSWcommon package with GAR


update() {
  ARCH=$1

  TMPDIR=/tmp/update-commondir.$$
  mkdir $TMPDIR
  (
    cd $TMPDIR
    wget http://mirror.opencsw.org/opencsw/unstable/$1/5.10/common-1.5,REV=2010.12.11-SunOS5.8-$1-CSW.pkg
    cat common-* | pkgtrans /dev/fd/0 $TMPDIR all
  )

  ( perl -ne '
my @l = split;
if( $l[1] =~ /^[ds]$/ ) {
  print ($l[3] =~ /([^=]*)/);
  print "\n";
}
  ' $TMPDIR/CSWcommon/pkgmap
    echo "/var"; echo "/var/run"
    echo "/usr"; echo "/usr/sadm"; echo "/usr/sadm/install"; echo "/usr/sadm/install/scripts"
  ) > ../etc/commondirs-$1

  rm -rf $TMPDIR
}

update sparc
update i386

