6 defined($umask=umask) or die $!;
7 $home= $ENV{'HOME'}.'/';
9 while ($ARGV[0] =~ m/^-/) {
15 } elsif (s/^-u([0-7]{3})/-/) {
31 defined($c= open P, "-|") or die $!;
32 if (!$c) { exec './gpt','config',$inputfile; die $!; }
35 close P; die "$?" if $?;
40 $!=0; defined($_=<P>) or die $!;
41 chomp; s/^\s+//; s/\s+$//;
42 next if m/^\#/; next unless m/\S/;
44 if (m/(.*\S)\s+\-\>\s+(\S.*)/) {
46 } elsif (m/^(.*\S)\s+\-\-$/) {
48 } elsif (m/^(.*\S)\s+(\S+)$/) {
50 $isdir= $of =~ s,/$,,;
51 if ($pe =~ m/^[0-7]+$/) {
53 } elsif ($pe eq '+x') {
55 } elsif ($pe eq '/') {
60 ($isdir ? $dirperms{$of} : $fileperms{$of}) = $pe;
67 $parent =~ s,/[^/]+$,, or return;
71 sub maybe_chmod ($$$) {
72 my ($nowperms,$perms,$obj) = @_;
73 return if $nowperms==$perms;
75 chmod $perms, $home.$obj or die $!;
77 would($obj, sprintf 'chmod %04o -> %04o', $nowperms, $perms);
84 $perms= exists $dirperms{$dir} ? $dirperms{$dir} : 02777&~$umask;
85 if (stat $home.$dir) {
86 -d _ or die "$dir is not a directory!";
87 $nowperms= (stat _)[2] & 07777;
88 maybe_chmod($nowperms,$perms,$dir);
90 die $! unless $!==&ENOENT;
92 mkdir $home.$dir, $perms or die $!;
94 would($dir, sprintf 'mkdir %04o', $perms);
99 -d 'new' or mkdir 'new', 02700 or die $!;
104 defined($c= fork) or die $!;
107 open STDOUT, "> $newf" or die "$newf $!";
108 exec './gpt','config',$if; die $!;
110 $!=0; waitpid($c,0)==$c or die $!;
114 opendir D, "files" or die $!;
115 while ($if=readdir D) {
116 next unless $if =~ m/^[_a-z0-9\\]/;
117 next if $if =~ m/\~$/;
122 $of =~ s/\\([0-9a-f][0-9a-f]|_|\\)/
123 length $1 eq 1 ? $1 : sprintf '%c', hex $1
126 next if $exclude{$of};
130 prep_proc('files/'.$if,$newf);
132 $perms= exists $fileperms{$of} ? $fileperms{$of} : 00666&~$umask;
133 chmod $perms, $newf or die $!;
135 if (stat $home.$of) {
136 -f _ or die "$of is not a file!";
137 $nowperms= (stat _)[2] & 07777;
138 if ($nowperms != $perms) {
139 would($of, sprintf 'chmod %04o -> %04o', $nowperms, $perms);
141 system 'diff','-u',$home.$of,$newf;
142 $?==0 or $?==256 or die $?;
145 die unless $!==&ENOENT;
146 would($of, sprintf 'create %04o', $perms);
149 rename $newf,$home.$of or die $!;
152 delete $fileperms{$of};
154 closedir D or die $!;
156 die join(', ', keys %fileperms) if %fileperms;
158 foreach $link (keys %linktargs) {
160 $targ= $linktargs{$link};
161 if (lstat $home.$link) {
162 -l _ or die "$link is not a link!";
163 defined($rl= readlink $home.$link) or die $!;
165 die unless $!==&ENOENT;
169 would($link, "symlink $targ <-");
171 unlink $home.$link if defined $rl;
172 symlink $targ,$home.$link or die $!;
177 foreach $dir (keys %dirperms) {
182 my ($obj,$what) = @_;
183 return if $would_done{$obj}++;
184 print STDOUT "*** $what $obj\n" or die $!;
189 print STDOUT "=== $changes changes\n" or die $!;
191 print STDOUT "=== no changes\n" or die $!;
194 prep_proc('execute','new/,execute');
196 chmod 0700,'new/,execute' or die $!;
197 system 'new/,execute'; $? and die $?;
200 close STDOUT or die $!;