Mediawiki/OAI mirror/OAIRepository/install oai server.pl
From Bjoern Hassler
< Mediawiki | OAI mirror | OAIRepository
WARNING! This is very basic code, provided for illustration. DO NOT USE!!!!
#!/usr/bin/perl # Where is your mysql? If mysql isn't on your path, you can enter it here: $mysql = "mysql"; # The user for your mysql database: $mysqluser = "root"; # Choose a user name and password for the harvester: $oaiuser = "SomeUserName"; $oaipass = "SomePassword"; # Set both of these to 1 if you want a dry run: $domysql = 0; $fixmysql = 0; ($pwd = `pwd`) =~ s/\n//; if ($pwd !~ /extensions\/OAI$/) { die("You need to be in extensions/OAI directory. Go to extensions/ and run svn co http://svn.wikimedia.org/svnroot/mediawiki/trunk/extensions/OAI/ if you haven't got the code yet.\n"); }; system("mkdir","$pwd/logs") if !-e "$pwd/logs"; $ls = "../../LocalSettings.php"; @var = ("wgDBprefix","wgDBname","wgDBuser","wgDBpassword","wgEnableUploads"); open LS,"<$ls"; while (<LS>) { if (m/OAI repository for update server/) { $lsdone = 1; }; foreach $key (@var) { if (m/\$$key\s*=\s*\"?([^\"]+)\"?\s*\;/) { $var{$key} = $1; }; }; }; foreach $key (@var) { if (!defined $var{$key}) { die("Sorry, could not determine value of \$$key from LocalSettings.php\n"); }; }; foreach (keys %var) { print "$_ = $var{$_}\n"; }; if ($var{wgEnableUploads} ne "true") { print " Warning: You will not be able to mirror files. Set $wgEnableUploads = true in LocalSettings.php to enable this. "; }; if (!$lsdone) { open LS,">>$ls"; print LS " # OAI repository for update server \@include( \$IP.'/extensions/OAI/OAIRepo.php' ); # Authentication and audit turned off: // \$oaiAgentRegex = '/experimental/'; // \$oaiAuth = true; # broken... squid? php config? wtf // \$oaiAudit = true; \$oaiAuditDatabase = '$var{wgDBname}'; # Please change the log location to a secure location: \$wgDebugLogGroups['oai'] = '$pwd/logs/oai.log'; "; close LS; } else { print "LocalSettings.php has already been modified. Remove the bits to do with the OAI extension to modify again.\n"; }; @scripts = qw(update_table.sql oaiaudit_table.sql oaiharvest_table.sql oaiuser_table.sql); print "Enter your mysql password for user '$mysqluser' as needed!\n"; foreach (@scripts) { system "perl -i.bak -pe 's/\\/\\*\\\$wgDBprefix\\*\\//$var{wgDBprefix}/g' $_\n" if $fixmysql; system "$mysql $var{wgDBname} -u$mysqluser -p < $_" if $domysql; }; open FILE,">add_user.sql"; print FILE "INSERT INTO $var{wgDBprefix}oaiuser(ou_name, ou_password_hash) VALUES ('$oaiuser', md5('$oaipass') );\n"; close FILE; system "$mysql $var{wgDBname} -u$mysqluser -p < add_user.sql" if $domysql;