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