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