[LON-CAPA-cvs] cvs: loncom /build cpfiles.pl

www www at source.lon-capa.org
Thu Oct 20 14:54:41 EDT 2011

www		Thu Oct 20 18:54:41 2011 EDT

  Added files:                 
    /loncom/build	cpfiles.pl 
  Move author spaces to /home/httpd/html/priv/
  Needs to be run *by hand* during installation.

Index: loncom/build/cpfiles.pl
+++ loncom/build/cpfiles.pl
# Script to move author spaces from
# /home/author
# to
# /home/httpd/html/priv/domain/author
# Should not be run automatically, but manually as part of the installation
# Since this is going to be run during installation, we cannot rely on lonc/lond/lonnet,
# and need to collect information the pedestrian way
use strict;
use File::Copy;

print "\nScript to move author spaces\n";
print "-----------------------------\n\n";
print "If run without parameters, the script will just tell you what it *would* do\n";
print "and give you warnings regarding possible problems.\n\n";

my $parameter=shift;

my ($login,$pass,$uid,$gid) = getpwnam('www');

my $commit=($parameter=~/commit/);

if ($commit) {
   print "\n *** Really running this\n";
} else {
   print "\nJust running in exploratory mode.\n";
   print "Run with parameter 'commit' to actually move the author spaces, e.g.\n";
   print "cpfiles.pl commit\n\n";

if ($commit) {
   print "\nMaking /home/httpd/html/priv\n";

# Authors hosted on this server
my %domauthors=();

foreach my $domain_directory (</home/httpd/lonUsers/*>) {
   my ($domain) = ($domain_directory=~/\/([^\/]+)$/);
   print "Found domain: $domain\n";
   my $dom_target="/home/httpd/html/priv/$domain";
   if ($commit) {
      print "Making $dom_target\n";
   } else {
      print "Would make $dom_target\n";
   my @domauth=();
   foreach my $domain_author (</home/httpd/html/res/$domain/*>) {
      my ($author)=($domain_author=~/\/([^\/]+)$/);
   $domauthors{$domain}=join(',', at domauth);
   print "Authors in $domain: $domauthors{$domain}\n";

# Go over all directories in the /home-directory
foreach my $home_directory (</home/*>) {
# Extract the author name
   my ($author) = ($home_directory=~/\/([^\/]+)$/); 
# Does this have a public_html-directory?
   unless (-e "/home/$author/public_html") { next; }
   print "Found author: $author\n";
   my $domain='';
   foreach my $trydom (keys(%domauthors)) {
      foreach my $domauth (split(/\,/,$domauthors{$trydom})) {
         if ($author eq $domauth) {
            print "$author found in $domauth\n";
            if ($domain) {
               print "*** ERROR: $author found in $domain earlier\n";
               print "*** This could be a serious problem\n";
               print "Enter 1: use $domain\n";
               print "Enter 2: use $trydom\n";
               print "Enter 3: stop\n";
               print "Your input: ";
               my $choice=<STDIN>;
               if ($choice==3) { print "Stopped.\n"; exit; }
               if ($choice==2) { $domain=$trydom; }
            } else {
            print "Will use $domain for $author\n";
   if ($domain) {
      my $source_path="/home/$author/public_html";
      my $target_path="/home/httpd/html/priv/$domain/$author";
      if ($commit) {
         print "Moving $source_path to $target_path\n";
      } else {
         print "Would move $source_path to $target_path\n";
   } else {
      print "*** WARNING: $author has no domain. The author may not have published.\n";
print "\nDone.\n";

More information about the LON-CAPA-cvs mailing list