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

« back to all changes in this revision

Viewing changes to debian/moin-mass-migrate

  • 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
 
2
# based on ikiwiki-mass-rebuild, part of ikiwiki, written by Joey Hess
 
3
 
 
4
use warnings;
 
5
use strict;
 
6
 
 
7
sub supplemental_groups {
 
8
        my $user=shift;
 
9
 
 
10
        my @list;
 
11
        while (my @fields=getgrent()) {
 
12
                if (grep { $_ eq $user } split(' ', $fields[3])) {
 
13
                        push @list, $fields[2];
 
14
                }
 
15
        }
 
16
 
 
17
        return @list;
 
18
}
 
19
 
 
20
sub processline {
 
21
        my $user=shift;
 
22
        my $url=shift;
 
23
        
 
24
        if (! getpwnam("$user")) {
 
25
                print STDERR "warning: user $user does not exist\n";
 
26
                return
 
27
        }
 
28
        # TODO: add sanity check for $url
 
29
        print "Processing moin wiki at $url as user $user ...\n";
 
30
        # su is not used because it passes arguments through the shell,
 
31
        # which might not be safe.
 
32
        defined(my $pid = fork) or die "Can’t fork: $!";
 
33
        if (! $pid) {
 
34
                my ($uuid, $ugid) = (getpwnam($user))[2, 3];
 
35
                my $grouplist=join(" ", $ugid, $ugid, supplemental_groups($user));
 
36
                $)=$grouplist;
 
37
                if ($!) {
 
38
                        die "failed to set egid $grouplist: $!";
 
39
                }
 
40
                $(=$ugid;
 
41
                $<=$uuid;
 
42
                $>=$uuid;
 
43
                if ($< != $uuid || $> != $uuid || $( != $ugid) {
 
44
                        die "failed to drop permissions to $user";
 
45
                }
 
46
                %ENV=(
 
47
                        PATH => $ENV{PATH},
 
48
                        HOME => (getpwnam($user))[7],
 
49
                );
 
50
                exec("moin", "--wiki-url", $url, "migration", "data", @ARGV);
 
51
                die "failed to run moin: $!";
 
52
        }
 
53
        waitpid($pid,0);
 
54
        if ($?) {
 
55
                print STDERR "Processing moin wiki at $url as user $user failed with code $?\n";
 
56
        }
 
57
}
 
58
 
 
59
sub processlist {
 
60
        my $file=shift;
 
61
        my $forceuser=shift;
 
62
 
 
63
        my $list;
 
64
        open ($list, "<$file") || die "$file: $!";
 
65
        while (<$list>) {
 
66
                chomp;
 
67
                s/^\s+//;
 
68
                s/\s+$//;
 
69
                next if /^#/ || ! length;
 
70
 
 
71
                if (/^([^\s]+)\s+([^\s]+)$/) {
 
72
                        my $user=$1;
 
73
                        my $url=$2;
 
74
                        if (defined $forceuser && $forceuser ne $user) {
 
75
                                print STDERR "warning: in $file line $., attempt to set user to $user, but user forced to $forceuser. Skipping\n";
 
76
                        }
 
77
                        processline($user, $url);
 
78
                # We once supported a middle config_dir value...
 
79
                } elsif (/^([^\s]+)\s+([^\s]+)\s+([^\s]+)$/) {
 
80
                        my $user=$1;
 
81
                        my $url=$3;
 
82
                        print STDERR "\nWARNING: $file line $., deprecated 3-value format (not \"USER URL\"). Stripping middle value\n\n";
 
83
                        if (defined $forceuser && $forceuser ne $user) {
 
84
                                print STDERR "warning: in $file line $., attempt to set user to $user, but user forced to $forceuser. Skipping\n";
 
85
                        }
 
86
                        processline($user, $url);
 
87
                }
 
88
                elsif (/^([^\s]+)$/) {
 
89
                        my $user=$1;
 
90
                        my $home=(getpwnam($user))[7];
 
91
                        if (defined $home && -d $home) {
 
92
                                my $dotfile="$home/.moin/wikilist";
 
93
                                if (-e $dotfile) {
 
94
                                        processlist($dotfile, $user);
 
95
                                }
 
96
                        }
 
97
                }
 
98
        }
 
99
        close $list;
 
100
}
 
101
 
 
102
my $wikilist="/etc/moin/wikilist";
 
103
 
 
104
if (-e $wikilist) {
 
105
        processlist($wikilist);
 
106
}