update-all-config: squelch logallrefupdates warning for worktrees
[girocco/readme.git] / toolbox / update-all-config.pl
blobb9df9cd975c6ff87a99b996b27278dd4020241ad
1 #!/usr/bin/perl
3 # update-all-config.pl - Update all out-of-date config
5 use strict;
6 use warnings;
7 use vars qw($VERSION);
8 BEGIN {*VERSION = \'2.0'}
9 use File::Basename;
10 use File::Spec;
11 use Cwd qw(realpath);
12 use POSIX qw();
13 use Getopt::Long;
14 use Pod::Usage;
15 use lib "__BASEDIR__";
16 use Girocco::Config;
17 use Girocco::Util;
18 use Girocco::CLIUtil;
19 use Girocco::Project;
21 my $shbin;
22 BEGIN {
23 $shbin = $Girocco::Config::posix_sh_bin;
24 defined($shbin) && $shbin ne "" or $shbin = "/bin/sh";
27 exit(&main(@ARGV)||0);
29 my ($dryrun, $force, $quiet);
31 sub die_usage {
32 pod2usage(-exitval => 2);
35 sub do_help {
36 pod2usage(-verbose => 2, -exitval => 0);
39 sub do_version {
40 print basename($0), " version ", $VERSION, "\n";
41 exit 0;
44 my ($dmode, $dperm, $drwxmode, $fmode, $fmodeoct, $fperm, $wall);
45 BEGIN {
46 $dmode=02775;
47 $dperm='drwxrwsr-x';
48 $drwxmode='ug+rwx,o+rx';
49 $fmode=0664;
50 $fmodeoct='0664';
51 $fperm='-rw-rw-r--';
52 $wall=0;
55 my $owning_group_id;
56 my $htmlcache_owning_group_id;
57 my $ctags_owning_group_id;
59 sub main {
60 local *ARGV = \@_;
61 my ($help, $version);
63 umask 002;
64 close(DATA) if fileno(DATA);
65 Getopt::Long::Configure('bundling');
66 GetOptions(
67 'help|h' => sub {do_help},
68 'version|V' => sub {do_version},
69 'dry-run|n' => \$dryrun,
70 'quiet|q' => \$quiet,
71 'force|f' => \$force,
72 ) or die_usage;
73 $dryrun and $quiet = 0;
75 -f jailed_file("/etc/group") or
76 die "Girocco group file not found: " . jailed_file("/etc/group") . "\n";
78 if (!defined($Girocco::Config::owning_group) || $Girocco::Config::owning_group eq "") {
79 die "\$Girocco::Config::owning_group unset, refusing to run without --force\n" unless $force;
80 $dmode=02777;
81 $dperm='drwxrwsrwx';
82 $drwxmode='a+rwx';
83 $fmode=0666;
84 $fmodeoct='0666';
85 $fperm='-rw-rw-rw-';
86 $wall=1;
87 warn "Mode 666 in effect\n" unless $quiet;
88 } elsif (($owning_group_id = scalar(getgrnam($Girocco::Config::owning_group))) !~ /^\d+$/) {
89 die "\$Girocco::Config::owning_group invalid ($Girocco::Config::owning_group), refusing to run\n";
91 if (defined($owning_group_id) && $Girocco::Config::htmlcache_owning_group) {
92 die "\$Girocco::Config::htmlcache_owning_group invalid ($Girocco::Config::htmlcache_owning_group), refusing to run\n"
93 unless ($htmlcache_owning_group_id = scalar(getgrnam($Girocco::Config::htmlcache_owning_group))) =~ /^\d+$/;
95 if (defined($owning_group_id) && $Girocco::Config::ctags_owning_group) {
96 die "\$Girocco::Config::ctags_owning_group invalid ($Girocco::Config::ctags_owning_group), refusing to run\n"
97 unless ($ctags_owning_group_id = scalar(getgrnam($Girocco::Config::ctags_owning_group))) =~ /^\d+$/;
100 my @allprojs = Girocco::Project::get_full_list;
101 my @projects = ();
103 my $root = $Girocco::Config::reporoot;
104 $root or die "\$Girocco::Config::reporoot is invalid\n";
105 $root =~ s,/+$,,;
106 $root ne "" or $root = "/";
107 $root = realpath($root);
108 if (@ARGV) {
109 my %projnames = map {($_ => 1)} @allprojs;
110 foreach (@ARGV) {
111 s,/+$,,;
112 $_ or $_ = "/";
113 -d $_ and $_ = realpath($_);
114 s,^\Q$root\E/,,;
115 s,\.git$,,;
116 if (!exists($projnames{$_})) {
117 warn "$_: unknown to Girocco (not in etc/group)\n"
118 unless $quiet;
119 next;
121 push(@projects, $_);
123 } else {
124 @projects = sort {lc($a) cmp lc($b)} @allprojs;
127 nice_me(18);
128 my $bad = 0;
129 foreach (@projects) {
130 my $projdir = "$root/$_.git";
131 if (! -d $projdir) {
132 warn "$_: does not exist -- skipping\n" unless $quiet;
133 next;
135 if (!is_git_dir($projdir)) {
136 warn "$_: is not a .git directory -- skipping\n" unless $quiet;
137 next;
139 if (-e "$projdir/.noconfig") {
140 warn "$_: found .noconfig -- skipping\n" unless $quiet;
141 next;
143 if (!chdir($projdir)) {
144 warn "$_: chdir to project directory failed: $!\n" unless $quiet;
145 next;
147 process_one_project($_) or $bad = 1;
150 return $bad ? 1 : 0;
153 my (@mkdirs, @mkfiles);
154 my (@fixdpermsdirs, @fixdpermsrwx, @fixfpermsfiles, @fixfpermsdirs);
155 BEGIN {
156 @mkdirs = qw(refs info hooks ctags htmlcache bundles reflogs objects objects/info);
157 @mkfiles = qw(config info/lastactivity);
158 @fixdpermsdirs = qw(. refs info ctags htmlcache bundles reflogs objects objects/info);
159 @fixdpermsrwx = qw(refs objects);
160 @fixfpermsfiles = qw(HEAD config description packed-refs README.html info/lastactivity
161 info/alternates info/http-alternates info/packs);
162 @fixfpermsdirs = qw(ctags);
165 my (@boolvars, @falsevars, @false0vars, @truevars);
166 BEGIN {
167 @boolvars = qw(gitweb.statusupdates);
168 @falsevars = qw(core.ignorecase receive.denynonfastforwards);
169 @false0vars = qw(receive.autogc);
170 @truevars = qw(receive.updateserverinfo repack.writebitmaps transfer.fsckobjects);
173 my $hdr;
175 sub defval($$) {
176 return defined($_[0]) ? $_[0] : $_[1];
179 sub openfind_ {
180 my $noe = shift;
181 my $duperr;
182 if ($noe) {{
183 open $duperr, '>&2' or last;
184 my $errfd = POSIX::open(File::Spec->devnull, &POSIX::O_RDWR);
185 defined($errfd) or close($duperr), $duperr = undef, last;
186 POSIX::dup2($errfd, 2) or close($duperr), $duperr = undef;
187 POSIX::close($errfd);
189 my $fd;
190 my $ans = open $fd, '-|', "find", @_;
191 if ($noe && defined($duperr) && defined(fileno($duperr))) {
192 POSIX::dup2(fileno($duperr), 2);
193 close($duperr);
195 $ans or die "find failed: $!\n";
196 return $fd;
199 sub openfind { return openfind_(0, @_); }
200 sub openfindne { return openfind_(1, @_); }
202 sub all_remotes
204 my $config = shift;
205 return map({
206 my ($i,$r) = (index($_,"."),rindex($_,"."));
207 substr($_,$i+1,$r-$i-1);
208 } grep(/^remote\.[^.].*\.url$/i, keys(%$config)));
211 sub has_default_fetch_spec
213 my $config = shift;
214 my $default = $config->{'remotes.default'};
215 my @remotes = defined($default) ? split(' ', $default) : all_remotes($config);
216 foreach (@remotes) {
217 defval($config->{"remote.$_.url"},"") ne "" or next;
218 !defined($default) && git_bool($config->{"remote.$_.skipdefaultupdate"}) and next;
219 defval($config->{"remote.$_.fetch"},"") ne "" and return 1;
221 return 0;
224 sub is_native_git_mirror_url
226 my $bu = shift;
227 defined($bu) && $bu ne "" or return 0;
228 # All current or former natively supported by Git URLs return true:
229 # 1. rsync: (removed in 2.8.0, also recognize rsync+ and rsync::)
230 # 2. ftp:/ftps: (strongly discouraged)
231 # 3. git:
232 # 4. http:/https: (smart and non-smart)
233 # 5. ssh:
234 # 6. scp-like ssh syntax [user@]host:[^:/]
235 return $bu =~ /^(?:
236 rsync[:+] |
237 ftps?: |
238 git: |
239 https?: |
240 ssh: |
241 (?:[^\s:\@]+\@)?[^\s:\@+]+:(?!\/\/)[^\s:\\]
242 )/xi;
245 sub process_one_project
247 my ($proj) = @_;
248 my $bad = 0;
249 my $reallybad = 0;
250 $hdr = 0;
251 do {
252 if (! -d $_) {
253 if (-e $_) {
254 warn "$proj: bypassing project, exists but not directory: $_\n" unless $quiet;
255 $reallybad = $bad = 1;
256 last;
257 } else {
258 my $grpid = $owning_group_id;
259 $grpid = $htmlcache_owning_group_id
260 if $htmlcache_owning_group_id && $_ eq "htmlcache";
261 $grpid = $ctags_owning_group_id
262 if $ctags_owning_group_id && $_ eq "ctags";
263 do_mkdir($proj, $_, $grpid) or $bad = 1, last;
266 } foreach (@mkdirs);
267 return 0 if $reallybad;
269 -d $_ && check_dperm($proj, $_) or $bad = 1 foreach (@fixdpermsdirs);
270 my $fp = openfindne(@fixdpermsrwx, qw(-xdev -type d ( ! -path objects/?? -o -prune ) ! -perm), "-$drwxmode", "-print");
271 while (<$fp>) {
272 chomp;
273 change_dpermrwx($proj, $_) or $bad = 1;
275 close($fp) or $bad = 1;
276 $fp = openfind(qw(. -xdev -type d ( ! -path ./objects/?? -o -prune ) ! -perm -a+rx -print));
277 while (<$fp>) {
278 chomp;
279 change_dpermrx($proj, $_) or $bad = 1;
281 close($fp) or $bad = 1;
283 do {
284 if (-e $_) {
285 if (! -f $_) {
286 warn "$proj: bypassing project, exists but not file: $_\n" unless $quiet;
287 $reallybad = $bad = 1;
288 last;
290 } else {
291 my $result = "(dryrun)";
292 if (!$dryrun) {
293 $result = "";
294 my $tf;
295 open($tf, '>', $_) && close ($tf) or $result = "FAILED", $bad = 1;
297 pmsg($proj, "$_: created", $result) unless $quiet;
299 } foreach(@mkfiles);
300 return 0 if $reallybad;
302 $dryrun || check_fperm($proj, "config") or $bad = 1;
303 my $config = read_config_file_hash("config", !$quiet);
304 if (!defined($config)) {
305 warn "$proj: could not read config file -- skipping\n" unless $quiet;
306 return 0;
309 my $do_config = sub {
310 my ($item, $val) = @_;
311 my $oldval = defval($config->{$item},"");
312 my $result = "(dryrun)";
313 if (!$dryrun) {
314 $result = "";
315 system($Girocco::Config::git_bin, "config", "--file", "config", "--replace-all", $item, $val) == 0 or
316 $result = "FAILED", $bad = 1;
318 if (!exists($config->{$item})) {
319 pmsg($proj, "config $item: created \"$val\"", $result) unless $quiet;
320 } else {
321 pmsg($proj, "config $item: \"$oldval\" -> \"$val\"", $result) unless $quiet;
324 my $do_config_unset = sub {
325 my ($item, $msg) = @_;
326 defined($msg) or $msg = "";
327 $msg eq "" or $msg = " " . $msg;
328 my $oldval = defval($config->{$item},"");
329 my $result = "(dryrun)";
330 if (!$dryrun) {
331 $result = "";
332 system($Girocco::Config::git_bin, "config", "--file", "config", "--unset-all", $item) == 0 or
333 $result = "FAILED", $bad = 1;
335 pmsg($proj, "config $item: removed$msg \"$oldval\"", $result) unless $quiet;
338 my $repovers = $config->{'core.repositoryformatversion'};
339 if (!defined($repovers)) {
340 $repovers = "";
341 } elsif ($repovers =~ /^[2345]$/) {
342 pmsg($proj, "WARNING: unknown core.repositoryformatversion value left unchanged: \"$repovers\"");
343 } elsif ($repovers !~ /^[01]$/) {
344 pmsg($proj, "WARNING: replacing invalid core.repositoryformatversion value: \"$repovers\"") unless $quiet;
345 $repovers = "";
347 &$do_config('core.repositoryformatversion', 0) if $repovers eq "";
348 my $hookspath = $Girocco::Config::reporoot . "/_global/hooks";
349 my $cfghooks = defval($config->{'core.hookspath'},"");
350 if ($cfghooks ne $hookspath) {
351 my $updatehookspath = 1;
352 $hookspath = $Girocco::Config::reporoot . "/$proj.git/hooks" if $Girocco::Config::localhooks;
353 if ($cfghooks =~ m{^/[^/]} && -d $cfghooks && -d "hooks") {
354 # tolerate this situation provided the realpath of $cfghooks
355 # matches the realpath of the hooks subdirectory and the hooks
356 # subdirectory exists; actually making sure the correct symlinks
357 # are present remains up to update-all-hooks not us
358 if (realpath($cfghooks) eq realpath("hooks")) {
359 # we do, however, insist that it be stored exactly
360 # as $reporoot/<project_name>.git/hooks in this case because
361 # that's the only guaranteed version that works in the chroot
362 $hookspath = $Girocco::Config::reporoot . "/$proj.git/hooks";
363 $cfghooks eq $hookspath and $updatehookspath = 0;
366 &$do_config('core.hookspath', $hookspath) if $updatehookspath;
368 my $cmplvl = defval($config->{'core.compression'},"");
369 if ($cmplvl !~ /^-?\d+$/ || $cmplvl < -1 || $cmplvl > 9 || "" . (0 + $cmplvl) ne "" . $cmplvl) {
370 pmsg($proj, "WARNING: replacing invalid core.compression value: \"$cmplvl\"") unless $cmplvl eq "" || $quiet;
371 $cmplvl = "";
372 } elsif ($cmplvl != 5) {
373 pmsg($proj, "WARNING: suboptimal core.compression value left unchanged: \"$cmplvl\"") unless $quiet;
375 $cmplvl ne "" or &$do_config('core.compression', 5);
376 my $grpshr = defval($config->{'core.sharedrepository'},"");
377 if ($grpshr eq "" || (valid_bool($grpshr) && !git_bool($grpshr))) {
378 &$do_config('core.sharedrepository', 1);
379 } elsif (!(valid_bool($grpshr) && git_bool($grpshr))) {
380 pmsg($proj, "WARNING: odd core.sharedrepository value left unchanged: \"$grpshr\"");
382 if (git_bool($config->{'core.bare'})) {
383 my $setlaru = 1;
384 my $laru = $config->{'core.logallrefupdates'};
385 if (defined($laru)) {
386 if (valid_bool($laru)) {
387 $setlaru = 0;
388 if (git_bool($laru)) {
389 pmsg($proj, "WARNING: core.logallrefupdates is true (left unchanged)")
390 unless $quiet || -d "worktrees";
392 } else {
393 pmsg($proj, "WARNING: replacing non-boolean core.logallrefupdates value") unless $quiet;
396 !$setlaru or &$do_config('core.logallrefupdates', 'false');
397 } else {
398 pmsg($proj, "WARNING: core.bare is not true (left unchanged)") unless $quiet;
400 my $precious = defval($config->{'extensions.preciousobjects'},"");
401 valid_bool($precious) && git_bool($precious) or &$do_config('extensions.preciousobjects', 'true');
402 defval($config->{'transfer.unpacklimit'},"") eq "1" or &$do_config('transfer.unpacklimit', 1);
403 lc(defval($config->{'receive.denydeletecurrent'},"")) eq "warn" or &$do_config('receive.denydeletecurrent', 'warn');
404 do {
405 !exists($config->{$_}) || valid_bool(defval($config->{$_},"")) or &$do_config_unset($_, "(not a boolean)");
406 } foreach (@boolvars);
407 do {
408 (valid_bool(defval($config->{$_},"")) && !git_bool($config->{$_})) or &$do_config($_, "false");
409 } foreach (@falsevars);
410 do {
411 (valid_bool(defval($config->{$_},"")) && !git_bool($config->{$_})) or &$do_config($_, 0);
412 } foreach (@false0vars);
413 do {
414 (valid_bool(defval($config->{$_},"")) && git_bool($config->{$_})) or &$do_config($_, "true");
415 } foreach (@truevars);
417 if (defined($Girocco::Config::owning_group) && $Girocco::Config::owning_group ne "") {
418 $fp = openfind(qw(. -xdev ( -type d -o -type f ) ! -group), $Girocco::Config::owning_group, "-print");
419 while (<$fp>) {
420 chomp;
421 my $grpid = $owning_group_id;
422 $grpid = $htmlcache_owning_group_id if $htmlcache_owning_group_id && m{^\./htmlcache(?:/|$)}i;
423 $grpid = $ctags_owning_group_id if $ctags_owning_group_id && m{^\./ctags(?:/|$)}i;
424 change_group($proj, $_, $grpid) or $bad = 1;
426 close($fp) or $bad = 1;
428 foreach (@fixfpermsfiles) {
429 if (-e $_) {
430 if (! -f $_) {
431 warn "$proj: bypassing project, exists but not file: $_\n" unless $quiet;
432 $reallybad = $bad = 1;
433 last;
435 check_fperm($proj, $_) or $bad = 1;
438 return 0 if $reallybad;
440 $fp = openfindne(@fixfpermsdirs, qw(-xdev -type f ! -perm), $fmodeoct, "-print");
441 while (<$fp>) {
442 chomp;
443 check_fperm($proj, $_) or $bad = 1;
445 close($fp) or $bad = 1;
446 $fp = openfind(qw(. -xdev -type f ! -perm -a+r -print));
447 while (<$fp>) {
448 chomp;
449 check_fpermr($proj, $_) or $bad = 1;
451 close($fp) or $bad = 1;
452 $fp = openfind(qw(. -xdev -type d ( -path ./hooks -o -path ./mob/hooks ) -prune -o -type f -perm +a+x -print));
453 while (<$fp>) {
454 chomp;
455 check_fpermnox($proj, $_) or $bad = 1;
457 close($fp) or $bad = 1;
459 my $bu = defval($config->{'gitweb.baseurl'},"");
460 if (-e ".nofetch") {
461 $bu eq "" or pmsg($proj, "WARNING: .nofetch exists but gitweb.baseurl is not empty ($bu)") unless $quiet;
462 } else {
463 if ($bu eq "") {
464 if (has_default_fetch_spec($config)) {
465 pmsg($proj, "WARNING: gitweb.baseurl is empty and .nofetch does not exist but fetch spec does") unless $quiet;
466 } else {
467 pmsg($proj, "WARNING: gitweb.baseurl is empty and .nofetch does not exist") unless $quiet;
469 } elsif (is_native_git_mirror_url($bu) && !has_default_fetch_spec($config)) {
470 pmsg($proj, "WARNING: gitweb.baseurl is not empty but fetch spec is") unless $quiet;
474 return !$bad;
477 sub do_mkdir
479 my ($proj, $subdir, $grpid) = @_;
480 my $result = "";
481 if (!$dryrun) {
482 mkdir($subdir) && -d "$subdir" or $result = "FAILED";
483 if ($grpid && $grpid != $owning_group_id) {
484 my @info = stat($subdir);
485 if (@info < 6 || $info[2] eq "" || $info[4] eq "" || $info[5] eq "") {
486 $result = "FAILED";
487 } elsif ($info[5] != $grpid) {
488 if (!chown($info[4], $grpid, $subdir)) {
489 $result = "FAILED";
490 warn "chgrp: ($proj) $subdir: $!\n" unless $quiet;
491 } elsif (!chmod($info[2] & 07777, $subdir)) {
492 $result = "FAILED";
493 warn "chmod: ($proj) $subdir: $!\n" unless $quiet;
497 } else {
498 $result = "(dryrun)";
500 pmsg($proj, "$subdir/: created", $result);
501 return $result ne "FAILED";
504 sub check_dperm {
505 my ($proj, $subdir) = @_;
506 my $oldmode = (stat($subdir))[2];
507 if (!defined($oldmode) || $oldmode eq "") {
508 warn "chmod: ($proj) $subdir: No such file or directory\n" unless $quiet;
509 return 0;
511 my $newmode = ($oldmode & ~07777) | $dmode;
512 $newmode == $oldmode and return 1;
513 my $result = "";
514 if (!$dryrun) {
515 if (!chmod($newmode & 07777, $subdir)) {
516 $result = "FAILED";
517 warn "chmod: ($proj) $subdir: $!\n" unless $quiet;
519 } else {
520 $result = "(dryrun)";
522 pmsg($proj, "$subdir/:", get_mode_perm($oldmode), '->', get_mode_perm($newmode), $result);
523 return $result ne "FAILED";
526 sub change_dpermrwx {
527 my ($proj, $subdir) = @_;
528 my $oldmode = (stat($subdir))[2];
529 if (!defined($oldmode) || $oldmode eq "") {
530 warn "chmod: ($proj) $subdir: No such file or directory\n" unless $quiet;
531 return 0;
533 my $newmode = $oldmode | ($wall ? 0777 : 0775);
534 $newmode == $oldmode and return 1;
535 my $result = "";
536 if (!$dryrun) {
537 if (!chmod($newmode & 07777, $subdir)) {
538 $result = "FAILED";
539 warn "chmod: ($proj) $subdir: $!\n" unless $quiet;
541 } else {
542 $result = "(dryrun)";
544 pmsg($proj, "$subdir/:", get_mode_perm($oldmode), '->', get_mode_perm($newmode), $result);
545 return $result ne "FAILED";
548 sub change_dpermrx {
549 my ($proj, $subdir) = @_;
550 $subdir =~ s,^\./,,;
551 my $oldmode = (stat($subdir))[2];
552 if (!defined($oldmode) || $oldmode eq "") {
553 warn "chmod: ($proj) $subdir: No such file or directory\n" unless $quiet;
554 return 0;
556 my $newmode = $oldmode | 0555;
557 $newmode == $oldmode and return 1;
558 my $result = "";
559 if (!$dryrun) {
560 if (!chmod($newmode & 07777, $subdir)) {
561 $result = "FAILED";
562 warn "chmod: ($proj) $subdir: $!\n" unless $quiet;
564 } else {
565 $result = "(dryrun)";
567 pmsg($proj, "$subdir/:", get_mode_perm($oldmode), '->', get_mode_perm($newmode), $result);
568 return $result ne "FAILED";
571 sub check_fperm {
572 my ($proj, $file) = @_;
573 my $oldmode = (stat($file))[2];
574 if (!defined($oldmode) || $oldmode eq "") {
575 warn "chmod: ($proj) $file: No such file or directory\n" unless $quiet;
576 return 0;
578 my $newmode = ($oldmode & ~07777) | $fmode;
579 $newmode == $oldmode and return 1;
580 my $result = "";
581 if (!$dryrun) {
582 if (!chmod($newmode & 07777, $file)) {
583 $result = "FAILED";
584 warn "chmod: ($proj) $file: $!\n" unless $quiet;
586 } else {
587 $result = "(dryrun)";
589 pmsg($proj, "$file:", get_mode_perm($oldmode), '->', get_mode_perm($newmode), $result);
590 return $result ne "FAILED";
593 sub check_fpermr {
594 my ($proj, $file) = @_;
595 $file =~ s,^\./,,;
596 my $oldmode = (stat($file))[2];
597 if (!defined($oldmode) || $oldmode eq "") {
598 warn "chmod: ($proj) $file: No such file or directory\n" unless $quiet;
599 return 0;
601 my $newmode = $oldmode | 0444;
602 $newmode == $oldmode and return 1;
603 my $result = "";
604 if (!$dryrun) {
605 if (!chmod($newmode & 07777, $file)) {
606 $result = "FAILED";
607 warn "chmod: ($proj) $file: $!\n" unless $quiet;
609 } else {
610 $result = "(dryrun)";
612 pmsg($proj, "$file:", get_mode_perm($oldmode), '->', get_mode_perm($newmode), $result);
613 return $result ne "FAILED";
616 sub check_fpermnox {
617 my ($proj, $file) = @_;
618 $file =~ s,^\./,,;
619 my $oldmode = (stat($file))[2];
620 if (!defined($oldmode) || $oldmode eq "") {
621 warn "chmod: ($proj) $file: No such file or directory\n" unless $quiet;
622 return 0;
624 my $newmode = $oldmode & ~0111;
625 $newmode == $oldmode and return 1;
626 my $result = "";
627 if (!$dryrun) {
628 if (!chmod($newmode & 07777, $file)) {
629 $result = "FAILED";
630 warn "chmod: ($proj) $file: $!\n" unless $quiet;
632 } else {
633 $result = "(dryrun)";
635 pmsg($proj, "$file:", get_mode_perm($oldmode), '->', get_mode_perm($newmode), $result);
636 return $result ne "FAILED";
639 sub change_group {
640 my ($proj, $item, $grpid) = @_;
641 $item =~ s,^\./,,;
642 my @info = stat($item);
643 if (@info < 6 || $info[2] eq "" || $info[4] eq "" || $info[5] eq "") {
644 warn "chgrp: ($proj) $item: No such file or directory\n" unless $quiet;
645 return 0;
647 $info[5] == $grpid and return 1;
648 my $result = "";
649 if (!$dryrun) {
650 if (!chown($info[4], $grpid, $item)) {
651 $result = "FAILED";
652 warn "chgrp: ($proj) $item: $!\n" unless $quiet;
653 } elsif (!chmod($info[2] & 07777, $item)) {
654 $result = "FAILED";
655 warn "chmod: ($proj) $item: $!\n" unless $quiet;
657 } else {
658 $result = "(dryrun)";
660 my $isdir = ((($info[2] >> 12) & 017) == 004) ? '/' : '';
661 pmsg($proj, "$item$isdir: group", get_grp_nam($info[5]), '->', get_grp_nam($grpid), $result);
662 return $result ne "FAILED";
665 my $wrote; BEGIN {$wrote = ""}
666 sub pmsg {
667 my $proj = shift;
668 my $msg = join(" ", @_);
669 $msg =~ s/\s+$//;
670 my $prefix = "";
671 if (!$hdr) {
672 $prefix = $wrote . $proj . ":\n";
673 $hdr = 1;
675 print $prefix, " ", join(' ', @_), "\n";
676 $wrote = "\n";
679 my %ftypes;
680 BEGIN {%ftypes = (
681 000 => '?',
682 001 => 'p',
683 002 => 'c',
684 003 => '?',
685 004 => 'd',
686 005 => '?',
687 006 => 'b',
688 007 => '?',
689 010 => '-',
690 011 => '?',
691 012 => 'l',
692 013 => '?',
693 014 => 's',
694 015 => '?',
695 016 => 'w',
696 017 => '?'
698 my %fperms;
699 BEGIN {%fperms = (
700 0 => '---',
701 1 => '--x',
702 2 => '-w-',
703 3 => '-wx',
704 4 => 'r--',
705 5 => 'r-x',
706 6 => 'rw-',
707 7 => 'rwx'
710 sub get_mode_perm {
711 my $mode = $_[0];
712 my $str = $ftypes{($mode >> 12) & 017} .
713 $fperms{($mode >> 6) & 7} .
714 $fperms{($mode >> 3) & 7} .
715 $fperms{$mode & 7};
716 substr($str,3,1) = ($mode & 0100) ? 's' : 'S' if $mode & 04000;
717 substr($str,6,1) = ($mode & 0010) ? 's' : 'S' if $mode & 02000;
718 substr($str,9,1) = ($mode & 0001) ? 't' : 'T' if $mode & 01000;
719 return $str;
722 sub get_perm {
723 my $mode = (stat($_[0]))[2];
724 defined($mode) or return '??????????';
725 return get_mode_perm($mode);
728 sub get_grp_nam {
729 my $grpid = $_[0];
730 defined($grpid) or return '?';
731 my $grpnm = scalar(getgrgid($grpid));
732 return defined($grpnm) && $grpnm ne "" ? $grpnm : $grpid;
735 sub get_grp {
736 my $grp = (stat($_[0]))[5];
737 defined($grp) or return '?';
738 return get_grp_nam($grp);
741 __END__
743 =head1 NAME
745 update-all-config.pl - Update all projects' config settings
747 =head1 SYNOPSIS
749 update-all-config.pl [<options>] [<projname>]...
751 Options:
752 -h | --help detailed instructions
753 -V | --version show version
754 -n | --dry-run show what would be done but don't do it
755 -f | --force run without a Config.pm owning_group
756 -q | --quiet suppress change messages
758 <projname> if given, only operate on these projects
760 =head1 OPTIONS
762 =over 8
764 =item B<-h>, B<--help>
766 Print the full description of update-all-config.pl's options.
768 =item B<-V>, B<--version>
770 Print the version of update-all-config.pl.
772 =item B<-n>, B<--dry-run>
774 Do not actually make any changes, just show what would be done without
775 actually doing it.
777 =item B<-q>, B<--quiet>
779 Suppress the messages about what's actually being changed. This option
780 is ignored if B<--dry-run> is in effect.
782 The warnings about missing and unknown-to-Girocco projects are also
783 suppressed by this option.
785 =item B<-f>, B<--force>
787 Allow running without a $Girocco::Config::owning_group set. This is not
788 recommended as it results in world-writable items being used (instead of
789 just world-readable).
791 =item B<<projname>>
793 If no project names are specified then I<all> projects are processed.
795 If one or more project names are specified then only those projects are
796 processed. Specifying non-existent projects produces a warning for them,
797 but the rest of the projects specified will still be processed.
799 Each B<projname> may be either a full absolute path starting with
800 $Girocco::Config::reporoot or just the project name part with or without
801 a trailing C<.git>.
803 Any explicitly specified projects that do exist but are not known to
804 Girocco will be skipped (with a warning).
806 =back
808 =head1 DESCRIPTION
810 Inspect the C<config> files of Girocco projects (i.e. $GIT_DIR/config) and
811 look for anomalies and out-of-date settings.
813 Additionally check the existence and permissions on various files and
814 directories in the project.
816 If an explicity specified project is located under $Girocco::Config::reporoot
817 but is not actually known to Girocco (i.e. it's not in the etc/group file)
818 then it will be skipped.
820 By default, any anomalies or out-of-date settings will be corrected with a
821 message to that effect. However using B<--dry-run> will only show the
822 correction(s) which would be made without making them and B<--quiet> will make
823 the correction(s) without any messages.
825 Any projects that have a C<$GIT_DIR/.noconfig> file are always skipped (with a
826 message unless B<--quiet> is used).
828 =cut