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