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 umask 022 35 # handle args 36 while getopts a:I:m:p:s: ch; do 37 case ${ch} in 38 a) 39 MACHINE_ARCH="${OPTARG}" 40 MACHINE_CPU="$(arch_to_cpu "${OPTARG}")" 41 ;; 42 I) 43 realprefix=${OPTARG} 44 got_realprefix=true 45 ;; 46 m) 47 MACHINE="${OPTARG}" 48 ;; 49 p) 50 prefix="${OPTARG}" 51 ;; 52 s) 53 setsdir="${OPTARG}" 54 ;; 55 *) 56 usage 57 ;; 58 esac 59 done 60 shift $((${OPTIND} - 1)) 61 if [ $# -ne 2 ]; then 62 usage 63 fi 64 setname="$1" 65 pkgname="$2" 66 67 if ! ${got_realprefix}; then 68 realprefix="${prefix}" 69 fi 70 71 filename="/tmp/makeplist.$$" 72 ffilename="/tmp/makeplist.files.$$" 73 dfilename="/tmp/makeplist.dirs.$$" 74 75 list_set_files "${setname}" | \ 76 ${ENV_CMD} PLISTPKG="${pkgname}" ${AWK} ' 77 $2 == ENVIRON["PLISTPKG"] { 78 sub("^\\./", "", $1); 79 print $1 80 }' | ${SORT} -u > "${filename}" 81 82 SELECTDIRS="-prune -type d" 83 SELECTNONDIRS="! -type d -print -o ( -type d -prune )" 84 85 # 86 # XXX: The "lists" do not differentiate between directories and files. 87 # But we need to differentiate between them, so we do so by checking 88 # what's actually present in the file system. Files or directories that 89 # are listed in the "lists" but that do not exist in the file system end 90 # up not appearing in our output, and this subverts a large part of the 91 # purpose of the "lists". 92 # 93 # XXX: Given that we have to figure out what is or is not a directory 94 # without assistance from the "lists", it would be much more efficient 95 # to consult the metalog instead of the file system. 96 # 97 98 ( 99 cd "${prefix}" 100 101 # 102 # Match the directories. Use find(1) to avoid repeat calls to 103 # 'test -d'. 104 # 105 # This is a little clever. I cannot use 'xargs find', because 106 # find wants for the option arguments to follow the path arguments. 107 # So I use 'xargs echo ${SELECTDIRS}' to make a maximum-length proto-command 108 # line. I use 'read' to peel the options off the front of the 109 # command-line, and 'find ${args} ${SELECTDIRS}' to put them at the end. 110 # 111 xargs echo ${SELECTDIRS} < "${filename}" | \ 112 while read ignore ignore ignore args; do 113 [ -z "${args}" ] && break 114 ${FIND} ${args} ${SELECTDIRS} 115 done | ${AWK} '{ print "@pkgdir " $1; }' > "${dfilename}" 116 117 # 118 # Match the non-directories. Use find(1) to avoid repeat calls to 119 # 'test ! -d'. See 'Match the directories' for an explanation of the 120 # cleverness. 121 # 122 xargs echo ${SELECTNONDIRS} < "${filename}" | \ 123 while read ignore ignore ignore ignore ignore ignore ignore ignore ignore \ 124 ignore args; do 125 [ -z "${args}" ] && break 126 ${FIND} ${args} ${SELECTNONDIRS} 127 done > "${ffilename}" 128 129 ) 130 131 echo "@cwd ${realprefix}" 132 if [ -s "${ffilename}" ]; then 133 cat "${ffilename}" 134 fi 135 if [ -s "${dfilename}" ]; then 136 ${SORT} -r "${dfilename}" 137 fi 138 139 rm -f "${filename}" "${ffilename}" "${dfilename}" 140 141 exit 0 142