Home | History | Annotate | Line # | Download | only in sets
makeplist revision 1.16
      1 #!/bin/sh
      2 #
      3 # Print out the files in some or all lists.
      4 # Usage: makeplist [-a arch] [-m machine] [-s setsdir] [-p prefix] setname pkgname
      5 #
      6 
      7 rundir=${0%/*}
      8 . ${rundir}/sets.subr
      9 prefix=/
     10 
     11 usage()
     12 {
     13 	cat 1>&2 <<USAGE
     14 Usage: ${0##*/} [-a arch] [-m machine] [-s setsdir] [-p prefix] setname pkgname
     15 	-a arch		set arch (e.g, m68k, mips, powerpc)	[$MACHINE_ARCH]
     16 	-m machine	set machine (e.g, amiga, i386, macppc)	[$MACHINE]
     17 	-s setsdir	directory to find sets			[$setsdir]
     18 	-p prefix	prefix for created plist		[$prefix]
     19 	setname pkgname	set and package to build plist for
     20 USAGE
     21 	exit 1
     22 }
     23 
     24 # handle args
     25 while getopts a:m:p:s: ch; do
     26 	case ${ch} in
     27 	a)
     28 		MACHINE_ARCH=${OPTARG}
     29 		MACHINE_CPU=$(arch_to_cpu ${OPTARG})
     30 		;;
     31 	m)
     32 		MACHINE=${OPTARG}
     33 		;;
     34 	p)
     35 		prefix=${OPTARG}
     36 		;;
     37 	s)
     38 		setsdir=${OPTARG}
     39 		;;
     40 	*)
     41 		usage
     42 		;;
     43 	esac
     44 done
     45 shift $((${OPTIND} - 1))
     46 if [ $# -ne 2 ]; then
     47 	usage
     48 fi
     49 setname="$1"
     50 pkgname=$2
     51 
     52 filename=/tmp/makeplist.$$ 
     53 ffilename=/tmp/makeplist.files.$$ 
     54 dfilename=/tmp/makeplist.dirs.$$ 
     55 
     56 list_set_files $setname | \
     57     env PLISTPKG=$pkgname awk '
     58 	$2 == ENVIRON["PLISTPKG"] {
     59 		sub("^\\./", "", $1);
     60 		print $1
     61 	}' | sort -u > $filename
     62 
     63 SELECTDIRS="-prune -type d"
     64 SELECTNONDIRS="! -type d -print -o ( -type d -prune )"
     65 
     66 cd $prefix
     67 #
     68 # Match the directories.  Use find(1) to avoid repeat calls to
     69 # 'test -d'.
     70 #
     71 # This is a little clever.  I cannot use 'xargs find', because
     72 # find wants for the option arguments to follow the path arguments.
     73 # So I use 'xargs echo $SELECTDIRS' to make a maximum-length proto-command
     74 # line.  I use 'read' to peel the options off the front of the
     75 # command-line, and 'find $args $SELECTDIRS' to put them at the end.
     76 #
     77 xargs echo $SELECTDIRS < $filename | \
     78 while read ignore ignore ignore args; do
     79 	[ -z "$args" ] && break 
     80 	find $args $SELECTDIRS
     81 done | awk '{ print "@dirrm " $1; }' > $dfilename
     82 
     83 #
     84 # Match the non-directories.  Use find(1) to avoid repeat calls to
     85 # 'test ! -d'.  See 'Match the directories' for an explanation of the
     86 # cleverness.
     87 #
     88 xargs echo $SELECTNONDIRS < $filename | \
     89 while read ignore ignore ignore ignore ignore ignore ignore ignore ignore \
     90     ignore args; do
     91 	[ -z "$args" ] && break 
     92 	find $args $SELECTNONDIRS
     93 done > $ffilename
     94 
     95 cd -
     96 
     97 echo "@cwd $prefix"
     98 if [ -s $ffilename ]; then
     99 	cat $ffilename
    100 fi
    101 if [ -s $dfilename ]; then
    102         sort -r $dfilename
    103 fi
    104 
    105 rm -f $filename $ffilename $dfilename
    106 
    107 exit 0
    108