chiark / gitweb /
Almost ready to try out on viking; must still remove colons.
authorian <ian>
Wed, 18 Jul 2001 20:44:39 +0000 (20:44 +0000)
committerian <ian>
Wed, 18 Jul 2001 20:44:39 +0000 (20:44 +0000)
.cvsignore [new file with mode: 0644]
config [new file with mode: 0644]
files/_.ircrc
files/private_ircpass [new file with mode: 0644]
gpt
perms
process [new file with mode: 0755]

diff --git a/.cvsignore b/.cvsignore
new file mode 100644 (file)
index 0000000..3e75765
--- /dev/null
@@ -0,0 +1 @@
+new
diff --git a/config b/config
new file mode 100644 (file)
index 0000000..9014c2a
--- /dev/null
+++ b/config
@@ -0,0 +1,2 @@
+@@-
+chomp($hostname= `uname -n`); $? and die;
index 9596ad34758f4ecc2897870782213c76d664f889..eefaac2f64b842ff809931ea4cc5f590e6ab2deb 100644 (file)
@@ -14,9 +14,7 @@
   join #topics
   join #chiark
 }
-/alias blight-id {
-  msg blight identpass ijackson Wfd38Blo
-}
+/load private/ircpass
 /alias fastness-id
   exec -msg Fastness -name fastness-id-proc irc-fastness-id
 }
diff --git a/files/private_ircpass b/files/private_ircpass
new file mode 100644 (file)
index 0000000..08dd3a5
--- /dev/null
@@ -0,0 +1,3 @@
+/alias blight-id {
+  msg blight identpass ijackson Wfd38Blo
+}
diff --git a/gpt b/gpt
index d87e7891c03d651fd00c8eecab3d6ad39a71eb0d..c50443ad910460820896cf4758290a40d896ce07 100755 (executable)
--- a/gpt
+++ b/gpt
@@ -17,7 +17,19 @@ package GenericPrepTemplate;
 use IO::Handle;
 use IO::File;
 
-open DEBUG, ">&4";
+open DEBUG, ">/dev/null" or die "gpt: /dev/null: $!\n";
+
+while (@main::ARGV =~ m/^-/) {
+    $_= shift @main::ARGV;
+    next if m/^--$/;
+    while (m/^-./) {
+       if (s/^-d/-/) {
+           open DEBUG, ">&2" or die "gpt: debug to stderr: $!\n";
+       } else {
+           die "gpt: unknown option \`$_'\n";
+       }
+    }
+}
 
 $fn= '<command line>';
 if (!@main::ARGV) {
diff --git a/perms b/perms
index 208c85b99ad8b56270b995cf0adb122fc51bb8d7..ef0233c229c47d9af43adffe616db71981f1d21a 100644 (file)
--- a/perms
+++ b/perms
@@ -1,2 +1,4 @@
-.bash_history          0000
+.bash_history          0400
 .configs/cache/                2770
+private/               2770
+.
diff --git a/process b/process
new file mode 100755 (executable)
index 0000000..56f25a5
--- /dev/null
+++ b/process
@@ -0,0 +1,142 @@
+#!/usr/bin/perl
+
+use POSIX;
+
+$action=0;
+defined($umask=umask) or die $!;
+$home= $ENV{'HOME'}.'/';
+
+while (@ARGV =~ m/^-/) {
+    $_= shift(@ARGV);
+    last if m/^--$/;
+    while (m/^-./) {
+       if (s/^-y/-/) {
+           $action=1;
+       } elsif (s/^-u([0-7]{3})/-/) {
+           $umask= oct $1;
+       } elsif (s/^-h/-/) {
+           $home= $';
+       } else {
+           die;
+       }
+    }
+}
+
+stat $home or die $!;
+-d _ or die;
+
+sub read_prep ($) {
+    my ($inputfile) = @_;
+    defined($c= open P, "-|") or die $!;
+    if (!$c) { exec './gpt','config',$inputfile; die $!; }
+}
+sub fin_prep () {
+    $!=0; close P; die "$! $?" if $! or $?;
+}
+
+read_prep('perms');
+for (;;) {
+    $!=0; defined($_=<P>) or die $!;
+    chomp; s/^\s+//; s/\s+$//;
+    next if m/^\#/; next unless m/\S/;
+    last if m/^\.$/;
+    m/^(.*\S)\s+([0-7]+)$/ or die;
+    ($of,$pe)=($1,oct $2);
+    $isdir= $of =~ s,/$,,;
+    ($isdir ? $dirperms{$of} : $fileperms{$of}) = $pe;
+}
+fin_prep();
+
+sub mkparents ($) {
+    my ($parent) = @_;
+    $parent =~ s,/[^/]+$,, or return;
+    ensuredir($parent);
+}
+
+sub maybe_chmod ($$$) {
+    my ($nowperms,$perms,$obj) = @_;
+    return if $nowperms==$perms;
+    if ($doing) {
+       chmod $perms, $home.$obj or die $!;
+    } else {
+       would($obj, sprintf 'chmod %04o -> %04o', $nowperms, $perms);
+    }
+}
+
+sub ensuredir ($) {
+    my ($dir) = @_;
+    mkparents($dir);
+    $perms= exists $dirperms{$dir} ? $dirperms{$dir} : 02777&~$umask;
+    if (stat $home.$dir) {
+       -d _ or die "$dir is not a directory!";
+       $nowperms= (stat _)[2] & 07777;
+       maybe_chmod($nowperms,$perms,$dir);
+    } else {
+       die $! unless $!==&ENOENT;
+       if ($doing) {
+           mkdir $home.$dir, $perms or die $!;
+       } else {
+           would($dir, sprintf 'mkdir %04o', $perms);
+       }
+    }
+}
+
+-d 'new' or mkdir 'new', 02700 or die $!;
+
+opendir D, "files" or die $!;
+while ($if=readdir D) {
+    next unless $if =~ m/^[:a-z0-9]/;
+    $of= $if; 
+    $of =~ s,\:,/,g; 
+    $of =~ s,^/,,;
+    $of =~ s,\\\;,:,g;
+    $of =~ s:\\([0-9a-f][0-9a-f]): sprintf '%c', hex $1 :ge;
+
+    $newf= 'new/'.$if;
+    mkparents($of);
+    defined($c= fork) or die $!;
+    if (!$c) {
+       unlink $newf;
+       open STDOUT, "> $newf" or die "$of $newf $!";
+       exec './gpt','config','files/'.$if; die $!;
+    }
+    $!=0; waitpid($c,0)==$c or die $!;
+    $? and die $?;
+
+    $perms= exists $fileperms{$of} ? $fileperms{$of} : 00666&~$umask;
+    chmod $perms, $newf or die $!;
+    
+    if (stat $home.$of) {
+       -f _ or die "$of is not a file!";
+       $nowperms= (stat _)[2] & 07777;
+       if (!$action) {
+           if ($nowperms != $perms) {
+               would($of, sprintf 'chmod %04o -> %04o', $nowperms, $perms);
+           }
+           system 'diff','-u',$home.$of,$newf;
+           $?==0 or $?==256 or die $?;
+       }
+    } else {
+       would($of, sprintf 'create %04o', $perms);
+    }
+    if ($action) {
+       rename $newf,$home.$of or die $!;
+    }
+
+    delete $fileperms{$of};
+}
+closedir D or die $!;
+
+die join(', ', keys %fileperms) if %fileperms;
+
+foreach $dir (keys %dirperms) {
+    ensuredir($dir);
+}
+
+sub would ($$) {
+    my ($obj,$what) = @_;
+    return if $would_done{$obj}++;
+    print STDOUT "*** $what $obj\n" or die $!;
+}
+
+close STDOUT or die $!;