2 # $NetBSD: mkreadme,v 1.22 2008/03/15 16:27:43 joerg Exp $
4 # Script for README.html generation
6 # Copyright (c) 2002, 2005 The NetBSD Foundation, Inc.
9 # This code is derived from software contributed to The NetBSD Foundation
12 # Redistribution and use in source and binary forms, with or without
13 # modification, are permitted provided that the following conditions
15 # 1. Redistributions of source code must retain the above copyright
16 # notice, this list of conditions and the following disclaimer.
17 # 2. Redistributions in binary form must reproduce the above copyright
18 # notice, this list of conditions and the following disclaimer in the
19 # documentation and/or other materials provided with the distribution.
20 # 3. All advertising materials mentioning features or use of this software
21 # must display the following acknowledgement:
22 # This product includes software developed by the NetBSD
23 # Foundation, Inc. and its contributors.
24 # 4. Neither the name of The NetBSD Foundation nor the names of its
25 # contributors may be used to endorse or promote products derived
26 # from this software without specific prior written permission.
28 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
29 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
30 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
32 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 # POSSIBILITY OF SUCH DAMAGE.
42 TMPDIR=${TMPDIR:-/tmp/mkreadme}
43 PKGSRCDIR=${PKGSRCDIR:-/usr/pkgsrc}
44 AWK=${AWK:-/usr/bin/awk}
57 BMAKE=${BMAKE:-${makeprog}}
60 echo "$prog - Generates README.html files for a pkgsrc tree"
61 echo "Usage: $prog [-c|--cdrom] [-C|--prune] [-d|--debug] [-f|--ftp] "
62 echo " [-p|--pkgsrc directory] "
63 echo " [-P|--packages directory] [-r|--restart] "
64 echo " [-s|--summary]"
65 echo " [-S|--save-database]"
67 echo " $prog -h|--help"
69 echo " $prog -v|--version"
71 echo "The options supported by $prog are: "
73 echo " -C|--prune Prune unused README.html files which may exist in"
74 echo " pkg directories which have been removed from CVS."
76 echo " -c|--cdrom Generates CD-ROM README.html files"
78 echo " -d|--debug Enables (extremely verbose) debug output"
80 echo " -f|--ftp Generates FTP README.html files"
82 echo " -h|--help Displays this help message"
84 echo " -p|--pkgsrc dir Specifies the pkgsrc directory. Defaults to"
85 echo " the value of the PKGSRCDIR environment variable"
86 echo " if set or /usr/pkgsrc otherwise."
88 echo " -P|--packages dir Specifies the packages directory."
90 echo " -r|--restart Restart. This option assumes that the database file"
91 echo " from a previous run still exists and that the script"
92 echo " should use that instead of recreating the database."
94 echo " -s|--summary Generate pkg_summary.gz files for the binary packages"
95 echo " directories while processing them."
97 echo " -S|--save-database Does not delete the database file after the run."
98 echo " This is useful for debugging or re-running this script"
99 echo " with the -r option."
101 echo " -v|--version Displays the version of this script and exits."
103 echo "Example: $prog -p /pub/NetBSD/packages/pkgsrc -P /pub/NetBSD/packages -f"
108 if [ "x$DEBUG" = "xno" -a "x$restart" = "xno" -a "x$save" = "xno" ]; then
111 echo "Debugging output left in $TMP"
119 ######################################################################
121 # Handle command line options
123 ######################################################################
142 # We're generating README.html's for a CD-ROM
148 # Prune old README.html files from pkgs which no longer exist
160 # We're generating README.html's for a CD-ROM
173 # Specify pkgsrc directory
179 # Specify PACKAGES directory
185 # Restart (ie, don't re-generate the database file)
191 # Generate the pkg_summary.gz files
197 # Save the database files
205 ${AWK} '/^#[ \t]*\$NetBSD/ {gsub(/,v/,"",$3);printf("%s: Version %s, %s\n",$3,$4,$5); exit 0;}' $prog
209 -*) echo "$prog: ERROR: $1 is not a valid option"
221 if [ "x$DEBUG" = "xyes" ]; then
225 if [ ! -d ${PKGSRCDIR} ]; then
226 echo "ERROR: package source directory ${PKGSRCDIR} does not exist"
231 if [ ! -d $TMPDIR ]; then
235 DEPENDSTREEFILE=$TMPDIR/dependstree
236 export DEPENDSTREEFILE
237 DEPENDSFILE=$TMPDIR/depends
239 SUPPORTSFILE=$TMPDIR/supports
241 INDEXFILE=$TMPDIR/index
243 ORDERFILE=$TMPDIR/order
245 DATABASEFILE=$TMPDIR/database
247 BINPKGFILE=$TMPDIR/binpkglist
249 echo "Starting README.html generation: `date`"
251 ######################################################################
253 # Extract key pkgsrc configuration variables
255 ######################################################################
258 echo "Extracting tool variables:"
260 if [ -d ${PKGSRCDIR}/pkgtools/prereq-readme ]; then
261 cd ${PKGSRCDIR}/pkgtools/prereq-readme
262 eval "`${BMAKE} show-tools`"
263 for v in AWK CMP ECHO EXPR FGREP FIND GREP GZIP_CMD SED SETENV SORT
265 eval "echo '---->' ${v}=\"\${${v}}\""
268 echo "Error: ${PKGSRCDIR}/pkgtools/prereq-readme does not seem to exist"
273 echo "Extracting configuration variables:"
275 if [ -d ${PKGSRCDIR}/pkgtools/prereq-readme ]; then
276 cd ${PKGSRCDIR}/pkgtools/prereq-readme
277 for v in CDROM_PKG_URL_HOST CDROM_PKG_URL_DIR DISTDIR \
278 FTP_PKG_URL_HOST FTP_PKG_URL_DIR PACKAGES PKG_INFO PKG_SUFX PKG_ADMIN \
279 AUDIT_PACKAGES AUDIT_PACKAGES_FLAGS PKGTOOLS_VERSION
281 val=`${BMAKE} show-var VARNAME=${v}`
283 echo "Error: make show-var VARNAME=${v} in `pwd` "
284 echo "Failed. This is a fatal error"
287 echo "----> ${v}=\"${val}\""
288 eval "${v}=\"${val}\""
291 echo "Error: ${PKGSRCDIR}/pkgtools/prereq-readme does not seem to exist"
295 if [ `${PKG_ADMIN} -V` -lt 20080415 ]; then
296 SCAN_VULNERABILITIES=0
297 echo "----> NOT checking for vulnerabilities, pkg_install too old"
299 _PVDIR=`${PKG_ADMIN} config-var PKGVULNDIR`;
300 if [ -e "${_PVDIR}"/pkg-vulnerabilities ]; then
301 SCAN_VULNERABILITIES=2
302 echo "----> Checking for vulnerabilities"
304 SCAN_VULNERABILITIES=1
305 echo "----> NOT checking for vulnerabilities"
309 ######################################################################
311 # Decide on FTP vs CDROM README.html files
313 ######################################################################
315 if [ "$ftp_readme" = "yes" ]; then
316 PKG_URL=${FTP_PKG_URL_HOST}${FTP_PKG_URL_DIR}
317 echo "Will generate FTP readme files with PKG_URL=$PKG_URL"
319 PKG_URL=${CDROM_PKG_URL_HOST}${CDROM_PKG_URL_DIR}
320 echo "Will generate CD-ROM readme files with PKG_URL=$PKG_URL"
323 ######################################################################
325 # Check for command line switch for packages directory
327 ######################################################################
329 # we've been given the directory as a command line switch
330 if [ ! -z "$PKGDIR" ]; then
332 echo "PACKAGES specified on command line to be $PKGDIR"
336 ######################################################################
338 # Extract Database for All Packages (longest step)
340 ######################################################################
342 if [ "x$restart" = "xno" ] ; then
344 echo "Extracting data. This could take a while"
345 echo "Started at: `date` "
349 # make sure we don't have an old database lying around
353 cats=`${BMAKE} show-subdir-var VARNAME=SUBDIR`
354 for c in ${cats} ; do
355 if [ ! -d ${PKGSRCDIR}/${c} ]; then
356 echo "WARNING: The category directory ${c} does not seem to" > /dev/stderr
357 echo " exist under ${PKGSRCDIR}" > /dev/stderr
360 echo "Extracting data for category ${c}"
362 list=`${BMAKE} show-subdir-var VARNAME=SUBDIR`
363 for pkgdir in $list ; do
365 if [ ! -d $pkgdir ]; then
367 echo "WARNING: the package directory $pkgdir is listed in" > /dev/stderr
368 echo " ${PKGSRCDIR}/${c}/Makefile" > /dev/stderr
369 echo " but the directory does not exist. Please fix this!" > /dev/stderr
371 cd ${PKGSRCDIR}/${c}/${pkgdir}
372 l=`${BMAKE} print-summary-data`
374 echo "WARNING (printdepends): the package in ${c}/${pkgdir} had problem with" \
376 echo " ${BMAKE} print-summary-data" > /dev/stderr
377 echo " database information for this package" > /dev/stderr
378 echo " will be dropped." > /dev/stderr
379 ${BMAKE} print-summary-data 2>&1 > /dev/stderr
381 echo "$l" >> $DATABASEFILE
385 if [ `${EXPR} $npkg % 100 = 0` -eq 1 ]; then
389 npkg=`${EXPR} $npkg + 1`
395 echo "Finished extracting data for ${npkg} packages at: `date` "
398 echo "Using existing database (are you sure you wanted the -r/--restart flag?)"
400 if [ ! -f $DATABASEFILE ]; then
402 echo "ERROR: You have use the -r/--restart flag but the database "
403 echo " file $DATABASEFILE does not exist"
409 ######################################################################
411 # Generate the package and category README.html files
413 ######################################################################
416 echo "Generating package README.html files"
418 if [ "x$DEBUG" = "xyes" ]; then
424 ${AWK} -f ${PKGSRCDIR}/mk/scripts/genreadme.awk \
425 builddependsfile=${TMPDIR}/pkgsrc.builddepends.debug \
427 dependsfile=${TMPDIR}/pkgsrc.depends.debug \
434 GZIP_CMD="$GZIP_CMD" \
436 PKG_ADMIN="$PKG_ADMIN" \
437 PKG_INFO="$PKG_INFO" \
440 PKGSRCDIR=$PKGSRCDIR \
441 PKGTOOLS_VERSION=$PKGTOOLS_VERSION \
442 SCAN_VULNERABILITIES=${SCAN_VULNERABILITIES} \
450 echo "Error: genreadme.awk failed to create README.html files"
454 ######################################################################
456 # Generate the README-IPv6.html file
458 ######################################################################
461 echo "Generating the README-IPv6.html file"
464 ipv6=${TMPDIR}/ipv6pkgs
465 ipv6_entries=${TMPDIR}/ipv6_entries
466 ${GREP} -l -e '^BUILD_DEFS.*=.*IPV6_READY' -e '^PKG_SUPPORTED_OPTIONS.*=.*inet6' -e '^USE_FEATURES.*=.*inet6' */*/Makefile */*/options.mk | ${SED} -e 's;Makefile;;g' -e 's;options.mk;;g' > $ipv6
467 ${FGREP} -f $ipv6 README-all.html | sort -t/ +1 > $ipv6_entries
469 -e "/%%TRS%%/r${ipv6_entries}" \
471 templates/README.ipv6 > ${TMPDIR}/README-IPv6.html
473 echo "Error: README-IPv6.html generation failed (on sed script)"
477 if [ ! -f README-IPv6.html ]; then
478 mv -f ${TMPDIR}/README-IPv6.html README-IPv6.html
479 elif cmp -s ${TMPDIR}/README-IPv6.html README-IPv6.html ; then
480 echo "README-IPv6.html is unchanged (no changes were needed)"
482 mv -f ${TMPDIR}/README-IPv6.html README-IPv6.html
485 ######################################################################
487 # Prune README.html files which are no longer needed
489 ######################################################################
490 if [ "x$prune" = "xyes" ]; then
492 echo "Pruning unused README.html files"
495 for d in `ls -d */*` ; do
496 if [ -d $d -a ! -f ${d}/Makefile -a -f ${d}/README.html ]; then
497 echo "Pruning ${d}/README.html which is no longer used"
498 rm -f ${d}/README.html
503 ######################################################################
505 # All done. Clean (if needed) and exit
507 ######################################################################
509 echo "README.html generation finished: `date`"
511 if [ "x$DEBUG" = "xno" -a "x$restart" = "xno" -a "x$save" = "xno" ]; then
514 echo "Debugging output left in $TMPDIR"