Gentoo Archives: gentoo-ppc-dev

From: Joe McMahon <mcmahon@×××××××××××.edu>
To: Mark Guertin <gerk@g.o>
Cc: gentooppc-dev@g.o, gentooppc-user@g.o
Subject: [gentooppc-dev] Dealing with updated config files
Date: Tue, 13 Aug 2002 14:58:25
In Reply to: [gentooppc-dev] ppc KEYWORDS (aka why ebuilds may not be found) by Mark Guertin
I've been finding that dealing with the updated config files can be a real 
pain in the neck; here's a Perl scrpt to simplify it some. (Requests for
features entertained. If people really like this, I'll make an ebuild out
of it.)

#!/usr/bin/perl -w

=head1 NAME

cfgdiff - show/manage updated config files on Gentoo Linux


  # List all the files that currently have ._config
  # files waiting to be checked:

  # Show the diffs for a particular file:
  cfgdiff /etc/make.conf

  # Accept the new file, replacing the old:
  cfgdiff /etc/make.conf accept

  # Reject the new file, keeping the old:
  cfgdiff /etc/make.conf reject

=head1 USAGE

C<cfgdiff> is suitable for helping you compare new versions of config 
to old ones on Gentoo Linux. 

C<emerge> creates files containing C<._cfg000> when it wants to allow you 
check these files before putting them into your running system. Normally,
you have to use C<find> (if you can remember the proper syntax) to find 
files, and then type in the C<diff>, C<rm>, or C<mv> commands yourself to 
update these files as you deem appropriate.

C<cfgdiff> makes all this much easier. You can get the list with one 
and then easily accept the new files (moving the new file over the old), 
reject the new files (simply removing them), or edit the config file in 

Typically, you'll do some installs, and C<emerge> will warn you that you 
a dozen or so config files to check and possibly update. Use C<cfgdiff> to
see them:

  $ cfgdiff 
  0 /etc/make.conf
  1 /etc/ ...


You can then check on any indiividual file:

  $ cfgdiff /etc/make.conf
  (diff output follows)

If you like the changes, accept them:

  $ cfgdiff /etc/make.conf accept

Or reject them:

  $ cfgdiff /etc/make.conf reject

Maybe you want to edit the file before or after:

  $ cfgdiff /etc/make.conf edit

=head Why the numbers?

If you are extremely lazy, you can simply enter the number of the file you
want to process and have C<cfgdiff> handle it:

  $ cfgdiff 
  0 /etc/something_log_and_hard_to_type
  $ cfgdiff 0 
  (diff output follows)
  $ cfgdiff 0 accept

=over 4

B<Be careful!> If you C<accept> or C<reject> a file, the file numbers
I<change>! Always rerun C<cfgdiff> to re-list the files if you're not
sure about the number, or just type the name (safest).


=head1 AUTHOR

Joe McMahon (mcmahon@×××××××.org)
Copyright 2002 by Joe McMahon.

=head1 LICENSE
This software is licensed under the same terms as Perl itself.


use strict;

my $file = shift;
my $action = shift;
my ($dir, $tail, $new, @names, @filenumber, %filemap);

# This subroutine finds all of the files that have updates
# and calls a callback routine for each (oldname, newname) pair.
sub fileaction {
  my $callback = shift;
  my @names = `find /etc -iname '._cfg????_*'` unless @names;
  foreach (@names) {
     my $newfile = $_;
     my $oldfile = $_;
     $callback->($oldfile, $newfile);  

unless (defined $file) {
  # print all the files with an associated number.
  my $fileno;
  fileaction( sub { print sprintf("%4d",$fileno++)," ",$_[0],"\n"} );
else {
  # A file argument was supplied, either a name or a number.
  if (my($file_to_use) = ($file =~ /^(\d+)$/)) {
    # "backreference" to a file by number in the list.
    fileaction( sub { @filenumber = $_[0]; $filemap{$_[0]} = $_[1]; } );
    $file = $filenumber[$file_to_use];
    die "File $file_to_use doesn't exist\n" unless defined $file;

  # Get the config file corresponding to this one.
  $new = $filemap{$file};

  unless (defined $action) {
    # No action, run a diff.
    die "No emerged config file $new\n" unless -e $new;
    system "/usr/bin/diff", $file, $new;
  elsif ($action =~ /accept/) {
    # Accept the new file as-is, replacing the old one.
    system "mv $new $file";
  elsif ($action =~ /reject/) {
    # Discard the new one, leave the old one unchanged.
    unlink $new;
  elsif ($action =~ /edit/) {
    # Edit the file.
    exec "vi $file";


 --- Joe M.


Subject Author
Re: [gentooppc-dev] Dealing with updated config files Kevyn Shortell <kevyn@×××.com>