ikiwiki-update-wikilist: Add -r switch to remove. Default behavior is now always to add.
parent
4ef96e2d99
commit
bc3363beb7
|
@ -7,6 +7,8 @@ ikiwiki (2.60) UNRELEASED; urgency=low
|
||||||
* The way wrappers are defined in the setup file has changed. Old setup
|
* The way wrappers are defined in the setup file has changed. Old setup
|
||||||
files will continue to work, for now.
|
files will continue to work, for now.
|
||||||
* Version control backends promoted to first-class plugins.
|
* Version control backends promoted to first-class plugins.
|
||||||
|
* ikiwiki-update-wikilist: Add -r switch to remove. Default behavior is now
|
||||||
|
always to add.
|
||||||
|
|
||||||
-- Joey Hess <joeyh@debian.org> Mon, 21 Jul 2008 11:35:46 -0400
|
-- Joey Hess <joeyh@debian.org> Mon, 21 Jul 2008 11:35:46 -0400
|
||||||
|
|
||||||
|
|
|
@ -4,14 +4,16 @@ ikiwiki-update-wikilist - add or remove user from /etc/ikiwiki/wikilist
|
||||||
|
|
||||||
# SYNOPSIS
|
# SYNOPSIS
|
||||||
|
|
||||||
ikiwiki-update-wikilist
|
ikiwiki-update-wikilist [-r]
|
||||||
|
|
||||||
# DESCRIPTION
|
# DESCRIPTION
|
||||||
|
|
||||||
`ikiwiki-update-wikilist` is designed to be made suid root, but not installed
|
`ikiwiki-update-wikilist` is designed to be made suid root, but is not installed
|
||||||
suid by default. If made suid, it allows users to add or remove their names
|
suid by default. If made suid, it allows users to add or remove their names
|
||||||
from the `/etc/ikiwiki/wikilist` file. If a user's name is not in the file,
|
from the `/etc/ikiwiki/wikilist` file.
|
||||||
it will be added; if the name is already present, it will be removed.
|
|
||||||
|
By default, the user's name will be added.
|
||||||
|
The `-r` switch causes the user's name to be removed.
|
||||||
|
|
||||||
If your name is in `/etc/ikiwiki/wikilist`, the [[ikiwiki-mass-rebuild]](8)
|
If your name is in `/etc/ikiwiki/wikilist`, the [[ikiwiki-mass-rebuild]](8)
|
||||||
command will look for a ~/.ikiwiki/wikilist file, and rebuild the wikis listed
|
command will look for a ~/.ikiwiki/wikilist file, and rebuild the wikis listed
|
||||||
|
|
|
@ -5,6 +5,8 @@ use warnings;
|
||||||
use strict;
|
use strict;
|
||||||
use English;
|
use English;
|
||||||
|
|
||||||
|
my $remove=(@ARGV && $ARGV[0] eq '-r');
|
||||||
|
|
||||||
my $username=getpwuid($REAL_USER_ID);
|
my $username=getpwuid($REAL_USER_ID);
|
||||||
if (! defined $username || ! length $username) {
|
if (! defined $username || ! length $username) {
|
||||||
die "unable to determine user name for UID $REAL_USER_ID\n";
|
die "unable to determine user name for UID $REAL_USER_ID\n";
|
||||||
|
@ -15,7 +17,8 @@ if (! -e $wikilist) {
|
||||||
die "$wikilist does not exist\n";
|
die "$wikilist does not exist\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
my $removed=0;
|
my $changed=0;
|
||||||
|
my $seen=0;
|
||||||
my @lines;
|
my @lines;
|
||||||
open (my $list, "<$wikilist") || die "read $wikilist: $!";
|
open (my $list, "<$wikilist") || die "read $wikilist: $!";
|
||||||
while (<$list>) {
|
while (<$list>) {
|
||||||
|
@ -23,7 +26,10 @@ while (<$list>) {
|
||||||
if (/^\s*([^\s]+)\s*$/) {
|
if (/^\s*([^\s]+)\s*$/) {
|
||||||
my $user=$1;
|
my $user=$1;
|
||||||
if ($user eq $username) {
|
if ($user eq $username) {
|
||||||
$removed=1;
|
if (! $remove) {
|
||||||
|
$seen=1;
|
||||||
|
push @lines, $_;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
push @lines, $_;
|
push @lines, $_;
|
||||||
|
@ -33,16 +39,24 @@ while (<$list>) {
|
||||||
push @lines, $_;
|
push @lines, $_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
close $list || die "error reading $list: $!";
|
if (! $seen && ! $remove) {
|
||||||
open ($list, ">$wikilist") || die "write $wikilist: $!";
|
push @lines, $username;
|
||||||
|
$changed=1;
|
||||||
|
}
|
||||||
|
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) {
|
foreach (@lines) {
|
||||||
print $list "$_\n";
|
print $list "$_\n";
|
||||||
}
|
}
|
||||||
if ($removed) {
|
if ($remove) {
|
||||||
print "removed user $username from $wikilist\n";
|
print "ikiwiki-update-wikilist: removed user $username from $wikilist\n";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
print $list "$username\n";
|
print "ikiwiki-update-wikilist: added user $username to $wikilist\n";
|
||||||
print "added user $username to $wikilist\n";
|
}
|
||||||
|
close $list || die "ikiwiki-update-wikilist: error writing $wikilist: $!\n";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
print "ikiwiki-update-wikilist: no changes need to be made\n";
|
||||||
}
|
}
|
||||||
close $list || die "error writing $list: $!";
|
|
||||||
|
|
Loading…
Reference in New Issue