Hoping that /usr/sbin isn't full yet... This makes easier to get to package readme files:
- Now you'll have exact command to view all added/changed readme files printed right after pkg_add(1) run; - You can simply type "pkg_readme mysql" if you're not sure what and where in MySQL you need to tweak, and still get there. kirby@ already liked it. Any more thoughts? -- WBR, Vadim Zhukov Index: Makefile =================================================================== RCS file: /cvs/src/usr.sbin/pkg_add/Makefile,v retrieving revision 1.80 diff -u -p -r1.80 Makefile --- Makefile 14 Apr 2014 10:56:11 -0000 1.80 +++ Makefile 8 Jul 2014 16:46:46 -0000 @@ -2,7 +2,8 @@ .include <bsd.own.mk> -MAN1=pkg_add.1 pkg_info.1 pkg_create.1 pkg_delete.1 pkg_mklocatedb.1 pkg_sign.1 +MAN1=pkg_add.1 pkg_info.1 pkg_create.1 pkg_delete.1 pkg_mklocatedb.1 \ + pkg_sign.1 pkg_readme.1 MAN5=package.5 pkg.conf.5 MAN8=pkg_check.8 MAN=${MAN1} ${MAN5} ${MAN8} @@ -76,7 +77,8 @@ PACKAGEDIRS=OpenBSD OpenBSD/PackageRepo OpenBSD/LibSpec SCRIPTS= pkg_add \ - pkg_mklocatedb + pkg_mklocatedb \ + pkg_readme SCRIPTS_LNK = \ pkg_add pkg_check \ Index: pkg_readme =================================================================== RCS file: pkg_readme diff -N pkg_readme --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ pkg_readme 8 Jul 2014 16:46:46 -0000 @@ -0,0 +1,109 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use OpenBSD::PackageName; +use OpenBSD::State; +use POSIX qw/mktime strftime/; + +my $state = OpenBSD::State->new("pkg_readme"); +our ($opt_L); +$state->handle_options('L:', + '[-L localbase] [count | pkgname-substring [...]]'); + +my $pager = $ENV{'PAGER'} // 'more'; + +my $readmesdir = ($opt_L // '/usr/local') . '/share/doc/pkg-readmes'; +chdir($readmesdir) or + $state->fatal("cannot chdir to #1: #2", $readmesdir, "$!"); + +my ($stemlookup, $listcount, $from, $till); +if ($#ARGV == -1) { + $stemlookup = 0; +} elsif ($#ARGV == 0 and $ARGV[0] =~ /^[0-9]+$/) { + $stemlookup = 0; + $listcount = int($ARGV[0]); + exit(0) if $listcount == 0; +} elsif ($#ARGV == 0 and $ARGV[0] eq 'today') { + my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime; + $from = mktime(0, 0, 0, $mday, $mon, $year, $wday, $yday, $isdst); + $till = mktime(0, 0, 0, $mday+1, $mon, $year, $wday, $yday, $isdst); + $listcount = 10000000000; # XXX big enough +} else { + $stemlookup = 1; +} + +sub exec_pager(@) { + do { # To silence warning about non-reachable code + exec { $pager } ($pager, @_); + } while (0); + $state->fatal("exec failed: #1", "$!"); +} + +opendir(my $dirh, ".") or + $state->fata("cannot open directory #1: #2", $readmesdir, "$!"); +if ($stemlookup) { + my @allreadmes = grep { -f $_ } readdir $dirh; + closedir $dirh; + + my $stems = OpenBSD::PackageName::compile_stemlist(@allreadmes); + my @pkglist; + foreach (@ARGV) { + if (OpenBSD::PackageName::is_stem $_) { + my @found = $stems->find_partial($_); + if (@found) { + push @pkglist, @found; + } else { + $state->errsay("#1: wrong package name ". + "or no readme file for #2", + "pkg_readme", $_); + } + } elsif (!/\// and -f $_) { + push @pkglist, $_; + } else { + $state->errsay("#1: wrong package name or no ". + "readme file for #2", "pkg_readme", $_); + } + } + + if (@pkglist) { + exec_pager(@pkglist); + } else { + exit(1); + } +} else { + my $maxlen = 0; + my %readmes; + while (readdir $dirh) { + next unless -f $_; + my @stat = stat($_); + next unless @stat; + + # $stat[9] is mtime + next if defined($from) and $stat[9] < $from; + next if defined($till) and $stat[9] >= $till; + $readmes{$_} = $stat[9]; + + $maxlen = length($_) if length($_) > $maxlen; + } + closedir $dirh; + + exit(1) unless %readmes; + + if ($listcount) { + my @sorted = sort { $readmes{$b} <=> $readmes{$a} } keys %readmes; + $listcount = @sorted if @sorted < $listcount; + exec_pager(@sorted[0 .. $listcount-1]); + } else { + # List packages with available readme files + my @sorted = sort { $readmes{$a} <=> $readmes{$b} } keys %readmes; + foreach (@sorted) { + my $time = strftime("%c", localtime($readmes{$_})); + $state->say("#1", sprintf("%-${maxlen}s %s", $_, + $time)); + } + } +} + +exit(0); Index: pkg_readme.1 =================================================================== RCS file: pkg_readme.1 diff -N pkg_readme.1 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ pkg_readme.1 8 Jul 2014 16:46:46 -0000 @@ -0,0 +1,104 @@ +.\" $OpenBSD$ +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" +.Dd $Mdocdate$ +.Dt PKG_README 1 +.Os +.Sh NAME +.Nm pkg_readme +.Nd list and display readme files for packages +.Sh SYNOPSIS +.Nm +.Bk -words +.Op Fl L Ar localbase +.Op Ar number +.Ek +.Pp +.Nm +.Bk -words +.Op Fl L Ar localbase +.Ar date +.Ek +.Pp +.Nm +.Bk -words +.Op Fl L Ar localbase +.Ar pkg-name +.Op Ar ... +.Ek +.Sh DESCRIPTION +When run without arguments, +.Nm +will list all available readme files for installed packages together +with time stamps of last modification, sorted by timestamp. +.Pp +If single argument is given, and it's a non-negative +.Ar number , +then +.Nm +will show last +.Ar number +installed or updated readme files. +And if this single argument is +.Dq today +then only readme files installed or updated today will be listed. +.Pp +Otherwise, all arguments will be treated as a list of package names +and/or their stems, and +.Nm +will try to find and display readme files for matching packages. +Package name matching is partial, so both +.Ar postgresql-server +and +.Ar postgresql +will match +.Ar postgresql-server-9.2.1 +package. +.Pp +.Nm +does not look into packages repository itself. +Thus +.Nm +can misbehave if packages are being installed, updated or removed while +it is running. +.Pp +The options are as follows: +.Bl -tag -width Ds +.It Fl L Ar localbase +.Nm +looks for readme files in +.Pa share/doc/pkg-readmes +subdirectory of +.Ar localbase . +Defaults to +.Pa /usr/local . +See +.Xr bsd.port.mk 5 +for a description of +.Ev LOCALBASE . +.El +.Sh ENVIRONMENT +.Bl -tag -width PAGER +.It Ev PAGER +Program used to display files. +If unset, +.Xr more 1 +is used. +.Sh SEE ALSO +.Xr pkg_info 1 +.Sh HISTORY +The +.Nm +command appeared in +.Ox 5.4 . +.Sh AUTHORS +This program was written by Vadim Zhukov. Index: OpenBSD/PackingElement.pm =================================================================== RCS file: /cvs/src/usr.sbin/pkg_add/OpenBSD/PackingElement.pm,v retrieving revision 1.234 diff -u -p -r1.234 PackingElement.pm --- OpenBSD/PackingElement.pm 18 Mar 2014 18:53:29 -0000 1.234 +++ OpenBSD/PackingElement.pm 8 Jul 2014 16:46:46 -0000 @@ -183,7 +183,7 @@ sub finish OpenBSD::PackingElement::Fontdir->finish($state); OpenBSD::PackingElement::RcScript->report($state); if ($state->{readmes}) { - $state->say("Look in #1/share/doc/pkg-readmes for extra documentation.", $state->{localbase}); + $state->say("Run 'pkg_readme #1' for extra documentation.", $state->{readmes}); } }