diff options
author | mjl <mjl@pkgsrc.org> | 2002-03-01 01:32:13 +0000 |
---|---|---|
committer | mjl <mjl@pkgsrc.org> | 2002-03-01 01:32:13 +0000 |
commit | 5ff2b0db8fe410df1de208ac14f778c1ae785f78 (patch) | |
tree | 47c385e9e249cb1a68e26c15e8cad17a8f20e9db /sysutils/adjustkernel | |
parent | 4a9fe9d3746c6ff8dba3058ae05f3b5d3e4bde63 (diff) | |
download | pkgsrc-5ff2b0db8fe410df1de208ac14f778c1ae785f78.tar.gz |
Initial import of adjustkernel, a tool to generate a kernel config
from dmesg.
Diffstat (limited to 'sysutils/adjustkernel')
-rw-r--r-- | sysutils/adjustkernel/DESCR | 1 | ||||
-rw-r--r-- | sysutils/adjustkernel/Makefile | 28 | ||||
-rw-r--r-- | sysutils/adjustkernel/PLIST | 3 | ||||
-rw-r--r-- | sysutils/adjustkernel/files/adjustkernel | 135 | ||||
-rw-r--r-- | sysutils/adjustkernel/files/adjustkernel.1 | 57 |
5 files changed, 224 insertions, 0 deletions
diff --git a/sysutils/adjustkernel/DESCR b/sysutils/adjustkernel/DESCR new file mode 100644 index 00000000000..bd166219749 --- /dev/null +++ b/sysutils/adjustkernel/DESCR @@ -0,0 +1 @@ +Build a kernel config file from dmesg output. diff --git a/sysutils/adjustkernel/Makefile b/sysutils/adjustkernel/Makefile new file mode 100644 index 00000000000..ac4a53e4773 --- /dev/null +++ b/sysutils/adjustkernel/Makefile @@ -0,0 +1,28 @@ +# $NetBSD: Makefile,v 1.1.1.1 2002/03/01 01:32:13 mjl Exp $ + +DISTNAME= adjustkernel-1.4 +CATEGORIES= sysutils +MASTER_SITES= # empty +DISTFILES= # empty + +MAINTAINER= mjl@netbsd.org +COMMENT= Generate a kernel config + +WRKSRC= ${WRKDIR} +NO_CHECKSUM= yes +NO_PATCH= yes +NO_BUILD= yes +NO_MTREE= yes + +USE_PERL5= YES + +REPLACE_PERL= adjustkernel + +do-extract: + ${CP} ${FILESDIR}/adjustkernel ${WRKDIR} + +do-install: + ${INSTALL_SCRIPT} ${WRKDIR}/adjustkernel ${PREFIX}/bin + ${INSTALL_MAN} ${FILESDIR}/adjustkernel.1 ${PREFIX}/man/man1 + +.include "../../mk/bsd.pkg.mk" diff --git a/sysutils/adjustkernel/PLIST b/sysutils/adjustkernel/PLIST new file mode 100644 index 00000000000..aee52141971 --- /dev/null +++ b/sysutils/adjustkernel/PLIST @@ -0,0 +1,3 @@ +@comment $NetBSD: PLIST,v 1.1.1.1 2002/03/01 01:32:13 mjl Exp $ +bin/adjustkernel +man/man1/adjustkernel.1 diff --git a/sysutils/adjustkernel/files/adjustkernel b/sysutils/adjustkernel/files/adjustkernel new file mode 100644 index 00000000000..972dc6c5cc6 --- /dev/null +++ b/sysutils/adjustkernel/files/adjustkernel @@ -0,0 +1,135 @@ +#!/usr/pkg/bin/perl +#-------------------------------------------------------------------------- +# %Id: adjustkernel,v 1.1 1999/10/15 01:21:30 feyrer Exp feyrer % +# $Emsi: adjustkernel,v 1.4 2001/10/04 22:26:26 mjl Exp $ +# +# Usage: adjustkernel -f GENERIC [-o outfile] [-d] +# +# commends out any lines that aren't found in the current kernel (dmesg) +# +#-------------------------------------------------------------------------- + +use strict; +use Getopt::Long; + +#-------------------------------------------------------------------------- +sub findInDmesg($$); + +#-------------------------------------------------------------------------- +my $kernel; +my $outname; +my $debug = 0; +my $remove = 0; +my $mesg; + +die "Invalid command line" unless GetOptions( + 'debug+' => \$debug, + 'file=s' => \$kernel, + 'outfile=s' => \$outname, + 'remove+' => \$remove, + 'mesg=s' => \$mesg + ); + +########################################################################### + +die "Usage: $0 [-d] [-o outfile] -f kernel-config\n" unless $kernel; + +$| = 1 if $debug; + +if($outname) + { + close STDOUT; + open STDOUT, "> $outname" or die "Cannot write $outname: $!"; + } + +my @dmesg; + +if($mesg) + { + open DMESG, "< $mesg" or die "Cannot read $mesg: $!"; + @dmesg = <DMESG>; + close DMESG; + } +else + { + @dmesg = `dmesg`; + } + +@dmesg = grep /^\s*\w+\s+at\s+\w+/, @dmesg; + +#-------------------------------------------------------------------------- +open(K,"$kernel") or die "Cannot read $kernel: $!"; +while (<K>) + { + chomp; + if (/^\s*#/) + { # Already commented out + # Nothing + } + elsif (/(\S*)\s+at\s+(\S*)(\s*.*)$/) + { + my ( $dev, $where, $comment ) = ( $1, $2, $3 ); + + print STDERR "#>> Have? <$dev> at <$where><$comment>\n" if $debug; + + # Deal with inconsistencies + $where = '\w+\d' if $where =~ /^mii/o; + + # Expand wildcards + my $gdev=$dev; + if ($dev =~ /[?*]$/o) + { + $gdev="$`\\d"; + } + + my $gwhere = $where; + if ($where =~ /[?*]$/o) + { + $gwhere="$`\\d"; + } + + my $spat = "^${gdev}\\s+at\\s+${gwhere}"; + print STDERR "#>> ? $spat\n" if $debug; + + my $l = findInDmesg(\@dmesg, "^${gdev}\\s+at\\s+${gwhere}"); + if (! $l) + { + if ($dev !~ /mainbus/) + { # inconsistent in dmesg, never comment out mainbus at something + next if $remove; + + print "#(# "; + } + } + } + + print "$_\n"; + } +close(K); + +# Mention what we didn't find. +foreach (@dmesg) + { + print "# NOTE: NoMatch: $_"; + } + +exit 0; + +#-------------------------------------------------------------------------- +sub findInDmesg($$) + { + my ( $dref, $pattern ) = @_; + + my @r = grep /$pattern/, @$dref; + + # We matched it once, so remove it from dmesg. + # Ie. we match tr0 at isa once, but not tr* at isa later on + @$dref = grep !/$pattern/, @$dref; + + print STDERR "#>> Have! @r" if @r && $debug; + + return scalar(@r) ? $r[0] : undef; + } + +#-------------------------------------------------------------------------- + diff --git a/sysutils/adjustkernel/files/adjustkernel.1 b/sysutils/adjustkernel/files/adjustkernel.1 new file mode 100644 index 00000000000..05ca33b9506 --- /dev/null +++ b/sysutils/adjustkernel/files/adjustkernel.1 @@ -0,0 +1,57 @@ +.\" $Emsi: adjustkernel.1,v 1.1 2002/03/01 01:25:37 mjl Exp $ +.\" $NetBSD: adjustkernel.1,v 1.1.1.1 2002/03/01 01:32:14 mjl Exp $ +.\" +.Dd February 28, 2002 +.Dt adjustkernel 1 +.Sh NAME +.Nm adjustkernel +.Nd generate kernel config from dmesg +.Sh SYNOPSIS +.Nm adjustkernel +.Op Fl outfile Ar new-config +.Op Fl mesg Ar dmesg-file +.Op Fl remove +.Op Fl debug +.Fl file Ar source-config +.Sh DESCRIPTION +.Nm +generates a new kernel configuration file from the +current dmesg output and the current kernel config file. +.Pp +The generation can be customized by using the following +options: +.Bl -tag -width Fl +.It Fl debug +be verbose and generate noise (mainly useful for debugging). +.It Fl file Ar source-config +read the currently booted kernel from source-config. +This option is mandatory. +.It Fl outfile Ar new-config +saves the newly generated config file to +.Ar new-config +.It Fl mesg Ar dmesg-file +read the dmesg data from +.Ar dmesg-file, +defaults to calling +.Ar /sbin/dmesg +and using its output. +.It Fl remove +causes the tool to remove entries in the config file instead +of commenting them out. +.El +.Pp +Note that options can be shortened, as long as they can be +unambigously distinguished. +.Sh EXAMPLES +To generate a new kernel config after having booted a +GENERIC kernel, +.Bd -literal +adjustkernel -f GENERIC -o MYKERNEL +.Ed +.Sh SEE ALSO +.Xr options 4 +.Sh AUTHORS +Originally created by Hubert Feyrer <hubert.feyrer@informatik.fh-regensburg.de>, +later hacked in shape and packetized by Martin J. Laubach <mjl@netbsd.org>. +.Sh BUGS +On thursdays. |