add LM 5 hw, caryatid
[light-and-matter.git] / scripts / custom / 101_reconcile_eruby_util.pl
blobeab81cdbc946a7c74cfbc95b81b196871c734a92
1 #!/usr/bin/perl
3 use strict;
4 use File::Compare;
5 use File::Copy;
7 my $info = <<"INFO";
8 I have two separate git repos, each of which includes its own copy of the identical
9 eruby_util.rb script. I want to make sure that these stay consistent.
10 If I edit the master, so it's newer than the copies, this script automatically updates
11 the copies; this shouldn't cause data loss, since any overwritten version was presumably
12 committed to its own project's git repo. If a copy differs from the master and is newer,
13 it's an error. The script 101_reconcile_eruby_util.pl should not be in the git
14 repos, because it's only useful to me.
15 INFO
17 my $master = "/home/bcrowell/Documents/programming/eruby_util_for_books/eruby_util.rb";
19 my @copies = (
20 "/home/bcrowell/Documents/writing/books/genrel/scripts/eruby_util.rb",
21 "/home/bcrowell/Documents/writing/books/sr/scripts/eruby_util.rb",
22 "/home/bcrowell/Documents/writing/books/fund/scripts/eruby_util.rb",
23 "/home/bcrowell/Documents/writing/books/physics/eruby_util.rb",
26 my $master_mod = last_modification_time($master);
27 foreach my $copy(@copies) {
28 if (compare($master,$copy) != 0) {
29 my $copy_mod = last_modification_time($copy);
30 if ($copy_mod>$master_mod) {
31 die "error in 101_reconcile_eruby_util.pl:\nfile\n $copy\ndiffers from, and is newer than,\n $master\nInfo:\n $info\n";
33 else {
34 print "101_reconcile_eruby_util.pl: overwriting\n $copy\nwith newer version from\n $master\n";
35 copy($master,$copy); # This causes the copy to be newer than the master, but that won't trigger future alarms, because they're identical.
40 sub last_modification_time {
41 my $filename = shift;
42 return ((stat ($filename))[9]); # in seconds, since 1970