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