summaryrefslogtreecommitdiff
path: root/pkgtools/cdpack/files
diff options
context:
space:
mode:
authordmcmahill <dmcmahill>2001-04-27 18:16:41 +0000
committerdmcmahill <dmcmahill>2001-04-27 18:16:41 +0000
commitd2556002f41844a98d0c903c638b4bd1215c5c14 (patch)
tree44b569fb94b433380ff8d5026e3f4a8849e2f796 /pkgtools/cdpack/files
parent6b5fdc2f2ea48faf8fd5e3fae9146186dfb3a2b0 (diff)
downloadpkgsrc-d2556002f41844a98d0c903c638b4bd1215c5c14.tar.gz
initial import of cdpack-1.0
cdpack is a small utility for creating ISO 9660 images for a multi-CD binary package collection. The utility creates ISO 9660 images for all the binary packages in a specified directory. A choice of two algorithms is available for how the packages are grouped. The "no duplication" algorithm arranges the packages so any package on CD number `n' will have all of its dependencies on CD numbers 1 through `n'. The "no inter-CD depends" algorithm will place certain packages on more than one CD to ensure that each CD is self contained (all package dependencies are satisfied within the single CD).
Diffstat (limited to 'pkgtools/cdpack/files')
-rwxr-xr-xpkgtools/cdpack/files/cdgen.awk426
-rw-r--r--pkgtools/cdpack/files/cdpack.1129
-rwxr-xr-xpkgtools/cdpack/files/cdpack.sh384
3 files changed, 939 insertions, 0 deletions
diff --git a/pkgtools/cdpack/files/cdgen.awk b/pkgtools/cdpack/files/cdgen.awk
new file mode 100755
index 00000000000..9c460e80b10
--- /dev/null
+++ b/pkgtools/cdpack/files/cdgen.awk
@@ -0,0 +1,426 @@
+#!/usr/bin/awk -f
+# $NetBSD: cdgen.awk,v 1.1.1.1 2001/04/27 18:16:42 dmcmahill Exp $
+#
+# Copyright (c) 2001 Dan McMahill, All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. All advertising materials mentioning features or use of this software
+# must display the following acknowledgement:
+# This product includes software developed by Dan McMahill
+# 4. The name of the author may not be used to endorse or promote
+# products derived from this software without specific prior written
+# permission.
+#
+# THIS SOFTWARE IS PROVIDED BY DAN MCMAHILL
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+BEGIN {
+
+# ARGV[0] = program name
+# ARGV[1] = packages directory (/usr/pkgsrc/packages/All)
+# ARGV[2] = output directory
+# ARGV[3] = Depends tree file. Has packages in tsort(1) input format.
+# ARGV[4] = Depends order file. Has packages in tsort(1) output format.
+# ARGV[5] = CD list. This script leaves a list of the CD directories in this file
+# ARGV[6] = dup flag. "dup=yes" for package duplication, "dup=no" for no duplication.
+# ARGV[7] = verbose flag. "verbose=yes" for verbose output
+# ARGV[8] = xtra_size. How many kB are needed per CD for common files
+
+ if (ARGC != 9){
+ printf("%s: wrong number of arguments\n",ARGV[0]);
+ usage();
+ exit(1);
+ }
+
+ prog = "cdgen.awk";
+ packages = ARGV[1];
+ cddir = ARGV[2];
+ deptree = ARGV[3];
+ order = ARGV[4];
+ cdlist = ARGV[5];
+ xtra_size= ARGV[8];
+
+ if (ARGV[6] ~ "dup=yes"){
+ dup=1;
+ }
+ else{
+ dup=0;
+ }
+ if (ARGV[7] ~ "verbose=yes"){
+ verbose=1;
+ }
+ else{
+ verbose=0;
+ }
+
+#
+# Make sure all required directories and files exist
+#
+ cmd="test -d " packages ;
+ if(system(cmd) != 0){
+ printf("%s: packages directory \"%s\" does not exist\n",prog,packages);
+ usage();
+ exit(1);
+ }
+
+ cmd="test -d " cddir ;
+ if(system(cmd) != 0){
+ printf("%s: cd image directory \"%s\" does not exist\n",prog,cddir);
+ usage();
+ exit(1);
+ }
+
+ cmd="test -f " deptree ;
+ if(system(cmd) != 0){
+ printf("%s: dependstree file \"%s\" does not exist\n",prog,deptree);
+ usage();
+ exit(1);
+ }
+
+ cmd="test -f " order ;
+ if(system(cmd) != 0){
+ printf("%s: build order file \"%s\" does not exist\n",prog,order);
+ usage();
+ exit(1);
+ }
+
+
+ now = strftime("%a %b %d %H:%M:%S %Z %Y");
+ printf("%s starting %28s\n",prog,now);
+
+#
+# Read in the build order. This gives the list of all possible
+# packages (note that some may actually not be available as binary
+# packages). The order is such that a package earlier in the list
+# will never depend on a package lower on the list.
+#
+
+ printf("Reading the depends order from \"%s\".\n",order);
+ n=1;
+ while(getline < order > 0){
+ pkgorder[n] = $1;
+ n++;
+ }
+ close(order);
+ npkgs = n-1;
+ printf("%d packages to go on CD-ROM!\n",npkgs);
+
+
+#
+# Read in the depends tree and flatten it.
+#
+ printf("Reading depends tree\n");
+ while(getline < deptree > 0){
+ if ($2 in topdepends)
+ topdepends[$2] = topdepends[$2] " " $1 " " ;
+ else
+ topdepends[$2] = " " $1 " " ;
+ }
+ close(deptree);
+
+# Now recurse the tree to give a flattened depends list for each pkg
+ printf("Flattening depends tree\n");
+ for (toppkg in topdepends){
+ find_all_depends(toppkg);
+ }
+
+
+#
+# Next get the sizes of each of the binary pacakges if they
+# exist. For those which don't exist, make a note of that.
+# getsize() returns size in kB if the file exists, 0 otherwise.
+#
+ printf("Loading binary package sizes\n");
+ nonzero=0;
+ totsize=0;
+ for (n in pkgorder){
+ pkgsize[pkgorder[n]] = getsize(pkgorder[n]);
+ if(pkgsize[pkgorder[n]] > 0){
+ nonzero++;
+ }
+ else{
+ printf("WARNING: binary package \"%s\" has zero size\n",pkgorder[n]);
+ }
+ totsize = totsize + pkgsize[pkgorder[n]];
+ }
+ printf("%d binary packages are available (%g Mb)!\n",nonzero,totsize/1024);
+
+#
+# Now we need to figure out which binary packages go on each
+# CD. The way we'll do this is start taking packages in the order
+# specified by 'pkgorder' until the first CD is full, then move
+# to the second, etc. This way, we never have to reinsert a CD
+# while installing pkgs.
+#
+ printf("Figuring out which packages go on each CD\n");
+
+# maximum kB for binary pkgs per CD.
+ maxcd=1024*620;
+
+#
+# no package duplication
+#
+ if (!dup){
+ cdn=1;
+ pkgn=0;
+ cdtot[cdn]=xtra_size;
+ cdpkgs[cdn]=0;
+
+ for (n=1; n<=npkgs ; n=n+1){
+# only process the package if it exists.
+ if (pkgsize[pkgorder[n]] > 0){
+ if (cdtot[cdn] < (maxcd-pkgsize[pkgorder[n]]) ){
+ cdtot[cdn] = cdtot[cdn] +pkgsize[pkgorder[n]];
+ cdcontents[cdn":"pkgorder[n]] = 1;
+ pkgn = pkgn + 1;
+ }
+ else{
+# the CD is full
+ printf("cd number %d is full (%g Mb)\n",cdn,
+ cdtot[cdn]/1024);
+ cdpkgs[cdn] = pkgn;
+# increment the CD counter
+ cdn = cdn + 1;
+ pkgn = 1;
+ cdtot[cdn] = xtra_size + pkgsize[pkgorder[n]];
+ cdcontents[cdn":"pkgorder[n]] = 1;
+ }
+ }
+ }
+ cdpkgs[cdn] = pkgn;
+ printf("cd number %d is partially full (%g Mb)\n",cdn,
+ cdtot[cdn]/1024);
+ }
+
+#
+# We will duplicate some packages to eliminate inter-CD dependencies.
+#
+ else{
+ cdn=1;
+ pkgn=0;
+ cdtot[cdn]=xtra_size;
+ cdpkgs[cdn]=0;
+ n=npkgs;
+ while (n > 0){
+ if ( !pkg_done[pkgorder[n]]){
+ size_needed = pkgsize[pkgorder[n]];
+ deps_needed = 0;
+ split(alldepends[pkgorder[n]],pkgdeps);
+ for (dep in pkgdeps){
+ if(!cdcontents[cdn":"pkgdeps[dep]]){
+ size_needed = size_needed + pkgsize[pkgdeps[dep]];
+ deps_needed++;
+ }
+ }
+ if (cdtot[cdn] + size_needed < maxcd){
+ cdcontents[cdn":"pkgorder[n]] = 1;
+ pkg_done[pkgorder[n]] = 1;
+ for (dep in pkgdeps){
+ cdcontents[cdn":"pkgdeps[dep]] = 1;
+ pkg_done[pkgdeps[dep]] = 1;
+ }
+ cdtot[cdn] = cdtot[cdn] + size_needed;
+ n--;
+ pkgn = pkgn + 1 + deps_needed;
+ }
+ else{
+# the CD is full
+ printf("cd number %d is full (%g Mb)\n",cdn,
+ cdtot[cdn]/1024);
+ cdpkgs[cdn] = pkgn;
+ cdn++;
+ cdtot[cdn] = xtra_size;
+ pkgn = 0;
+ }
+ }
+ else{
+# we've already done this pkg
+ n--;
+ }
+
+ }
+ cdpkgs[cdn] = pkgn;
+ printf("cd number %d is partially full (%g Mb)\n",cdn,
+ cdtot[cdn]/1024);
+ }
+
+# remember how many cd's there are
+ ncd=cdn;
+
+# print some stats
+ if (dup){
+ tot_cdpkgs=0;
+ for (cdn=1; cdn<=ncd; cdn=cdn+1){
+ tot_cdpkgs = tot_cdpkgs + cdpkgs[cdn];
+ }
+ printf("CD images with package duplication resulted in %d packages total\n",tot_cdpkgs);
+ printf("This is an increase of %d over the base %d packages\n",tot_cdpkgs-npkgs,npkgs);
+ }
+
+#
+# Next, create a subdirectory for each CD and populate the directory
+# with links to the actual binary pkgs
+#
+ printf("Creating subdirectories for each CD and populating it with links\n");
+ printf("to the binary packages and other required files.\n");
+ for (cdn=1; cdn<=ncd; cdn=cdn+1){
+ printf("----------- CD #%d ----------\n",cdn);
+ printf(" %3d binary packages\n",cdpkgs[cdn]);
+ outdir=cddir "/cd" cdn "/packages/All";
+ cmd="test -d " outdir;
+ if(system(cmd) == 0){
+ printf("%10s: output dir \"%s\" already exists.\n",prog,outdir);
+ printf("%10s please remove it.\n","");
+ exit(1);
+ }
+
+# create output directory
+ cmd = "mkdir -p " outdir;
+ do_system(cmd);
+
+# populate it with the symlinks to the binary packages
+ for (n=1; n<=npkgs; n++){
+ if (cdcontents[cdn":"pkgorder[n]]){
+ cmd = "cd " outdir " && ln -s " packages "/" ;
+ cmd = cmd pkgorder[n] ".tgz";
+ do_system(cmd);
+ }
+ }
+
+# add it to the cd list
+ printf("cd%d\n",cdn) > cdlist ;
+
+ }
+
+ close(cdlist);
+
+ now = strftime("%a %b %d %H:%M:%S %Z %Y");
+ printf("%s finished on %28s\n",prog,now);
+
+ printf("\n");
+
+ exit 0
+ }
+
+function getsize(name,cmd,sz){
+
+ cmd="test -f " packages "/" name ".tgz";
+ if(system(cmd) == 0){
+ cmd="du -k " packages "/" name ".tgz";
+ cmd | getline ;
+ close(cmd);
+ sz=$1;
+ }
+ else{
+ sz=0;
+ }
+
+ return(sz);
+}
+
+function do_system(cmd,rv){
+ rv = system(cmd);
+ if (rv != 0){
+ printf("Error: system(\"%s\") returned %d\n",cmd,rv);
+ exit(1);
+ }
+ return(0);
+}
+
+#
+# show usage
+#
+function usage(){
+ printf("\nUsage:\n\n");
+ printf("%10s -- Create directories for building binary package ISO images\n",
+ prog,prog);
+ printf("%10s packages images dependstree order cdlist\n","");
+ printf("\n");
+ printf("\n");
+
+}
+
+
+function find_all_depends(pkg,pkgreg,i,deps){
+# if we find the package already has been fully depended
+# then return the depends list
+ if (pkg in alldepends){
+# printf("\t%s is already depended.\n",pkg);
+ return(alldepends[pkg]);
+ }
+
+# if we find the package listed in its own depends list, then
+# return an empty list if we're going down the depends tree.
+# When a package lists itself in the depends tree file, it simply
+# is a place holder and means the package has no depends. However
+# other packages may still depend upon it, so we need to keep looking.
+ if ( topdepends[pkg]~reg2str(pkg) ){
+# printf("\t%s depends on its self.\n",pkg);
+ alldepends[pkg] = " ";
+ return(alldepends[pkg]);
+ }
+
+# otherwise recursively gather depends that each of the depends
+# has
+ pkgreg=reg2str(pkg);
+ split(topdepends[pkg],deps);
+ i=1;
+ alldepends[pkg] = " ";
+ while ( i in deps ){
+# don't add ourselves to the list (a possibility when going up the tree)
+ if (" "deps[i]" "!~pkgreg){
+ alldepends[pkg] = alldepends[pkg] " " deps[i] " " find_all_depends(deps[i]);
+ }
+ i=i+1;
+ }
+ alldepends[pkg] = uniq(alldepends[pkg]);
+ return(alldepends[pkg]);
+}
+
+#
+# take a string which has special characters like '+' in it and
+# escape them. Also put a space before and after since that's how
+# we'll distinguish things like gnome from gnome-libs
+#
+function reg2str(reg){
+ gsub(/\+/,"\\\+",reg);
+ gsub(/\./,"\\\.",reg);
+ reg = " "reg" ";
+ return(reg);
+}
+
+#
+# take the depends lists and uniq them.
+#
+function uniq(list,deps,i,ulist){
+
+# split out the depends
+ split(list,deps);
+
+ i=1;
+ ulist = " ";
+ while (i in deps){
+ if (ulist !~reg2str(deps[i])){
+ ulist = ulist deps[i]" ";
+ }
+ i++;
+ }
+ return(ulist);
+}
diff --git a/pkgtools/cdpack/files/cdpack.1 b/pkgtools/cdpack/files/cdpack.1
new file mode 100644
index 00000000000..3c504c0ac05
--- /dev/null
+++ b/pkgtools/cdpack/files/cdpack.1
@@ -0,0 +1,129 @@
+.\" $NetBSD: cdpack.1,v 1.1.1.1 2001/04/27 18:16:42 dmcmahill Exp $
+.\"
+.\" Copyright (c) 2001 Dan McMahill, All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by Dan McMahill
+.\" 4. The name of the author may not be used to endorse or promote
+.\" products derived from this software without specific prior written
+.\" permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY DAN MCMAHILL
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd April 25, 2001
+.Dt CDPACK 1
+.Os NetBSD
+.Sh NAME
+.Nm cdpack
+.Nd produce multi-CD binary package images
+.Sh SYNOPSIS
+.Nm ""
+.Op -nvV
+.Op -x extra_directory
+.Ar packages_directory
+.Ar cd_image_directory
+.Sh DESCRIPTION
+The
+.Nm
+utility produces ISO 9660 image files for
+a multiple CD-ROM collection of binary packages.
+.Pp
+The
+.Nm
+utility extracts the dependency information from the binary
+packages in the directory
+.Ar packages_directory
+specified on the command line. The dependency information is
+used to determine which packages are placed on which CD. The
+directory
+.Ar cd_image_directory
+is used as a staging area and the final ISO 9660 images are left in
+that directory. A file,
+.Ar README.txt
+, will be left in the root of each CD image along with an index
+file
+.Ar .index
+which lists the contents of each CD.
+.Bl -tag -width "-x directory "
+.It Fl n
+Do not duplicate packages in order to prevent inter-CD dependencies.
+The default without the
+.Fl n
+option will place a package and all of its dependencies on the same
+CD. If a particular package is also required by pacakges on other
+CD's, it will be placed there as well.
+When the
+.Fl n
+option is used packages are not duplicated. This results in slightly
+smaller ISO 9660 images.
+.Nm
+places packages which are lower in the dependency tree on lower
+numbered CD-ROM's and packages which are higher on the higher numbered
+CD-ROM's. In this fashion, a package on CD number n
+will have all of its dependencies on CD numbers 1 through n
+.It Fl v
+Be verbose. Currently does not change things much.
+.It Fl V
+Print the program version number and exit.
+.It Fl x Ar directory
+Includes the contents of
+.Ar directory
+on each CD.
+.El
+.Pp
+The
+.Nm
+utility exits 0 on success, and >0 if an error occurs.
+.Sh EXAMPLES
+This example takes all of the binary packages found in
+/usr/pkgsrc/packages/All and creates cd images in
+/u2/cdimages/cd{1,2,...}.iso. The directories
+/u2/cdimages/cd{1,2,...} are used to create the ISO 9660 layouts.
+.D1 cdpack /usr/pkgsrc/packages/All /u2/cdimages
+.Pp
+To include a common set of files on all CD's, place them in a
+directory, /tmp/foo, in this example, and pass in the directory name
+with the
+.Fl x
+option.
+.Dl cdpack -x /tmp/foo /usr/pkgsrc/packages/All /u2/cdimages
+.Sh ENVIRONMENT
+.Nm
+uses the fillowing environment variables if set.
+.Bl -tag -width "TMPDIR"
+.It Ev TMPDIR
+Directory for holding temporary files during the image creation.
+Defaults to
+.Dq Li /tmp .
+.El
+.Sh SEE ALSO
+.Xr mkisofs 1
+.Sh HISTORY
+The
+.Nm
+utility first appeared in the
+.Nx
+packages collection in April, 2001.
+.Sh AUTHOR
+The
+.Nm
+utility was written by Dan McMahill (dmcmahill@netbsd.org).
diff --git a/pkgtools/cdpack/files/cdpack.sh b/pkgtools/cdpack/files/cdpack.sh
new file mode 100755
index 00000000000..1ff5c7abf66
--- /dev/null
+++ b/pkgtools/cdpack/files/cdpack.sh
@@ -0,0 +1,384 @@
+#!/bin/sh
+# $NetBSD: cdpack.sh,v 1.1.1.1 2001/04/27 18:16:42 dmcmahill Exp $
+#
+# Copyright (c) 2001 Dan McMahill, All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. All advertising materials mentioning features or use of this software
+# must display the following acknowledgement:
+# This product includes software developed by Dan McMahill
+# 4. The name of the author may not be used to endorse or promote
+# products derived from this software without specific prior written
+# permission.
+#
+# THIS SOFTWARE IS PROVIDED BY DAN MCMAHILL
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+# $0 = program name
+# $2 = packages directory (/usr/pkgsrc/packages/All)
+# $3 = output directory
+
+prog=cdpack
+progver=@progver@
+
+TMPDIR=${TMPDIR:-/tmp}
+TMP=${TMPDIR}/${prog}.$$
+
+depf=$TMP/depf
+depf2=$TMP/depf2
+deptree=$TMP/deptree
+order=$TMP/order
+cdlist=$TMP/cdlist
+indexf=$TMP/indexf
+readme=$TMP/readme
+warnings=$TMP/warnings
+
+rm -fr $TMP
+mkdir $TMP
+
+usage(){
+ echo "$prog - generates ISO9660 images for a multi-cd binary package collection"
+ echo "Usage: $prog packages_directory cdimage_directory"
+ echo "Example: $prog /usr/pkgsrc/packages/netbsd-1.5/alpha/All /images/netbsd-1.5/alpha"
+}
+
+clean_and_exit(){
+ rm -fr $TMP
+ exit 1
+}
+
+DUP=yes
+VERBOSE=no
+VERSION=no
+USE_XTRA=no
+
+while
+ test -n "$1"
+do
+ case "$1"
+ in
+ # do not duplicate packages to avoid inter-CD dependencies
+ -n) DUP=no
+ shift
+ ;;
+
+ # be verbose
+ -v) VERBOSE=yes
+ shift
+ ;;
+
+ # display version
+ -V) VERSION=yes
+ shift
+ ;;
+
+ # extra directory to go on each CD.
+ -x) extra=$2
+ USE_XTRA=yes
+ shift 2
+ ;;
+
+ -*) echo "$prog: ERROR: $s is not a valid option"
+ usage
+ clean_and_exit
+ ;;
+
+ *) ARGS="$ARGS $1"
+ shift
+ ;;
+ esac
+done
+
+if [ $VERSION = "yes" ]; then
+ echo "$prog-$progver"
+ rm -fr $TMP
+ exit 0
+fi
+
+set -- $ARGS
+
+if [ $# -ne 2 ]; then
+ echo "$prog: wrong number of arguments"
+ usage
+ clean_and_exit
+fi
+
+packages=$1
+cddir=$2
+
+if [ $VERBOSE = "yes" ]; then
+ echo "Verbose output is on"
+fi
+
+#
+# Make sure all required directories and files exist
+#
+
+if [ ! -d $packages ]; then
+ echo "$prog: packages directory \"$packages\" does not exist"
+ usage
+ clean_and_exit
+fi
+
+if [ ! -d $cddir ]; then
+ echo "$prog: cd image directory \"$cddir\" does not exist"
+ usage
+ clean_and_exit
+fi
+
+if [ "$USE_XTRA" = "yes" -a ! -d $extra ]; then
+ echo "$prog: extra directory \"$extra\" specified with -x does not exist"
+ usage
+ clean_and_exit
+fi
+
+if [ "$USE_XTRA" = "yes" ]; then
+ case $extra in
+ /*) # do nothing, its an absolute path
+ ;;
+ *) extra=`pwd`/$extra
+ ;;
+ esac
+ XTRA_SIZE=`du -sk $extra | awk '{print $1}'`
+ if [ "$VERBOSE" = "yes" ]; then
+ echo "Extra directory full path name is \"$extra\". It contains $XTRA_SIZE kB."
+ fi
+else
+ XTRA_SIZE=0
+fi
+
+echo " "
+echo "$prog starting: `date`"
+echo " "
+
+#
+# go through all the binary packages and extract their run depends and
+# also any package conflicts.
+#
+# $deptree = this file contains a tsort(1) run depends tree using
+# binary package names.
+#
+
+npkgs=0
+echo "Extracting all dependency information for the binary packages..."
+for pkg in $packages/*
+do
+ if [ -f $pkg ]; then
+ # extract the packge name
+ pkgname=`basename $pkg .tgz`
+
+ # extract the packing list
+ cat $pkg | (cd $TMP; tar --fast-read -xzf - +CONTENTS)
+
+ # extract the depends
+ deps=`awk '/^@pkgdep/ {printf("%s ",$2)}' $TMP/+CONTENTS`
+
+ # extract any conflicts
+ cfls=`awk '/^@pkgcfl/ {printf("%s ",$2)}' $TMP/+CONTENTS`
+
+ rm $TMP/+CONTENTS
+
+ # store the results
+ echo "$pkgname | $deps | $cfls" >> $depf
+
+ # also process all of the listed depends with
+ # 'pkg_admin lsbest' to handle glob patterns
+ bestdeps=" "
+ listed=no
+ if [ ! -z "$deps" ]; then
+ for dep in $deps
+ do
+ best=`/usr/sbin/pkg_admin lsbest "${packages}/${dep}"`
+ if [ ! -z "$best" ]; then
+ best=`basename $best .tgz`
+ bestdeps=$bestdeps" "$best
+ echo "$best $pkgname" >> $deptree
+ listed=yes
+ else
+ echo "WARNING: $pkgname depends on \"$dep\" which was not found"
+ echo "WARNING: $pkgname depends on \"$dep\" which was not found" >> $warnings
+ fi
+ done
+ fi
+ if [ "$listed" = "no" ]; then
+ # make sure we add ourselves to the tree if we have no depends or if the
+ # depends were not found
+ echo "$pkgname $pkgname" >> $deptree
+ fi
+
+ echo "$pkgname | $bestdeps | $cfls" >> $depf2
+
+ npkgs=$(($npkgs + 1))
+ else
+ # Don't bomb out on 1 package
+ echo "$prog: warning: $pkg not readable"
+ fi
+done
+
+echo " "
+echo "Finished extracting dependencies and conflicts for $npkgs binary packages"
+echo " "
+
+#
+# sort the packages in dependency order
+#
+mv $deptree ${deptree}.bak
+sort -u ${deptree}.bak > ${deptree}
+tsort $deptree > $order
+
+#
+# Run the awk program which figures out which packages go on which CD.
+# This program also creates subdirectories and populates them with
+# links to the actual binary pacakges.
+#
+# packages = ARGV[1];
+# cddir = ARGV[2];
+# deptree = ARGV[3];
+# order = ARGV[4];
+# cdlist = ARGV[5];
+#
+if [ "$VERBOSE" = "yes" ]; then
+ echo "awk -f cdgen.awk $packages $cddir $deptree $order $cdlist dup=$DUP"
+fi
+awk -f @prefix@/libexec/cdgen.awk $packages $cddir $deptree $order $cdlist dup=$DUP verbose=$VERBOSE $XTRA_SIZE
+
+if [ $? -ne 0 ]; then
+ echo "$prog: ERROR: cdgen.awk has failed"
+ clean_and_exit
+fi
+
+#
+# Generate a README
+#
+cat <<EOF > $readme
+This CD-ROM collection contains NetBSD binary packages. For
+information on the NetBSD package collection, please visit
+http://www.netbsd.org/Documentation/software/packages.html.
+
+For more information about the NetBSD project, visit the
+project homepage at http://www.netbsd.org
+
+EOF
+
+if [ "$DUP" = "yes" ]; then
+cat <<EOF >> $readme
+The packages on this CD have been arranged to eliminate all
+inter-CD dependencies. In other words, each package on this
+CD should have all of its dependencies (if they are allowed
+to be provided on CD) present on the same CD.
+
+EOF
+else
+
+cat <<EOF >> $readme
+The packages on this CD have been arranged such that for a
+given package on CD number n, all of the other required
+packages are on CD number 1 through n. This allows the
+user to make a single pass through the CD set when installing
+a collection of packages.
+
+EOF
+fi
+
+cat <<EOF >> $readme
+
+This README, along with the CD layout was created using the
+cdpack program which is available as part of the NetBSD
+packages collection at
+ftp://ftp.netbsd.org/pub/NetBSD/packages/pkgsrc/pkgtools/cdpack
+.
+
+EOF
+
+#
+# Generate an index file which lists the contents of each CD.
+#
+
+echo "Creating CD Index File"
+
+for cdname in `cat $cdlist`
+do
+ for pkg in ${cddir}/${cdname}/packages/All/*
+ do
+ echo "`basename $pkg` $cdname" >> $indexf
+ done
+done
+mv $indexf ${indexf}.tmp
+sort ${indexf}.tmp > $indexf
+
+#
+# Populate the cd's with the index file and readme
+# actually copy these over since the originals will
+# be deleted from their temporary directories
+#
+ncds=0
+for cdname in `cat $cdlist`
+do
+ (cd ${cddir}/${cdname} && cp $indexf .index)
+ (cd ${cddir}/${cdname} && cp $readme README.txt)
+
+ if [ $USE_XTRA = "yes" ]; then
+ for f in $extra/*
+ do
+ (cd ${cddir}/${cdname} && ln -sf $f)
+ done
+ fi
+
+ ncds=$(($ncds + 1))
+done
+
+#
+# Create the ISO Images
+#
+volid=PackagesCD
+#mkisofs_flags="-f -l -r -J -L -volset-size $ncds -V $volid "
+mkisofs_flags="-f -l -r -J -L "
+
+echo "Creating the ISO images"
+cdn=1
+for cdname in `cat $cdlist`
+do
+ echo "----------- $cdname ----------"
+ #mkisofs_flags2=" -volset-ID $cdname -volset-seqno $cdn "
+ mkisofs_flags2=" -V ${volid}$cdn "
+ echo "(cd ${cddir} && mkisofs $mkisofs_flags $mkisofs_flags2 -o ${cdname}.iso $cdname)"
+ ( cd ${cddir} && mkisofs $mkisofs_flags $mkisofs_flags2 -o ${cdname}.iso $cdname )
+ if [ $? != 0 ]; then
+ echo "mkisofs failed"
+ clean_and_exit
+ fi
+ cdn=$(($cdn + 1))
+done
+
+echo "ISO Images are available in $cddir"
+
+if [ -f $warnings ]; then
+ echo "There were warnings generated:"
+ cat $warnings
+fi
+
+echo " "
+echo "$prog finished: `date`"
+echo " "
+
+rm -fr $TMP
+
+exit 0
+