summaryrefslogtreecommitdiff
path: root/ikiwiki-update-wikilist
diff options
context:
space:
mode:
authorJoey Hess <joey@kodama.kitenet.net>2008-07-27 00:02:04 -0400
committerJoey Hess <joey@kodama.kitenet.net>2008-07-27 00:02:04 -0400
commitbc3363beb767a82e3bdde2d038e7b678bd35f193 (patch)
tree8e3c5cd08dac5029a9546d0f8acbda8dbd7fe26a /ikiwiki-update-wikilist
parent4ef96e2d9994c407f0f2f46301eb91fab6b48a37 (diff)
ikiwiki-update-wikilist: Add -r switch to remove. Default behavior is now always to add.
Diffstat (limited to 'ikiwiki-update-wikilist')
-rwxr-xr-xikiwiki-update-wikilist36
1 files changed, 25 insertions, 11 deletions
diff --git a/ikiwiki-update-wikilist b/ikiwiki-update-wikilist
index 0f3f0bcc6..0b52543cd 100755
--- a/ikiwiki-update-wikilist
+++ b/ikiwiki-update-wikilist
@@ -5,6 +5,8 @@ use warnings;
use strict;
use English;
+my $remove=(@ARGV && $ARGV[0] eq '-r');
+
my $username=getpwuid($REAL_USER_ID);
if (! defined $username || ! length $username) {
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";
}
-my $removed=0;
+my $changed=0;
+my $seen=0;
my @lines;
open (my $list, "<$wikilist") || die "read $wikilist: $!";
while (<$list>) {
@@ -23,7 +26,10 @@ while (<$list>) {
if (/^\s*([^\s]+)\s*$/) {
my $user=$1;
if ($user eq $username) {
- $removed=1;
+ if (! $remove) {
+ $seen=1;
+ push @lines, $_;
+ }
}
else {
push @lines, $_;
@@ -33,16 +39,24 @@ while (<$list>) {
push @lines, $_;
}
}
-close $list || die "error reading $list: $!";
-open ($list, ">$wikilist") || die "write $wikilist: $!";
-foreach (@lines) {
- print $list "$_\n";
+if (! $seen && ! $remove) {
+ push @lines, $username;
+ $changed=1;
}
-if ($removed) {
- print "removed user $username from $wikilist\n";
+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";
}
else {
- print $list "$username\n";
- print "added user $username to $wikilist\n";
+ print "ikiwiki-update-wikilist: no changes need to be made\n";
}
-close $list || die "error writing $list: $!";