Home | History | Annotate | Line # | Download | only in sets
makeplist revision 1.20
      1 #!/bin/sh
      2 #
      3 # Print out the files in some or all lists.
      4 # Usage: makeplist [options] setname pkgname
      5 # options:
      6 # 	-a arch		set arch (e.g, m68k, mips, powerpc)	
      7 # 	-m machine	set machine (e.g, amiga, i386, macppc)
      8 # 	-s setsdir	directory to find sets
      9 # 	-p prefix	prefix for package creation
     10 # 	-I realprefix	prefix for eventual installation
     11 # 	setname pkgname	set and package to build plist for
     12 #
     13 
     14 rundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/"
     15 . "${rundir}/sets.subr"
     16 prefix=/
     17 realprefix=/
     18 got_realprefix=false
     19 
     20 usage() {
     21 	cat 1>&2 <<USAGE
     22 Usage: $0 [options] setname pkgname"
     23 options:"
     24 	-a arch		set arch (e.g, m68k, mips, powerpc)	[${MACHINE_ARCH}]
     25 	-m machine	set machine (e.g, amiga, i386, macppc)	[${MACHINE}]
     26 	-s setsdir	directory to find sets			[${setsdir}]
     27 	-p prefix	prefix for created plist		[${prefix}]
     28 	-I realprefix	prefix for eventual installation	[${realprefix}]
     29 	setname pkgname	set and package to build plist for
     30 USAGE
     31 	exit 1
     32 }
     33 
     34 # handle args
     35 while getopts a:I:m:p:s: ch; do
     36 	case ${ch} in
     37 	a)
     38 		MACHINE_ARCH="${OPTARG}"
     39 		MACHINE_CPU="$(arch_to_cpu "${OPTARG}")"
     40 		;;
     41 	I)
     42 		realprefix=${OPTARG}
     43 		got_realprefix=true
     44 		;;
     45 	m)
     46 		MACHINE="${OPTARG}"
     47 		;;
     48 	p)
     49 		prefix="${OPTARG}"
     50 		;;
     51 	s)
     52 		setsdir="${OPTARG}"
     53 		;;
     54 	*)
     55 		usage
     56 		;;
     57 	esac
     58 done
     59 shift $((${OPTIND} - 1))
     60 if [ $# -ne 2 ]; then
     61 	usage
     62 fi
     63 setname="$1"
     64 pkgname="$2"
     65 
     66 if ! ${got_realprefix}; then
     67     realprefix="${prefix}"
     68 fi
     69 
     70 filename="/tmp/makeplist.$$"
     71 ffilename="/tmp/makeplist.files.$$"
     72 dfilename="/tmp/makeplist.dirs.$$"
     73 
     74 list_set_files "${setname}" | \
     75     ${ENV_CMD} PLISTPKG="${pkgname}" ${AWK} '
     76 	$2 == ENVIRON["PLISTPKG"] {
     77 		sub("^\\./", "", $1);
     78 		print $1
     79 	}' | ${SORT} -u > "${filename}"
     80 
     81 SELECTDIRS="-prune -type d"
     82 SELECTNONDIRS="! -type d -print -o ( -type d -prune )"
     83 
     84 #
     85 # XXX: The "lists" do not differentiate between directories and files.
     86 # But we need to differentiate between them, so we do so by checking
     87 # what's actually present in the file system.  Files or directories that
     88 # are listed in the "lists" but that do not exist in the file system end
     89 # up not appearing in our output, and this subverts a large part of the
     90 # purpose of the "lists".
     91 #
     92 # XXX: Given that we have to figure out what is or is not a directory
     93 # without assistance from the "lists", it would be much more efficient
     94 # to consult the metalog instead of the file system.
     95 #
     96 
     97 (
     98 cd "${prefix}"
     99 
    100 #
    101 # Match the directories.  Use find(1) to avoid repeat calls to
    102 # 'test -d'.
    103 #
    104 # This is a little clever.  I cannot use 'xargs find', because
    105 # find wants for the option arguments to follow the path arguments.
    106 # So I use 'xargs echo ${SELECTDIRS}' to make a maximum-length proto-command
    107 # line.  I use 'read' to peel the options off the front of the
    108 # command-line, and 'find ${args} ${SELECTDIRS}' to put them at the end.
    109 #
    110 xargs echo ${SELECTDIRS} < "${filename}" | \
    111 while read ignore ignore ignore args; do
    112 	[ -z "${args}" ] && break 
    113 	${FIND} ${args} ${SELECTDIRS}
    114 done | ${AWK} '{ print "@dirrm " $1; }' > "${dfilename}"
    115 
    116 #
    117 # Match the non-directories.  Use find(1) to avoid repeat calls to
    118 # 'test ! -d'.  See 'Match the directories' for an explanation of the
    119 # cleverness.
    120 #
    121 xargs echo ${SELECTNONDIRS} < "${filename}" | \
    122 while read ignore ignore ignore ignore ignore ignore ignore ignore ignore \
    123     ignore args; do
    124 	[ -z "${args}" ] && break 
    125 	${FIND} ${args} ${SELECTNONDIRS}
    126 done > "${ffilename}"
    127 
    128 )
    129 
    130 echo "@cwd ${realprefix}"
    131 if [ -s "${ffilename}" ]; then
    132 	cat "${ffilename}"
    133 fi
    134 if [ -s "${dfilename}" ]; then
    135         ${SORT} -r "${dfilename}"
    136 fi
    137 
    138 rm -f "${filename}" "${ffilename}" "${dfilename}"
    139 
    140 exit 0
    141