NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: replacement tool for "adjustkernel"



Eric d'Halibut пишет:
adjustkernel, a tool for analyzing dmesg output in order to configure
a kernel config file, is long, or so it seems to me tonight after a
little time looking for it, gone.

Has anyone an alternative to it?

Hi! A lot time ago I wrote some little script on awk that do same as like alternative tools
adjustkernel, dmassage. Perl is bloat, awk is cool :)
Save it to dmesg2gen.sh for example and invoke:
dmesg | dmesg2gen.sh /usr/sys/arch/i386/conf/GENERIC > myconfig

with option -s you can strip all commented lines on output.

#!/bin/sh

if [ "X"$1 = X"-s" ]; then
    shift; VS="-v strip=1"
fi

/usr/bin/awk `echo ${VS:-"-v strip=0"}` '
BEGIN {
  progname = "deconf";
  comment_chars  = "#-#";

  if (ARGC < 2) {
    print "Usage: " progname " [-s] GENERIC_FILE";
    print "Reading dmesg(8) output from standart input" \
     " and output config template.";
    bailout = 1; exit;
  }

  if ((getline < (gen = ARGV[1])) == -1) {
    print progname ": " gen ": not found or not readable" > "/dev/stderr";
    bailout = 1; exit;
  }
  close(gen);

  ARGV[1] = "-"; # read output from dmesg from standart input
}

/^[a-z]+[0-9]+[ ]+at[ ]+[a-z]+[0-9]+/ {
  sub(/:$/, "", $3);
  dmesg[$1] = $3;
}

END {
  if (bailout) exit(1);

  while(getline < gen) {
    if (match($0, /^[a-z]+[*?0-9]+[ \t]+at[ \t]+[a-z]+[*?0-9]+/)) {
    split(substr($0, RSTART, RLENGTH), spec);
    gdev = ggdev = spec[1]; gwhere = ggwhere = spec[3];
    matches = 0;
    sub(/[*?0-9]+$/, "", ggdev);
    sub(/[*?0-9]+$/, "", ggwhere);
    for(s in dmesg) {
      if ((substr(s, 1, length(s)-1) == ggdev) &&
          (substr(dmesg[s], 1, length(dmesg[s])-1) == ggwhere)) {
        #print gdev " -> " gwhere " : " s " -> " dmesg[s];
        if ((gdev ~ /[*?]+$/ && gwhere ~ /[*?]+$/) ||
        (gdev == s && gwhere ~ /[*?]+$/)  ||
        (gdev == s && gwhere == dmesg[s]) ||
        (gdev ~ /[*?]+$/ && gwhere == dmesg[s])) {
          matches++; delete dmesg[s];
          continue;
        }
      }
      # phys can have any parent
      if ((substr(s, 1, length(s)-1) == ggdev) && ggwhere == "mii") {
        matches++; delete dmesg[s];
      }
    }
    if (matches == 0) { if (!strip) print comment_chars $0; } else print;
    }
    else {
      if ((/^[ \t]*$/ || /^[ \t]*#/) && strip) continue;
      print;
    }
  }
  close(gen);

  matches = 0; for(s in dmesg) matches++;
  if (matches) {
    print "\n# deconfig orphaned records: ";
    for(s in dmesg) { print "#" s " at " dmesg[s]; }
  }
}
' $@


Home | Main Index | Thread Index | Old Index