2007-09-06 02:32:11 +02:00
|
|
|
#!/usr/bin/perl -t
|
|
|
|
# Add a user to the system wide wikilist.
|
|
|
|
# This script can safely be made suid.
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
use English;
|
|
|
|
|
2008-07-27 06:02:04 +02:00
|
|
|
my $remove=(@ARGV && $ARGV[0] eq '-r');
|
|
|
|
|
2007-09-06 02:32:11 +02:00
|
|
|
my $username=getpwuid($REAL_USER_ID);
|
|
|
|
if (! defined $username || ! length $username) {
|
|
|
|
die "unable to determine user name for UID $REAL_USER_ID\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
my $wikilist="/etc/ikiwiki/wikilist";
|
|
|
|
if (! -e $wikilist) {
|
|
|
|
die "$wikilist does not exist\n";
|
|
|
|
}
|
|
|
|
|
2008-07-27 06:02:04 +02:00
|
|
|
my $changed=0;
|
|
|
|
my $seen=0;
|
2007-09-06 02:32:11 +02:00
|
|
|
my @lines;
|
|
|
|
open (my $list, "<$wikilist") || die "read $wikilist: $!";
|
|
|
|
while (<$list>) {
|
|
|
|
chomp;
|
|
|
|
if (/^\s*([^\s]+)\s*$/) {
|
|
|
|
my $user=$1;
|
|
|
|
if ($user eq $username) {
|
2008-07-27 06:02:04 +02:00
|
|
|
if (! $remove) {
|
|
|
|
$seen=1;
|
|
|
|
push @lines, $_;
|
|
|
|
}
|
2007-09-06 02:32:11 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
push @lines, $_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
push @lines, $_;
|
|
|
|
}
|
|
|
|
}
|
2008-07-27 06:02:04 +02:00
|
|
|
if (! $seen && ! $remove) {
|
|
|
|
push @lines, $username;
|
|
|
|
$changed=1;
|
2007-09-06 02:32:11 +02:00
|
|
|
}
|
2008-07-27 06:02:04 +02:00
|
|
|
if ($changed) {
|
|
|
|
close $list || die "ikiwiki-update-wikilist: error reading $list: $!\n";
|
|
|
|
open ($list, ">$wikilist") || die "ikiwiki-update-wikilist: error writing $wikilist: $!\n";
|
|
|
|
foreach (@lines) {
|
|
|
|
print $list "$_\n";
|
|
|
|
}
|
|
|
|
if ($remove) {
|
|
|
|
print "ikiwiki-update-wikilist: removed user $username from $wikilist\n";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
print "ikiwiki-update-wikilist: added user $username to $wikilist\n";
|
|
|
|
}
|
|
|
|
close $list || die "ikiwiki-update-wikilist: error writing $wikilist: $!\n";
|
2007-09-06 02:32:11 +02:00
|
|
|
}
|
|
|
|
else {
|
2008-07-27 06:02:04 +02:00
|
|
|
print "ikiwiki-update-wikilist: no changes need to be made\n";
|
2007-09-06 02:32:11 +02:00
|
|
|
}
|