Gentoo Logo
Gentoo Spaceship




Note: Due to technical difficulties, the Archives are currently not up to date. GMANE provides an alternative service for most mailing lists.
c.f. bug 424647
List Archive: gentoo-ppc-dev
Navigation:
Lists: gentoo-ppc-dev: < Prev By Thread Next > < Prev By Date Next >
Headers:
To: Mark Guertin <gerk@g.o>
From: Joe McMahon <mcmahon@...>
Subject: Dealing with updated config files
Date: Tue Aug 13 14:59:05 2002
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

=head1 SYNOPSYS

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

  # 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 
files
to old ones on Gentoo Linux. 

C<emerge> creates files containing C<._cfg000> when it wants to allow you 
to 
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 
these
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 
command, 
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 
question.

Typically, you'll do some installs, and C<emerge> will warn you that you 
have
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).

=back

=head1 AUTHOR

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

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

=cut

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) {
     chomp;
     my $newfile = $_;
     s/._cfg.{4}_//;
     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";
  }
}

Enjoy. 

 --- Joe M.



Replies:
Re: Dealing with updated config files
-- Kevyn Shortell
References:
ppc KEYWORDS (aka why ebuilds may not be found)
-- Mark Guertin
Navigation:
Lists: gentoo-ppc-dev: < Prev By Thread Next > < Prev By Date Next >
Previous by thread:
Re: [gentooppc-user] ppc KEYWORDS (aka why ebuilds may not be found)
Next by thread:
Re: Dealing with updated config files
Previous by date:
Re: [gentooppc-user] ppc KEYWORDS (aka why ebuilds may not be found)
Next by date:
ppc KEYWORDS


Updated Jun 17, 2009

Summary: Archive of the gentoo-ppc-dev mailing list.

Donate to support our development efforts.

Copyright 2001-2013 Gentoo Foundation, Inc. Questions, Comments? Contact us.