~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to debian/moin-update-wikilist

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mfrom: (0.9.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080622211713-fpo2zrq3s5dfecxg
Tags: 1.7.0-3
Simplify /etc/moin/wikilist format: "USER URL" (drop unneeded middle
CONFIG_DIR that was wrongly advertised as DATA_DIR).  Make
moin-mass-migrate handle both formats and warn about deprecation of
the old one.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl -t
 
2
# Add a user to the system wide wikilist.
 
3
# This script can safely be made suid.
 
4
use warnings;
 
5
use strict;
 
6
use English;
 
7
 
 
8
my $username=getpwuid($REAL_USER_ID);
 
9
if (! defined $username || ! length $username) {
 
10
        die "unable to determine user name for UID $REAL_USER_ID\n";
 
11
}
 
12
 
 
13
my $wikilist="/etc/moin/wikilist";
 
14
if (! -e $wikilist) {
 
15
        die "$wikilist does not exist\n";
 
16
}
 
17
 
 
18
my $removed=0;
 
19
my @lines;
 
20
open (my $list, "<$wikilist") || die "read $wikilist: $!";
 
21
while (<$list>) {
 
22
        chomp;
 
23
        if (/^\s*([^\s]+)\s*$/) {
 
24
                my $user=$1;
 
25
                if ($user eq $username) {
 
26
                        $removed=1;             
 
27
                }
 
28
                else {
 
29
                        push @lines, $_;
 
30
                }
 
31
        }
 
32
        else {
 
33
                push @lines, $_;
 
34
        }
 
35
}
 
36
close $list || die "error reading $list: $!";
 
37
open ($list, ">$wikilist") || die "write $wikilist: $!";
 
38
foreach (@lines) {
 
39
        print $list "$_\n";
 
40
}
 
41
if ($removed) {
 
42
        print "removed user $username from $wikilist\n";
 
43
}
 
44
else {
 
45
        print $list "$username\n";
 
46
        print "added user $username to $wikilist\n";
 
47
}
 
48
close $list || die "error writing $list: $!";