File:  [LON-CAPA] / doc / loncapafiles / updatequery.piml
Revision 1.24: download - view: text, annotated - select for diffs
Mon Feb 3 18:03:51 2003 UTC (21 years, 4 months ago) by harris41
Branches: MAIN
CVS tags: HEAD
best wishes to all.

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

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