File:  [LON-CAPA] / doc / loncapafiles / updatequery.piml
Revision 1.22: download - view: text, annotated - select for diffs
Mon Dec 9 21:10:44 2002 UTC (21 years, 4 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- doing BUG#1034
- reversed order, now asks about cluster before asking about values
- grabs domain info from to be installed hosts.tab if it exists
- FIXME doesn't handle standalone properly yet

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

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