2006-11-28 06:46:13 +01:00
|
|
|
#!/usr/bin/perl
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
2006-05-05 22:48:20 +02:00
|
|
|
|
2011-06-08 23:33:15 +02:00
|
|
|
my $etcfile="/etc/ikiwiki/wikilist";
|
2007-11-14 15:27:11 +01:00
|
|
|
|
2011-06-08 23:33:15 +02:00
|
|
|
sub root {
|
|
|
|
$> == 0;
|
2007-11-14 15:27:11 +01:00
|
|
|
}
|
|
|
|
|
2011-06-08 23:33:15 +02:00
|
|
|
sub username {
|
|
|
|
(getpwuid($>))[0];
|
2008-06-13 19:05:44 +02:00
|
|
|
}
|
|
|
|
|
2006-11-28 06:46:13 +01:00
|
|
|
sub processline {
|
|
|
|
my $setup=shift;
|
|
|
|
|
|
|
|
if (! -f "$setup") {
|
|
|
|
print STDERR "warning: $setup does not exist, skipping\n";
|
|
|
|
return;
|
|
|
|
}
|
2011-06-08 23:33:15 +02:00
|
|
|
print "Processing $setup as user ".username()." ...\n";
|
2015-03-01 17:14:32 +01:00
|
|
|
my $ret=system("ikiwiki", "--setup", $setup, @ARGV);
|
2011-06-08 23:33:15 +02:00
|
|
|
if ($ret != 0) {
|
|
|
|
print STDERR "warning: processing $setup failed with code $ret\n";
|
2006-11-28 06:46:13 +01:00
|
|
|
}
|
2011-06-08 23:33:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
my %users;
|
|
|
|
sub processuser {
|
|
|
|
my $user=shift;
|
2011-08-21 23:36:29 +02:00
|
|
|
return if $user=~/^-/ || $users{$user};
|
2011-06-08 23:33:15 +02:00
|
|
|
$users{$user}=1;
|
|
|
|
my $ret=system("su", $user, "-s", "/bin/sh", "-c", "--", "$0 --nonglobal @ARGV");
|
|
|
|
if ($ret != 0) {
|
|
|
|
print STDERR "warning: processing for $user failed with code $ret\n";
|
2006-11-28 06:46:13 +01:00
|
|
|
}
|
|
|
|
}
|
2006-05-27 21:04:46 +02:00
|
|
|
|
2006-11-28 06:46:13 +01:00
|
|
|
sub processlist {
|
|
|
|
my $file=shift;
|
2011-06-08 23:33:15 +02:00
|
|
|
|
|
|
|
return unless -e $file;
|
2006-05-05 22:48:20 +02:00
|
|
|
|
2006-11-28 06:46:13 +01:00
|
|
|
my $list;
|
|
|
|
open ($list, "<$file") || die "$file: $!";
|
|
|
|
while (<$list>) {
|
|
|
|
chomp;
|
|
|
|
s/^\s+//;
|
|
|
|
s/\s+$//;
|
|
|
|
next if /^#/ || ! length;
|
2011-06-08 23:33:15 +02:00
|
|
|
if (/^([-\w]+)\s+([^\s]+)$/) {
|
2006-11-28 06:46:13 +01:00
|
|
|
my $user=$1;
|
|
|
|
my $setup=$2;
|
2011-06-08 23:33:15 +02:00
|
|
|
if (root()) {
|
|
|
|
processuser($user);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (username() eq $user) {
|
|
|
|
processline($setup);
|
|
|
|
}
|
2006-11-28 06:46:13 +01:00
|
|
|
}
|
|
|
|
}
|
2011-06-08 23:33:15 +02:00
|
|
|
elsif (/^([-\w]+)$/) {
|
2006-11-28 06:46:13 +01:00
|
|
|
my $user=$1;
|
2011-06-08 23:33:15 +02:00
|
|
|
if (root()) {
|
|
|
|
processuser($user);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
my $home=(getpwnam($user))[7];
|
|
|
|
if (defined $home && -d $home) {
|
|
|
|
my $dotfile="$home/.ikiwiki/wikilist";
|
|
|
|
processlist($dotfile);
|
2006-11-28 06:46:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close $list;
|
|
|
|
}
|
|
|
|
|
2011-06-08 23:33:15 +02:00
|
|
|
if (@ARGV && $ARGV[0] eq "--nonglobal") {
|
|
|
|
shift;
|
|
|
|
# avoid recursively processing if the wikilist file has a root
|
|
|
|
# user in it
|
|
|
|
if (root()) {
|
|
|
|
exit 1;
|
|
|
|
}
|
2006-05-05 22:48:20 +02:00
|
|
|
}
|
|
|
|
|
2011-06-08 23:33:15 +02:00
|
|
|
processlist($etcfile);
|