chiark / gitweb /
HOME/personal/crypto/scripts
[ian-dotfiles.git] / process
diff --git a/process b/process
index bf3295ddfff085cd645aabd1510bb664df558bc3..192d96461a78463c68941e1cf85fe0d1e2b07a72 100755 (executable)
--- a/process
+++ b/process
@@ -32,7 +32,7 @@ sub read_prep ($) {
     if (!$c) { exec './gpt','config',$inputfile; die $!; }
 }
 sub fin_prep () {
-    $!=0; close P; die "$! $?" if $! or $?;
+    close P; die "$?" if $?;
 }
 
 read_prep('perms');
@@ -41,10 +41,22 @@ for (;;) {
     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;
+    if (m/(.*\S)\s+\-\>\s+(\S.*)/) {
+       $linktargs{$1}= $2;
+    } elsif (m/^(.*\S)\s+(\S+)$/) {
+       ($of,$pe)=($1,$2);
+       $isdir= $of =~ s,/$,,;
+       if ($pe =~ m/^[0-7]+$/) {
+           $pe= oct $&;
+       } elsif ($pe eq '+x') {
+           $pe= 0777&~$umask;
+       } elsif ($pe eq '/') {
+           $pe= 02777&~$umask;
+       } else {
+           die "$pe ?";
+       }
+       ($isdir ? $dirperms{$of} : $fileperms{$of}) = $pe;
+    }
 }
 fin_prep();
 
@@ -121,12 +133,11 @@ while ($if=readdir D) {
        if ($nowperms != $perms) {
            would($of, sprintf 'chmod %04o -> %04o', $nowperms, $perms);
        }
-       if (!$action) {
-           system 'diff','-u',$home.$of,$newf;
-           $?==0 or $?==256 or die $?;
-           $changes++ if $?;
-       }
+       system 'diff','-u',$home.$of,$newf;
+       $?==0 or $?==256 or die $?;
+       $changes++ if $?;
     } else {
+       die unless $!==&ENOENT;
        would($of, sprintf 'create %04o', $perms);
     }
     if ($action) {
@@ -139,6 +150,25 @@ closedir D or die $!;
 
 die join(', ', keys %fileperms) if %fileperms;
 
+foreach $link (keys %linktargs) {
+    mkparents($link);
+    $targ= $linktargs{$link};
+    if (lstat $home.$link) {
+       -l _ or die "$link is not a link!";
+       defined($rl= readlink $home.$link) or die $!;
+    } else {
+       die unless $!==&ENOENT;
+       $rl= undef;
+    }
+    if ($rl ne $targ) {
+       would($link, "symlink $targ <-");
+       if ($action) {
+           unlink $home.$link if defined $rl;
+           symlink $targ,$home.$link or die $!;
+       }
+    }
+}
+
 foreach $dir (keys %dirperms) {
     ensuredir($dir);
 }