X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=ian-dotfiles.git;a=blobdiff_plain;f=process;h=513091890610b533e03631bee6c7198d31da57a1;hp=0a6dba60474ea47ac3a6bb2aa8f1497fa4a14f7b;hb=8fb78f857f03cbd75c56bf11c367c861dcc00e0b;hpb=db63b537826068dbcd6545609ed8d3038292a6c3 diff --git a/process b/process index 0a6dba6..5130918 100755 --- a/process +++ b/process @@ -6,7 +6,7 @@ $action=0; defined($umask=umask) or die $!; $home= $ENV{'HOME'}.'/'; -while (@ARGV =~ m/^-/) { +while ($ARGV[0] =~ m/^-/) { $_= shift(@ARGV); last if m/^--$/; while (m/^-./) { @@ -21,6 +21,7 @@ while (@ARGV =~ m/^-/) { } } } +die if @ARGV; stat $home or die $!; -d _ or die; @@ -40,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(); @@ -56,7 +69,7 @@ sub mkparents ($) { sub maybe_chmod ($$$) { my ($nowperms,$perms,$obj) = @_; return if $nowperms==$perms; - if ($doing) { + if ($action) { chmod $perms, $home.$obj or die $!; } else { would($obj, sprintf 'chmod %04o -> %04o', $nowperms, $perms); @@ -73,7 +86,7 @@ sub ensuredir ($) { maybe_chmod($nowperms,$perms,$dir); } else { die $! unless $!==&ENOENT; - if ($doing) { + if ($action) { mkdir $home.$dir, $perms or die $!; } else { would($dir, sprintf 'mkdir %04o', $perms); @@ -83,6 +96,19 @@ sub ensuredir ($) { -d 'new' or mkdir 'new', 02700 or die $!; +sub prep_proc ($$) { + my ($if,$newf) = @_; + my ($c); + defined($c= fork) or die $!; + if (!$c) { + unlink $newf; + open STDOUT, "> $newf" or die "$newf $!"; + exec './gpt','config',$if; die $!; + } + $!=0; waitpid($c,0)==$c or die $!; + $? and die $?; +} + opendir D, "files" or die $!; while ($if=readdir D) { next unless $if =~ m/^[_a-z0-9\\]/; @@ -94,16 +120,9 @@ while ($if=readdir D) { length $1 eq 1 ? $1 : 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 $?; + $newf= 'new/'.$if; + prep_proc('files/'.$if,$newf); $perms= exists $fileperms{$of} ? $fileperms{$of} : 00666&~$umask; chmod $perms, $newf or die $!; @@ -111,14 +130,14 @@ while ($if=readdir D) { 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 $?; + if ($nowperms != $perms) { + would($of, sprintf 'chmod %04o -> %04o', $nowperms, $perms); } + 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) { @@ -131,6 +150,24 @@ 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= ''; + } + if ($rl ne $targ) { + would($link, "symlink $targ <-"); + if ($action) { + symlink $targ,$home.$link or die $!; + } + } +} + foreach $dir (keys %dirperms) { ensuredir($dir); } @@ -139,6 +176,19 @@ sub would ($$) { my ($obj,$what) = @_; return if $would_done{$obj}++; print STDOUT "*** $what $obj\n" or die $!; + $changes++; +} + +if ($changes) { + print STDOUT "=== $changes changes\n" or die $!; +} else { + print STDOUT "=== no changes\n" or die $!; +} + +prep_proc('execute','new/,execute'); +if ($action) { + chmod 0700,'new/,execute' or die $!; + system 'new/,execute'; $? and die $?; } close STDOUT or die $!;