]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - ikiwiki-mass-rebuild
improve error message when postsignin is not set
[git.ikiwiki.info.git] / ikiwiki-mass-rebuild
1 #!/usr/bin/perl
2 no lib '.';
3 use warnings;
4 use strict;
6 my $etcfile="/etc/ikiwiki/wikilist";
8 sub root {
9         $> == 0;
10 }
12 sub username {
13         (getpwuid($>))[0];
14 }
16 sub processline {
17         my $setup=shift;
18         
19         if (! -f "$setup") {
20                 print STDERR "warning: $setup does not exist, skipping\n";
21                 return;
22         }
23         print "Processing $setup as user ".username()." ...\n";
24         my $ret=system("ikiwiki", "--setup", $setup, @ARGV);
25         if ($ret != 0) {
26                 print STDERR "warning: processing $setup failed with code $ret\n";
27         }
28 }
30 my %users;
31 sub processuser {
32         my $user=shift;
33         return if $user=~/^-/ || $users{$user};
34         $users{$user}=1;
35         my $ret=system("su", $user, "-s", "/bin/sh", "-c", "--", "$0 --nonglobal @ARGV");
36         if ($ret != 0) {
37                 print STDERR "warning: processing for $user failed with code $ret\n";
38         }
39 }
41 sub processlist {
42         my $file=shift;
44         return unless -e $file;
46         my $list;
47         open ($list, "<$file") || die "$file: $!";
48         while (<$list>) {
49                 chomp;
50                 s/^\s+//;
51                 s/\s+$//;
52                 next if /^#/ || ! length;
53                 if (/^([-\w]+)\s+([^\s]+)$/) {
54                         my $user=$1;
55                         my $setup=$2;
56                         if (root()) {
57                                 processuser($user);
58                         }
59                         else {
60                                 if (username() eq $user) {
61                                         processline($setup);
62                                 }
63                         }
64                 }
65                 elsif (/^([-\w]+)$/) {
66                         my $user=$1;
67                         if (root()) {
68                                 processuser($user);
69                         }
70                         else {
71                                 my $home=(getpwnam($user))[7];
72                                 if (defined $home && -d $home) {
73                                         my $dotfile="$home/.ikiwiki/wikilist";
74                                         processlist($dotfile);
75                                 }
76                         }
77                 }
78         }
79         close $list;
80 }
82 if (@ARGV && $ARGV[0] eq "--nonglobal") {
83         shift;
84         # avoid recursively processing if the wikilist file has a root
85         # user in it
86         if (root()) {
87                 exit 1;
88         }
89 }
91 processlist($etcfile);