summaryrefslogtreecommitdiff
path: root/localmoin-mass-migrate
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2008-04-23 09:01:01 +0000
committerJonas Smedegaard <dr@jones.dk>2008-04-23 09:01:01 +0000
commitacfeb3c3e7ce9fe2a25651e2a119bd55b47cdff3 (patch)
tree80e78dd50d619b4749e94d22a697d925747ec806 /localmoin-mass-migrate
parent8c9ecea6139667e5d9fc8c9c5a2b1720a1f9d9cb (diff)
New script to mass-upgrade moin.
Diffstat (limited to 'localmoin-mass-migrate')
-rwxr-xr-xlocalmoin-mass-migrate104
1 files changed, 104 insertions, 0 deletions
diff --git a/localmoin-mass-migrate b/localmoin-mass-migrate
new file mode 100755
index 0000000..51fed7b
--- /dev/null
+++ b/localmoin-mass-migrate
@@ -0,0 +1,104 @@
+#!/usr/bin/perl
+# based on ikiwiki-mass-rebuild, part of ikiwiki, written by Joey Hess
+
+use warnings;
+use strict;
+
+sub supplemental_groups {
+ my $user=shift;
+
+ my @list;
+ while (my @fields=getgrent()) {
+ if (grep { $_ eq $user } split(' ', $fields[3])) {
+ push @list, $fields[2];
+ }
+ }
+
+ return @list;
+}
+
+sub processline {
+ my $user=shift;
+ my $configdir=shift;
+ my $url=shift;
+
+ if (! getpwnam("$user")) {
+ print STDERR "warning: user $user does not exist\n";
+ return
+ }
+ if (! -d "$configdir") {
+ print STDERR "warning: $configdir does not exist, skipping\n";
+ return;
+ }
+ # TODO: add sanity check for $url
+ print "Processing $configdir for $url as user $user ...\n";
+ # su is not used because it passes arguments through the shell,
+ # which is not safe for untrusted configdir paths.
+ defined(my $pid = fork) or die "Can’t fork: $!";
+ if (! $pid) {
+ my ($uuid, $ugid) = (getpwnam($user))[2, 3];
+ my $grouplist=join(" ", $ugid, $ugid, supplemental_groups($user));
+ $)=$grouplist;
+ if ($!) {
+ die "failed to set egid $grouplist: $!";
+ }
+ $(=$ugid;
+ $<=$uuid;
+ $>=$uuid;
+ if ($< != $uuid || $> != $uuid || $( != $ugid) {
+ die "failed to drop permissions to $user";
+ }
+ %ENV=(
+ PATH => $ENV{PATH},
+ HOME => (getpwnam($user))[7],
+ );
+ exec("moin", "--config-dir", $configdir, "--wiki-url", $url, "migration", "data", @ARGV);
+ die "failed to run moin: $!";
+ }
+ waitpid($pid,0);
+ if ($?) {
+ print STDERR "Processing $configdir for $url as user $user failed with code $?\n";
+ }
+}
+
+sub processlist {
+ my $file=shift;
+ my $forceuser=shift;
+
+ my $list;
+ open ($list, "<$file") || die "$file: $!";
+ while (<$list>) {
+ chomp;
+ s/^\s+//;
+ s/\s+$//;
+ next if /^#/ || ! length;
+
+ if (/^([^\s]+)\s+([^\s]+)\s+([^\s]+)$/) {
+ my $user=$1;
+ my $configdir=$2;
+ my $url=$3;
+ if (defined $forceuser && $forceuser ne $user) {
+ print STDERR "warning: in $file line $., attempt to set user to $user, but user forced to $forceuser. Skipping\n";
+ }
+ processline($user, $configdir, $url);
+ }
+ elsif (/^([^\s]+)$/) {
+ my $user=$1;
+ my $home=(getpwnam($user))[7];
+ if (defined $home && -d $home) {
+ my $dotfile="$home/.moin/wikilist";
+ if (-e $dotfile) {
+ processlist($dotfile, $user);
+ }
+ }
+ }
+ }
+ close $list;
+}
+
+my $wikilist="/etc/moin/wikilist";
+
+if (-e $wikilist) {
+ processlist($wikilist);
+}
+