diff options
author | joey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071> | 2007-09-06 00:32:11 +0000 |
---|---|---|
committer | joey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071> | 2007-09-06 00:32:11 +0000 |
commit | 926c04e844f231622cfe7d74701a878581125188 (patch) | |
tree | 47745aa67327868debf5fad8ebac4c5c6811e062 /ikiwiki-update-wikilist | |
parent | 8fd13334af6538ab65273a4a6adb5a8cb3faef17 (diff) |
commit.
* Add the ikiwiki-update-wikilist command.
Diffstat (limited to 'ikiwiki-update-wikilist')
-rwxr-xr-x | ikiwiki-update-wikilist | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/ikiwiki-update-wikilist b/ikiwiki-update-wikilist new file mode 100755 index 000000000..0f3f0bcc6 --- /dev/null +++ b/ikiwiki-update-wikilist @@ -0,0 +1,48 @@ +#!/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; + +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"; +} + +my $removed=0; +my @lines; +open (my $list, "<$wikilist") || die "read $wikilist: $!"; +while (<$list>) { + chomp; + if (/^\s*([^\s]+)\s*$/) { + my $user=$1; + if ($user eq $username) { + $removed=1; + } + else { + push @lines, $_; + } + } + else { + push @lines, $_; + } +} +close $list || die "error reading $list: $!"; +open ($list, ">$wikilist") || die "write $wikilist: $!"; +foreach (@lines) { + print $list "$_\n"; +} +if ($removed) { + print "removed user $username from $wikilist\n"; +} +else { + print $list "$username\n"; + print "added user $username to $wikilist\n"; +} +close $list || die "error writing $list: $!"; |