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
Message-Id: Pine.LNX.4.44.0208131350590.21841-100000@tribal.metalab.unc.edu
In Reply to: [gentooppc-dev] ppc KEYWORDS (aka why ebuilds may not be found) by Mark Guertin
1 I've been finding that dealing with the updated config files can be a real
2 pain in the neck; here's a Perl scrpt to simplify it some. (Requests for
3 features entertained. If people really like this, I'll make an ebuild out
4 of it.)
5
6 #!/usr/bin/perl -w
7
8 =head1 NAME
9
10 cfgdiff - show/manage updated config files on Gentoo Linux
11
12 =head1 SYNOPSYS
13
14 # List all the files that currently have ._config
15 # files waiting to be checked:
16 cfgdiff
17
18 # Show the diffs for a particular file:
19 cfgdiff /etc/make.conf
20
21 # Accept the new file, replacing the old:
22 cfgdiff /etc/make.conf accept
23
24 # Reject the new file, keeping the old:
25 cfgdiff /etc/make.conf reject
26
27 =head1 USAGE
28
29 C<cfgdiff> is suitable for helping you compare new versions of config
30 files
31 to old ones on Gentoo Linux.
32
33 C<emerge> creates files containing C<._cfg000> when it wants to allow you
34 to
35 check these files before putting them into your running system. Normally,
36 you have to use C<find> (if you can remember the proper syntax) to find
37 these
38 files, and then type in the C<diff>, C<rm>, or C<mv> commands yourself to
39 update these files as you deem appropriate.
40
41 C<cfgdiff> makes all this much easier. You can get the list with one
42 command,
43 and then easily accept the new files (moving the new file over the old),
44 reject the new files (simply removing them), or edit the config file in
45 question.
46
47 Typically, you'll do some installs, and C<emerge> will warn you that you
48 have
49 a dozen or so config files to check and possibly update. Use C<cfgdiff> to
50 see them:
51
52 $ cfgdiff
53 0 /etc/make.conf
54 1 /etc/ ...
55
56 $
57
58 You can then check on any indiividual file:
59
60 $ cfgdiff /etc/make.conf
61 (diff output follows)
62 $
63
64 If you like the changes, accept them:
65
66 $ cfgdiff /etc/make.conf accept
67 $
68
69 Or reject them:
70
71 $ cfgdiff /etc/make.conf reject
72
73 Maybe you want to edit the file before or after:
74
75 $ cfgdiff /etc/make.conf edit
76
77 =head Why the numbers?
78
79 If you are extremely lazy, you can simply enter the number of the file you
80 want to process and have C<cfgdiff> handle it:
81
82 $ cfgdiff
83 0 /etc/something_log_and_hard_to_type
84 $ cfgdiff 0
85 (diff output follows)
86 $ cfgdiff 0 accept
87
88 =over 4
89
90 B<Be careful!> If you C<accept> or C<reject> a file, the file numbers
91 I<change>! Always rerun C<cfgdiff> to re-list the files if you're not
92 sure about the number, or just type the name (safest).
93
94 =back
95
96 =head1 AUTHOR
97
98 Joe McMahon (mcmahon@×××××××.org)
99 Copyright 2002 by Joe McMahon.
100
101 =head1 LICENSE
102 This software is licensed under the same terms as Perl itself.
103
104 =cut
105
106 use strict;
107
108 my $file = shift;
109 my $action = shift;
110 my ($dir, $tail, $new, @names, @filenumber, %filemap);
111
112 # This subroutine finds all of the files that have updates
113 # and calls a callback routine for each (oldname, newname) pair.
114 sub fileaction {
115 my $callback = shift;
116 my @names = `find /etc -iname '._cfg????_*'` unless @names;
117 foreach (@names) {
118 chomp;
119 my $newfile = $_;
120 s/._cfg.{4}_//;
121 my $oldfile = $_;
122 $callback->($oldfile, $newfile);
123 }
124 }
125
126 unless (defined $file) {
127 # print all the files with an associated number.
128 my $fileno;
129 fileaction( sub { print sprintf("%4d",$fileno++)," ",$_[0],"\n"} );
130 }
131 else {
132 # A file argument was supplied, either a name or a number.
133 if (my($file_to_use) = ($file =~ /^(\d+)$/)) {
134 # "backreference" to a file by number in the list.
135 fileaction( sub { @filenumber = $_[0]; $filemap{$_[0]} = $_[1]; } );
136 $file = $filenumber[$file_to_use];
137 die "File $file_to_use doesn't exist\n" unless defined $file;
138 }
139
140 # Get the config file corresponding to this one.
141 $new = $filemap{$file};
142
143 unless (defined $action) {
144 # No action, run a diff.
145 die "No emerged config file $new\n" unless -e $new;
146 system "/usr/bin/diff", $file, $new;
147 }
148 elsif ($action =~ /accept/) {
149 # Accept the new file as-is, replacing the old one.
150 system "mv $new $file";
151 }
152 elsif ($action =~ /reject/) {
153 # Discard the new one, leave the old one unchanged.
154 unlink $new;
155 }
156 elsif ($action =~ /edit/) {
157 # Edit the file.
158 exec "vi $file";
159 }
160 }
161
162 Enjoy.
163
164 --- Joe M.

Replies

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