File:  [LON-CAPA] / doc / loncapafiles / updatequery.piml
Revision 1.23: download - view: text, annotated - select for diffs
Mon Dec 9 21:27:36 2002 UTC (21 years, 4 months ago) by albertel
Branches: MAIN
CVS tags: version_0_6_2, version_0_6, HEAD
- Finished off BUG#1034
- tries harder to locate an existing domain description (looks in starter hosts.tab and installed hosts.tab)
- standalone mode works

    1: <!-- updatequery.piml -->
    2: <!-- Scott Harrison -->
    3: 
    4: <!-- $Id: updatequery.piml,v 1.23 2002/12/09 21:27:36 albertel Exp $ -->
    5: 
    6: <!--
    7: 
    8: This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: 
   10: LON-CAPA is free software; you can redistribute it and/or modify
   11: it under the terms of the GNU General Public License as published by
   12: the Free Software Foundation; either version 2 of the License, or
   13: (at your option) any later version.
   14: 
   15: LON-CAPA is distributed in the hope that it will be useful,
   16: but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: GNU General Public License for more details.
   19: 
   20: You should have received a copy of the GNU General Public License
   21: along with LON-CAPA; if not, write to the Free Software
   22: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: 
   24: /home/httpd/html/adm/gpl.txt
   25: 
   26: http://www.lon-capa.org/
   27: 
   28: -->
   29: 
   30: <piml>
   31: <targetroot>/</targetroot>
   32: <files>
   33: <file>
   34: <target dist='default'>/</target>
   35: <perlscript mode='fg'>
   36: $|=1;
   37:   print(&lt;&lt;END);
   38: 
   39: 
   40: *********************************************
   41: *********************************************
   42: ****                                     ****
   43: **** LON-CAPA SYSTEM INFORMATION REQUEST ****
   44: ****                                     ****
   45: **** Please respond to the choices below ****
   46: ****                                     ****
   47: *********************************************
   48: *********************************************
   49: 
   50: END
   51: sleep(3);
   52: </perlscript>
   53: </file>
   54: <file>
   55: <target dist='default'>loncom/hosts.tab</target>
   56: <perlscript mode='fg'>
   57: unless (-l "<TARGET />") {
   58:   print(&lt;&lt;END);
   59: 
   60: ===============================================================================
   61: What hosts.tab would you like to have installed?
   62: (hosts.tab is a listing of all other internet machines
   63: that a server system considers to be valid server systems
   64: on the LON-CAPA network)
   65: 
   66: 1) PRODUCTION - you want to deliver courses today or sometime very soon
   67:                 on this machine
   68: 2) STAND-ALONE - you want this machine to run in 'stand-alone' mode and
   69:                  not be connected to other LON-CAPA machines for now
   70: 3) DEVELOPMENT - you want to play with or explore LON-CAPA
   71: 4) PRESERVE the existing hosts.tab (/home/httpd/lonTabs/hosts.tab)
   72: 
   73: END
   74: # Option number 26 will install rawhide_hosts.tab, but
   75: # the typical user does not want to be part of an intensive
   76: # machine test cluster.
   77: 
   78: # get input
   79: # if valid then process, otherwise loop
   80: $flag=0;
   81: while (!$flag) {
   82:   print "ENTER 1, 2, 3, or 4:\n";
   83:   my $choice=&lt;&gt;;
   84:   chomp($choice);
   85:   if ($choice==1) {
   86:     $lonCluster='production'; $flag=1;
   87:   }
   88:   elsif ($choice==2) {
   89:     $lonCluster='standalone'; $flag=1;
   90:   }
   91:   elsif ($choice==3) {
   92:     $lonCluster='development'; $flag=1;
   93:   }
   94:   elsif ($choice==4) {
   95:     $lonCluster='existing'; $flag=1;
   96:     if (-e '/home/httpd/lonTabs/hosts.tab') {
   97:       `cp /home/httpd/lonTabs/hosts.tab ../existing_hosts.tab`;
   98:     }
   99:     else {
  100:       print &lt;&lt;END;
  101: There is no existing /home/httpd/lonTabs/hosts.tab
  102: END
  103:       die('');
  104:     }
  105:   }
  106:   elsif ($choice==26) {
  107:     $lonCluster='rawhide'; $flag=1;
  108:   }
  109: }
  110: }
  111: </perlscript>
  112: </file>
  113: <file>
  114: <target dist='default'>/home/httpd/lonTabs/hosts.tab</target>
  115: <perlscript mode='fg'>
  116: $|=1;
  117: my $domainDescription;
  118: unless (-e "<TARGET />") {
  119:   print(&lt;&lt;END);
  120:            WELCOME TO LON-CAPA!
  121: 
  122: If you have questions, please visit http://install.lon-capa.org
  123: or contact sharrison\@mail.lon-capa.org.
  124: 
  125: ===============================================================================
  126: The following 4 values are needed to configure LON-CAPA:
  127: * Machine Role
  128: * LON-CAPA Domain Name
  129: * LON-CAPA Machine ID Name, and
  130: * System Administration E-mail Address.
  131: END
  132: 
  133: open(OUT,'&gt;/tmp/loncapa_updatequery.out');
  134: close(OUT);
  135: 
  136: # query for Machine Role
  137:   print(&lt;&lt;END);
  138: **** Machine Role ****
  139: Library server (recommended if first-time installation of LON-CAPA):
  140:    Servers that are repositories of authoritative educational resources.
  141:    These servers also provide the construction space by which instructors
  142:    assemble their classroom online material.
  143: Access server:
  144:    Servers that load-balance high-traffic delivery of educational resources
  145:    over the world-wide web.
  146: 1) Will this be a library server? (recommended if this is your first install)
  147: 2) Or, will this be an access server?
  148: END
  149: my $flag=0;
  150: my $r='';
  151: my $lonRole;
  152: while (!$flag) {
  153:   print "ENTER A CHOICE OF 1 or 2:\n";
  154:   my $choice=&lt;&gt;;
  155:   chomp($choice);
  156:   if ($choice==1) {
  157:     open(OUT,'&gt;&gt;/tmp/loncapa_updatequery.out');
  158:     print(OUT 'lonRole'."\t".'library'."\n");
  159:     close(OUT);
  160:     $lonRole='library';
  161:     $r='l';
  162:     $flag=1;
  163:   }
  164:   elsif ($choice==2) {
  165:     open(OUT,'&gt;&gt;/tmp/loncapa_updatequery.out');
  166:     print(OUT 'lonRole'."\t".'access'."\n");
  167:     close(OUT);
  168:     $lonRole='access';
  169:     $r='a';
  170:     $flag=2;
  171:   }
  172:   else {
  173: 
  174:   }
  175: }
  176: 
  177: # need to recommend a machine ID name (ipdomain.l.somenumber)
  178: my $hostname=`hostname`; chomp($hostname);
  179: my $ipdomain='';
  180: if ($hostname=~/([^\.]*)\.([^\.]*)$/) {
  181:   $ipdomain=$1;
  182: }
  183: 
  184:   print(&lt;&lt;END);
  185: 
  186: **** Domain ****
  187: [this does NOT need to correspond to internet address domains,
  188:  examples might be "msu" or "bionet" or "vermontcc"]
  189: END
  190: 
  191: # get domain name
  192: # accept if valid, if not valid, tell user and repeat
  193: $flag=0;
  194: my $lonDefDomain;
  195: while (!$flag) {
  196: if ($ipdomain) {
  197: print(&lt;&lt;END);
  198: ENTER LONCAPA DOMAIN [$ipdomain]:
  199: END
  200: }
  201: else {
  202:   print(&lt;&lt;END);
  203: ENTER LONCAPA DOMAIN:
  204: END
  205: }
  206:   my $choice=&lt;&gt;;
  207:   chomp($choice);
  208:   my $bad_domain_flag=0;
  209:   my @bad_domain_names=('raw','userfiles','priv','adm','uploaded');
  210:   foreach my $bad (@bad_domain_names) {
  211:     $bad_domain_flag=1 if $choice eq $bad;
  212:   }
  213:   if ($ipdomain and $choice=~/^\s*$/) {
  214:     $choice=$ipdomain;
  215:     open(OUT,'&gt;&gt;/tmp/loncapa_updatequery.out');
  216:     print(OUT 'lonDefDomain'."\t".$choice."\n");
  217:     close(OUT);
  218:     $lonDefDomain=$choice;
  219:     $flag=1;
  220:   }
  221:   elsif ($choice!~/\_/ and $choice=~/^\w+$/) {
  222:     open(OUT,'&gt;&gt;/tmp/loncapa_updatequery.out');
  223:     print(OUT 'lonDefDomain'."\t".$choice."\n");
  224:     close(OUT);
  225:     $lonDefDomain=$choice;
  226:     $r='l';
  227:     $flag=1;
  228:   }
  229:   elsif ($bad_domain_flag) {
  230:     print "Invalid input ('$choice' conflicts with LON-CAPA namespace).\n";
  231:     print "Please try something different than '$choice'\n";
  232:   }
  233:   else {
  234:     print "Invalid input (only alphanumeric characters supported).\n";
  235:   }
  236: }
  237: 
  238: 
  239: # get domain description
  240: # accept if valid, if not valid, tell user and repeat
  241: $flag=0;
  242: 
  243: while (!$flag) {
  244:   print(&lt;&lt;END);
  245: 
  246: **** Domain Description ****
  247: String describing the domain, to be shown to users.
  248: [Example, msu is Michigan State University]
  249: ENTER DOMAIN DESCRIPTION:
  250: END
  251: 
  252:   my $choice=&lt;&gt;;
  253:   chomp($choice);
  254:   if ($choice!~/:/) {
  255:     open(OUT,'&gt;&gt;/tmp/loncapa_updatequery.out');
  256:     print(OUT 'domainDescription'."\t".$choice."\n");
  257:     close(OUT);
  258:     $domainDescription=$choice;
  259:     $flag=1;
  260:   }
  261:   else {
  262:     print "Invalid input (no ':' allowed).\n";
  263:   }
  264: }
  265: 
  266: my $lonHostID;
  267: if ($lonDefDomain) {
  268:   $lonHostID=$lonDefDomain.$r.int(1+rand(9)); # should be probably also detect
  269:                                               # against the hosts.tab
  270: }
  271: 
  272:   print(&lt;&lt;END);
  273: 
  274: **** Machine ID Name ****
  275: [this does NOT need to correspond to internet address names;
  276:  this name MUST be unique to the whole LON-CAPA network;
  277:  we recommend that you use a name based off of your institution;
  278:  good examples: "msul1" or "bionetl1";
  279:  bad examples: "loncapabox" or "studentsinside"]
  280: END
  281: # get machine name
  282: # accept if valid, if not valid, tell user and repeat
  283: $flag=0;
  284: while (!$flag) {
  285: if ($ipdomain) {
  286: print(&lt;&lt;END);
  287: ENTER LONCAPA MACHINE ID [$lonHostID]:
  288: END
  289: }
  290: else {
  291:   print(&lt;&lt;END);
  292: ENTER LONCAPA MACHINE ID:
  293: END
  294: }
  295:   my $choice=&lt;&gt;;
  296:   chomp($choice);
  297:   if ($lonHostID and $choice=~/^\s*$/) {
  298:     $choice=$lonHostID;
  299:     open(OUT,'&gt;&gt;/tmp/loncapa_updatequery.out');
  300:     print(OUT 'lonHostID'."\t".$choice."\n");
  301:     close(OUT);
  302:     $lonHostID=$choice;
  303:     $flag=1;
  304:   }
  305:   elsif ($choice!~/\_/ and $choice=~/^\w+$/) {
  306:     open(OUT,'&gt;&gt;/tmp/loncapa_updatequery.out');
  307:     print(OUT 'lonHostID'."\t".$choice."\n");
  308:     close(OUT);
  309:     $lonHostID=$choice;
  310:     $flag=1;
  311:   }
  312:   else {
  313:     print "Invalid input (only alphanumeric characters supported).\n";
  314:   }
  315: }
  316: 
  317: # get e-mail address
  318: # accept if valid, if not valid, tell user and repeat
  319: $flag=0;
  320: my $lonAdmEMail;
  321: while (!$flag) {
  322:   print(&lt;&lt;END);
  323: 
  324: **** System Administrator's E-mail ****
  325: E-mail address of the person who will manage this machine
  326: [should be in the form somebody\@somewhere]
  327: ENTER E-MAIL ADDRESS:
  328: END
  329: 
  330:   my $choice=&lt;&gt;;
  331:   chomp($choice);
  332:   if ($choice=~/\@/) {
  333:     open(OUT,'&gt;&gt;/tmp/loncapa_updatequery.out');
  334:     print(OUT 'lonAdmEMail'."\t".$choice."\n");
  335:     close(OUT);
  336:     $lonAdmEMail=$choice;
  337:     $flag=1;
  338:   }
  339:   else {
  340:     print "Invalid input (this needs to look like an e-mail address!).\n";
  341:   }
  342: }
  343: 
  344: # update loncapa.conf
  345: my $confdir='/etc/httpd/conf/';
  346: #my $confdir='';
  347: my $filename='loncapa.conf';
  348: my %perlvar;
  349:     if (-e "$confdir$filename") {
  350: 	open(CONFIG,'&lt;'.$confdir.$filename) or die("Can't read $confdir$filename");
  351: 	while (my $configline=&lt;CONFIG&gt;) {
  352: 	    if ($configline =~ /^[^\#]*PerlSetVar/) {
  353: 		my ($unused,$varname,$varvalue)=split(/\s+/,$configline);
  354: 		chomp($varvalue);
  355: 		$perlvar{$varname}=$varvalue if $varvalue!~/^\{\[\[\[\[/;
  356: 	    }
  357: 	}
  358: 	close(CONFIG);
  359:     }
  360:     $perlvar{'lonHostID'}=$lonHostID;
  361:     $perlvar{'lonDefDomain'}=$lonDefDomain;
  362:     $perlvar{'lonAdmEMail'}=$lonAdmEMail;
  363:     $perlvar{'lonRole'}=$lonRole;
  364:     unless ($perlvar{'lonLoadLim'} and $perlvar{'lonLoadLim'}!~/\{\[\[\[\[/) {
  365:        $perlvar{'lonLoadLim'}='2.00';
  366:     }
  367:     unless ($perlvar{'lonExpire'} and $perlvar{'lonExpire'}!~/\{\[\[\[\[/) {
  368:        $perlvar{'lonExpire'}='86400';
  369:     }
  370:     unless ($perlvar{'lonReceipt'} and $perlvar{'lonReceipt'}!~/\{\[\[\[\[/) {
  371:        my $lonReceipt='';
  372:        srand(time ^ $$ ^ unpack "%L*", `ps axww | gzip`);
  373:        my @alnum=(0..9,a..z);
  374:        foreach my $i (1..20) {
  375: 	 $lonReceipt.=$alnum[int(rand(36))];
  376:        }
  377:        $perlvar{'lonReceipt'}=$lonReceipt;
  378:     }
  379:     open(OUT,"&gt;$confdir$filename") or
  380:       die("Cannot output to $confdir$filename\n");
  381:     foreach my $key (keys %perlvar) {
  382:       my $value=$perlvar{$key};
  383:       print(OUT &lt;&lt;END);
  384: PerlSetVar     $key      $value
  385: END
  386:     }
  387:     close(OUT);
  388: }
  389: </perlscript>
  390: </file>
  391: <file>
  392: <target dist='default'>/</target>
  393: <perlscript mode='fg'>
  394: # read values from loncapa.conf
  395: my $confdir='/etc/httpd/conf/';
  396: my $filename='loncapa.conf';
  397: my %perlvar;
  398:     if (-e "$confdir$filename") {
  399: 	open(CONFIG,'&lt;'.$confdir.$filename) or 
  400:           die("Can't read $confdir$filename");
  401: 	while (my $configline=&lt;CONFIG&gt;) {
  402: 	    if ($configline =~ /^[^\#]*PerlSetVar/) {
  403: 		my ($unused,$varname,$varvalue)=split(/\s+/,$configline);
  404: 		chomp($varvalue);
  405: 		$perlvar{$varname}=$varvalue;
  406: 	    }
  407: 	}
  408: 	close(CONFIG);
  409:     }
  410:     unless ($perlvar{'lonLoadLim'} and $perlvar{'lonLoadLim'}!~/\{\[\[\[\[/) {
  411:        $perlvar{'lonLoadLim'}='2.00';
  412:     }
  413:     unless ($perlvar{'lonExpire'} and $perlvar{'lonExpire'}!~/\{\[\[\[\[/) {
  414:        $perlvar{'lonExpire'}='86400';
  415:     }
  416:     unless ($perlvar{'lonReceipt'} and $perlvar{'lonReceipt'}!~/\{\[\[\[\[/) {
  417:        my $lonReceipt='';
  418:        srand(time ^ $$ ^ unpack "%L*", `ps axww | gzip`);
  419:        my @alnum=(0..9,a..z);
  420:        foreach my $i (1..20) {
  421: 	 $lonReceipt.=$alnum[int(rand(36))];
  422:        }
  423:        $perlvar{'lonReceipt'}=$lonReceipt;
  424:     }
  425: my %perlvarstatic;
  426:     if (-e "${confdir}loncapa_apache.conf") {
  427: 	open(CONFIG,'&lt;'.$confdir.'loncapa_apache.conf') or 
  428:           die("Can't read ${confdir}loncapa_apache.conf");
  429: 	while (my $configline=&lt;CONFIG&gt;) {
  430: 	    if ($configline =~ /^[^\#]*PerlSetVar/) {
  431: 		my ($unused,$varname,$varvalue)=split(/\s+/,$configline);
  432: 		chomp($varvalue);
  433: 		$perlvarstatic{$varname}=$varvalue;
  434: 	    }
  435: 	}
  436: 	close(CONFIG);
  437:     }
  438:     if (!$domainDescription && $lonCluster ne 'existing') {
  439:        open(IN,'&lt;../'.$lonCluster.'_hosts.tab');
  440:        while(&lt;IN&gt;) {
  441:           if (/^$perlvar{'lonHostID'}\:/) {
  442: 	     (undef,undef,undef,undef,undef,$domainDescription)=split(/:/,$_);
  443: 	     chomp($domainDescription);
  444:              last;
  445:           }
  446:        }
  447:        close(IN);
  448:     }
  449:     if (!$domainDescription) {
  450:        open(IN,'&lt;/home/httpd/lonTabs/hosts.tab');
  451:        while(&lt;IN&gt;) {
  452:           if (/^$perlvar{'lonHostID'}\:/) {
  453: 	     (undef,undef,undef,undef,undef,$domainDescription)=split(/:/,$_);
  454: 	     chomp($domainDescription);
  455:              last;
  456:           }
  457:        }
  458:        close(IN);
  459:     }
  460:    
  461: # implement editing logic below, interactively
  462: # update loncapa.conf until 8 is entered
  463: 
  464: $flag=0;
  465: 
  466: while (!$flag) {
  467:   print(&lt;&lt;END);
  468: 
  469: ===============================================================================
  470: This is now the current configuration of your machine.
  471: 1) Domain Name: $perlvar{'lonDefDomain'}
  472: 2) Domain Description: $domainDescription
  473: 3) Machine Name: $perlvar{'lonHostID'}
  474: 4) System Administrator's E-mail Address: $perlvar{'lonAdmEMail'}
  475: 5) Role: $perlvar{'lonRole'}
  476: 6) Cache Expiration Time: $perlvar{'lonExpire'}
  477: 7) Server Load: $perlvar{'lonLoadLim'}
  478: 8) Everything is correct up above
  479: END
  480: my $hbug=-1;
  481: my $dbug=-1;
  482: {
  483:   my $v=$perlvar{'lonHostID'};
  484:   $hbug=0;
  485:   $hbug=1 if $v=~/\W/;
  486:   $hbug=1 if $v=~/\_/;
  487: }
  488: {
  489:   my $v=$1;
  490:   $dbug=0;
  491:   $dbug=1 if $v=~/\W/;
  492:   $dbug=1 if $v=~/\_/;
  493: }
  494: 
  495: if ($hbug) {
  496:   print "**** ERROR **** ".
  497: 	"Invalid lonHostID (should only be letters and/or digits)\n";
  498: }
  499: if ($dbug) {
  500:   print "**** ERROR **** ".
  501: 	"Invalid lonDefDomain (should only be letters and/or digits)\n";
  502: }
  503: 
  504:   print(&lt;&lt;END);
  505: ENTER A CHOICE OF 1-7 TO CHANGE, otherwise ENTER 8:
  506: END
  507: my $choice=&lt;&gt;;
  508: chomp($choice);
  509:   if ($choice==1) {
  510:   print(&lt;&lt;END);
  511: 1) Domain Name: $perlvar{'lonDefDomain'}
  512: ENTER NEW VALUE (this is an internal value used to identify a group of
  513:                  LON-CAPA machines, it must be alphanumerical, we suggest
  514:                  using a part of your actual DNS domain. For example, for
  515:                  the machine loncapa.msu.edu, we set the Domain to msu):
  516: END
  517:     my $choice2=&lt;&gt;;
  518:     chomp($choice2);
  519:     $perlvar{'lonDefDomain'}=$choice2;
  520:   }
  521:   elsif ($choice==2) {
  522:   print(&lt;&lt;END);
  523: 2) Domain Description: $domainDescription
  524: ENTER NEW VALUE (this should be a string that describes your domain, spaces
  525:                  and punctuation are fine except for ':'):
  526: END
  527:     my $choice2=&lt;&gt;;
  528:     chomp($choice2);
  529:     $domainDescription=$choice2;
  530:   }
  531:   elsif ($choice==3) {
  532:   print(&lt;&lt;END);
  533: 3) Machine Name: $perlvar{'lonHostID'}
  534: ENTER NEW VALUE (this will be the name of the machine in the LON-CAPA network
  535:                  it cannot contain any of '_' '-' '.' or ':'. We suggest that
  536:                  if you are in the domain 'example' and are the first library
  537:                  server you enter 'examplel1') :
  538: END
  539:     my $choice2=&lt;&gt;;
  540:     chomp($choice2);
  541:     $perlvar{'lonHostID'}=$choice2;
  542:   }
  543:   elsif ($choice==4) {
  544:   print(&lt;&lt;END);
  545: 4) System Administrator's E-mail Address: $perlvar{'lonAdmEMail'}
  546: ENTER NEW VALUE:
  547: END
  548:     my $choice2=&lt;&gt;;
  549:     chomp($choice2);
  550:     $perlvar{'lonAdmEMail'}=$choice2;
  551:   }
  552:   elsif ($choice==5) {
  553:   print(&lt;&lt;END);
  554: 5) Role: $perlvar{'lonRole'}
  555: ENTER NEW VALUE (this should be either 'access' or 'library' 
  556:                  if in doubt select 'library'):
  557: END
  558:     my $choice2=&lt;&gt;;
  559:     chomp($choice2);
  560:     $perlvar{'lonRole'}=$choice2;
  561:   }
  562:   elsif ($choice==6) {
  563:   print(&lt;&lt;END);
  564: 6) Cache Expiration Time: $perlvar{'lonExpire'}
  565: ENTER NEW VALUE (in seconds, 86400 is a reasonable value):
  566: END
  567:     my $choice2=&lt;&gt;;
  568:     chomp($choice2);
  569:     $perlvar{'lonExpire'}=$choice2;
  570:   }
  571:   elsif ($choice==7) {
  572:   print(&lt;&lt;END);
  573: 7) Server Load: $perlvar{'lonLoadLim'}
  574: ENTER NEW VALUE:
  575: END
  576:     my $choice2=&lt;&gt;;
  577:     chomp($choice2);
  578:     $perlvar{'lonLoadLim'}=$choice2;
  579:   }
  580:   elsif ($choice==8) {
  581:     $flag=1;
  582:   }
  583:   else {
  584: 
  585:   }
  586: }
  587:     open(OUT,"&gt;$confdir$filename") or
  588:       die("Cannot output to $confdir$filename\n");
  589:     foreach my $key (keys %perlvar) {
  590:       my $value=$perlvar{$key};
  591:       print(OUT &lt;&lt;END) unless $perlvarstatic{$key};
  592: PerlSetVar     $key      $value
  593: END
  594:     }
  595:     close(OUT);
  596: </perlscript>
  597: </file>
  598: <file>
  599: <target dist='default'>loncom/hosts.tab</target>
  600: <perlscript mode='fg'>
  601: unless (-l "<TARGET />") {
  602:   my $hostname=`hostname`;chomp($hostname);
  603:   my $hostaddress=`hostname -i $hostname`;chomp($hostaddress);
  604:   $hostaddress=~s/\s//;
  605:   $date=`date -I`; chomp($date);
  606:   $lonHostID=$perlvar{'lonHostID'};
  607:   $lonHostID=~s/\W//g;
  608:   $lineexistflag=0;
  609:   $hostidexistflag=0;
  610:   $line2insert=&lt;&lt;END;
  611: $perlvar{'lonHostID'}:$perlvar{'lonDefDomain'}:$perlvar{'lonRole'}:$hostname:$hostaddress:$domainDescription
  612: END
  613:   if ($lonCluster eq 'standalone') {
  614:     open(OUT,'&gt;../'.$lonCluster.'_hosts.tab') or
  615:       die('file generation error');
  616:       print(OUT $line2insert);
  617:     close(OUT);
  618:   }
  619:   if ($flag==1) {
  620:     `rm -f ../hosts.tab`;
  621:     open(IN,'&lt;../'.$lonCluster.'_hosts.tab');
  622:     while(&lt;IN&gt;) {
  623:       if (/^$line2insert$/) {
  624:         $lineexistflag=1;
  625:       }
  626:       if (/^$lonHostID\:/) {
  627:         $hostidexistflag=1;
  628:       }
  629:     }
  630:     close(IN);
  631:     if ($hostidexistflag and !$lineexistflag) {
  632:       print &lt;&lt;END;
  633: WARNING: $lonHostID already exists inside
  634: loncapa/loncom/${lonCluster}_hosts.tab.  The entry inside
  635: ${lonCluster}_hosts.tab does not match your settings.
  636: The entry inside ${lonCluster}_hosts.tab is being replaced
  637: with your new values.
  638: END
  639:       `grep -v "$lonHostID:" ../${lonCluster}_hosts.tab &gt; ../new_${lonCluster}_hosts.tab`;
  640:        open(OUT,'&gt;&gt;../new_'.$lonCluster.'_hosts.tab') or
  641:          die("cannot open loncom/${lonCluster}_hosts.tab for output\n");
  642:          print(OUT $line2insert);
  643:        close(OUT);
  644:       `ln -s new_${lonCluster}_hosts.tab ../hosts.tab`;
  645:       # email appropriate message
  646:       system('ping -c 1 www.lon-capa.org > /dev/null || ping -c 1 www.msu.edu > /dev/null || ping -c 1 www.mit.edu > /dev/null');
  647:       `echo "REPLACE:$lonCluster:$lonHostID:$date:$line2insert" | mail -s "REPLACE:$lonCluster:$lonHostID:$date" installrecord\@mail.lon-capa.org` unless $?;
  648:     }
  649:     elsif ($hostidexistflag and $lineexistflag) {
  650:       print &lt;&lt;END;
  651: Entry exists in ${lonCluster}_hosts.tab.
  652: END
  653:       `ln -s ${lonCluster}_hosts.tab ../hosts.tab`;
  654:       # email appropriate message
  655:       `echo "STABLEUPDATE:$lonCluster:$lonHostID:$date:$line2insert" | mail -s "STABLEUPDATE:$lonCluster:$lonHostID:$date" installrecord\@mail.lon-capa.org`;
  656:     }
  657:     elsif (!$hostidexistflag and !$lineexistflag) {
  658:       print &lt;&lt;END;
  659: New entry for $lonCluster.
  660: END
  661:       `cat ../${lonCluster}_hosts.tab &gt; ../new_${lonCluster}_hosts.tab`;
  662:        open(OUT,'&gt;&gt;../new_'.$lonCluster.'_hosts.tab') or
  663:          die("cannot open loncom/new_${lonCluster}_hosts.tab for output\n");
  664:          print(OUT $line2insert);
  665:        close(OUT);
  666:       `ln -s new_${lonCluster}_hosts.tab ../hosts.tab`;
  667:       # email appropriate message
  668:       `echo "INSERT:$lonCluster:$lonHostID:$date:$line2insert" | mail -s "INSERT:$lonCluster:$lonHostID:$date" installrecord\@mail.lon-capa.org`;
  669:     }
  670:   }
  671: }
  672: </perlscript>
  673: </file>
  674: </files>
  675: </piml>

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>