1: <!-- updatequery.piml -->
2:
3: <!-- $Id: updatequery.piml,v 1.31 2004/06/01 15:55:00 albertel 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(<<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(<<END);
58:
59: ===============================================================================
60: Which cluster option would you like to have installed?
61: IMPORTANT: to take advantage of the cluster options 1) and 3),
62: you must contact lon-capa\@lon-capa.org.
63:
64: 1) PRODUCTION - you want to eventually connect this machine to the
65: LON-CAPA content sharing network. This setting is for
66: schools, colleges, and universities, that currently
67: are running - or in the future will run - courses
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 do software (not content!) development with
71: this workstation and eventually link it with the
72: workstations of other LON-CAPA software developers.
73: 4) PRESERVE the existing hosts.tab and domain.tab
74: (/home/httpd/lonTabs/hosts.tab and
75: /home/httpd/lonTabs/domain.tab)
76:
77: END
78: # Option number 26 will install rawhide_hosts.tab, but
79: # the typical user does not want to be part of an intensive
80: # machine test cluster.
81:
82: # get input
83: # if valid then process, otherwise loop
84: $flag=0;
85: while (!$flag) {
86: print "ENTER 1, 2, 3, or 4:\n";
87: my $choice=<>;
88: chomp($choice);
89: if ($choice==1) {
90: $lonCluster='production'; $flag=1;
91: }
92: elsif ($choice==2) {
93: $lonCluster='standalone'; $flag=1;
94: }
95: elsif ($choice==3) {
96: $lonCluster='development'; $flag=1;
97: }
98: elsif ($choice==4) {
99: $lonCluster='existing'; $flag=1;
100: if (-e '/home/httpd/lonTabs/hosts.tab') {
101: `cp /home/httpd/lonTabs/hosts.tab ../existing_hosts.tab`;
102: }
103: else {
104: print <<END;
105: There is no existing /home/httpd/lonTabs/hosts.tab
106: END
107: die('');
108: }
109: if (-e '/home/httpd/lonTabs/domain.tab') {
110: `cp /home/httpd/lonTabs/domain.tab ../existing_domain.tab`;
111: }
112: else {
113: print <<END;
114: There is no existing /home/httpd/lonTabs/domain.tab
115: END
116: die('');
117: }
118: }
119: elsif ($choice==26) {
120: $lonCluster='rawhide'; $flag=1;
121: }
122: }
123: }
124: </perlscript>
125: </file>
126: <file>
127: <target dist='default'>/home/httpd/lonTabs/hosts.tab</target>
128: <perlscript mode='fg'>
129: $|=1;
130: my $domainDescription;
131: my $domainTabExtras;
132: unless (-e "<TARGET />") {
133: print(<<END);
134: WELCOME TO LON-CAPA!
135:
136: If you have questions, please visit http://install.lon-capa.org
137: or contact sharrison\@mail.lon-capa.org.
138:
139: ===============================================================================
140: The following 4 values are needed to configure LON-CAPA:
141: * Machine Role
142: * LON-CAPA Domain Name
143: * LON-CAPA Machine ID Name, and
144: * System Administration E-mail Address.
145: END
146:
147: open(OUT,'>/tmp/loncapa_updatequery.out');
148: close(OUT);
149:
150: # query for Machine Role
151: print(<<END);
152: **** Machine Role ****
153: Library server (recommended if first-time installation of LON-CAPA):
154: Servers that are repositories of authoritative educational resources.
155: These servers also provide the construction space by which instructors
156: assemble their classroom online material.
157: Access server:
158: Servers that load-balance high-traffic delivery of educational resources
159: over the world-wide web.
160: 1) Will this be a library server? (recommended if this is your first install)
161: 2) Or, will this be an access server?
162: END
163: my $flag=0;
164: my $r='';
165: my $lonRole;
166: while (!$flag) {
167: print "ENTER A CHOICE OF 1 or 2:\n";
168: my $choice=<>;
169: chomp($choice);
170: if ($choice==1) {
171: open(OUT,'>>/tmp/loncapa_updatequery.out');
172: print(OUT 'lonRole'."\t".'library'."\n");
173: close(OUT);
174: $lonRole='library';
175: $r='l';
176: $flag=1;
177: }
178: elsif ($choice==2) {
179: open(OUT,'>>/tmp/loncapa_updatequery.out');
180: print(OUT 'lonRole'."\t".'access'."\n");
181: close(OUT);
182: $lonRole='access';
183: $r='a';
184: $flag=2;
185: }
186: else {
187:
188: }
189: }
190:
191: # need to recommend a machine ID name (ipdomain.l.somenumber)
192: my $hostname=`hostname`; chomp($hostname);
193: my $ipdomain='';
194: if ($hostname=~/([^\.]*)\.([^\.]*)$/) {
195: $ipdomain=$1;
196: }
197:
198: print(<<END);
199:
200: **** Domain ****
201: [this does NOT need to correspond to internet address domains,
202: examples might be "msu" or "bionet" or "vermontcc"]
203: END
204:
205: # get domain name
206: # accept if valid, if not valid, tell user and repeat
207: $flag=0;
208: my $lonDefDomain;
209: while (!$flag) {
210: if ($ipdomain) {
211: print(<<END);
212: ENTER LONCAPA DOMAIN [$ipdomain]:
213: END
214: }
215: else {
216: print(<<END);
217: ENTER LONCAPA DOMAIN:
218: END
219: }
220: my $choice=<>;
221: chomp($choice);
222: my $bad_domain_flag=0;
223: my @bad_domain_names=('raw','userfiles','priv','adm','uploaded');
224: foreach my $bad (@bad_domain_names) {
225: $bad_domain_flag=1 if $choice eq $bad;
226: }
227: if ($ipdomain and $choice=~/^\s*$/) {
228: $choice=$ipdomain;
229: open(OUT,'>>/tmp/loncapa_updatequery.out');
230: print(OUT 'lonDefDomain'."\t".$choice."\n");
231: close(OUT);
232: $lonDefDomain=$choice;
233: $flag=1;
234: }
235: elsif ($choice!~/\_/ and $choice=~/^\w+$/) {
236: open(OUT,'>>/tmp/loncapa_updatequery.out');
237: print(OUT 'lonDefDomain'."\t".$choice."\n");
238: close(OUT);
239: $lonDefDomain=$choice;
240: $r='l';
241: $flag=1;
242: }
243: elsif ($bad_domain_flag) {
244: print "Invalid input ('$choice' conflicts with LON-CAPA namespace).\n";
245: print "Please try something different than '$choice'\n";
246: }
247: else {
248: print "Invalid input (only alphanumeric characters supported).\n";
249: }
250: }
251:
252:
253: # get domain description
254: # accept if valid, if not valid, tell user and repeat
255: $flag=0;
256:
257: while (!$flag) {
258: print(<<END);
259:
260: **** Domain Description ****
261: String describing the domain, to be shown to users.
262: [Example, msu is Michigan State University]
263: ENTER DOMAIN DESCRIPTION:
264: END
265:
266: my $choice=<>;
267: chomp($choice);
268: if ($choice!~/:/) {
269: open(OUT,'>>/tmp/loncapa_updatequery.out');
270: print(OUT 'domainDescription'."\t".$choice."\n");
271: close(OUT);
272: $domainDescription=$choice;
273: $flag=1;
274: }
275: else {
276: print "Invalid input (no ':' allowed).\n";
277: }
278: }
279:
280: my $lonHostID;
281: if ($lonDefDomain) {
282: $lonHostID=$lonDefDomain.$r.int(1+rand(9)); # should be probably also detect
283: # against the hosts.tab
284: }
285:
286: print(<<END);
287:
288: **** Machine ID Name ****
289: [this does NOT need to correspond to internet address names;
290: this name MUST be unique to the whole LON-CAPA network;
291: we recommend that you use a name based off of your institution;
292: good examples: "msul1" or "bionetl1";
293: bad examples: "loncapabox" or "studentsinside"]
294: END
295: # get machine name
296: # accept if valid, if not valid, tell user and repeat
297: $flag=0;
298: while (!$flag) {
299: if ($ipdomain) {
300: print(<<END);
301: ENTER LONCAPA MACHINE ID [$lonHostID]:
302: END
303: }
304: else {
305: print(<<END);
306: ENTER LONCAPA MACHINE ID:
307: END
308: }
309: my $choice=<>;
310: chomp($choice);
311: if ($lonHostID and $choice=~/^\s*$/) {
312: $choice=$lonHostID;
313: open(OUT,'>>/tmp/loncapa_updatequery.out');
314: print(OUT 'lonHostID'."\t".$choice."\n");
315: close(OUT);
316: $lonHostID=$choice;
317: $flag=1;
318: }
319: elsif ($choice!~/\_/ and $choice=~/^\w+$/) {
320: open(OUT,'>>/tmp/loncapa_updatequery.out');
321: print(OUT 'lonHostID'."\t".$choice."\n");
322: close(OUT);
323: $lonHostID=$choice;
324: $flag=1;
325: }
326: else {
327: print "Invalid input (only alphanumeric characters supported).\n";
328: }
329: }
330:
331: # get e-mail address
332: # accept if valid, if not valid, tell user and repeat
333: $flag=0;
334: my $lonAdmEMail;
335: while (!$flag) {
336: print(<<END);
337:
338: **** System Administrator's E-mail ****
339: E-mail address of the person who will manage this machine
340: [should be in the form somebody\@somewhere]
341: ENTER E-MAIL ADDRESS:
342: END
343:
344: my $choice=<>;
345: chomp($choice);
346: if ($choice=~/\@/) {
347: open(OUT,'>>/tmp/loncapa_updatequery.out');
348: print(OUT 'lonAdmEMail'."\t".$choice."\n");
349: close(OUT);
350: $lonAdmEMail=$choice;
351: $flag=1;
352: }
353: else {
354: print "Invalid input (this needs to look like an e-mail address!).\n";
355: }
356: }
357:
358: # update loncapa.conf
359: my $confdir='/etc/httpd/conf/';
360: #my $confdir='';
361: my $filename='loncapa.conf';
362: my %perlvar;
363: if (-e "$confdir$filename") {
364: open(CONFIG,'<'.$confdir.$filename) or die("Can't read $confdir$filename");
365: while (my $configline=<CONFIG>) {
366: if ($configline =~ /^[^\#]*PerlSetVar/) {
367: my ($unused,$varname,$varvalue)=split(/\s+/,$configline);
368: chomp($varvalue);
369: $perlvar{$varname}=$varvalue if $varvalue!~/^\{\[\[\[\[/;
370: }
371: }
372: close(CONFIG);
373: }
374: $perlvar{'lonHostID'}=$lonHostID;
375: $perlvar{'lonDefDomain'}=$lonDefDomain;
376: $perlvar{'lonAdmEMail'}=$lonAdmEMail;
377: $perlvar{'lonRole'}=$lonRole;
378: unless ($perlvar{'lonLoadLim'} and $perlvar{'lonLoadLim'}!~/\{\[\[\[\[/) {
379: $perlvar{'lonLoadLim'}='2.00';
380: }
381: unless ($perlvar{'lonUserLoadLim'} and $perlvar{'lonUserLoadLim'}!~/\{\[\[\[\[/) {
382: $perlvar{'lonUserLoadLim'}='0';
383: }
384: unless ($perlvar{'lonExpire'} and $perlvar{'lonExpire'}!~/\{\[\[\[\[/) {
385: $perlvar{'lonExpire'}='86400';
386: }
387: unless ($perlvar{'lonReceipt'} and $perlvar{'lonReceipt'}!~/\{\[\[\[\[/) {
388: my $lonReceipt='';
389: srand(time ^ $$ ^ unpack "%L*", `ps axww | gzip`);
390: my @alnum=(0..9,a..z);
391: foreach my $i (1..20) {
392: $lonReceipt.=$alnum[int(rand(36))];
393: }
394: $perlvar{'lonReceipt'}=$lonReceipt;
395: }
396: open(OUT,">$confdir$filename") or
397: die("Cannot output to $confdir$filename\n");
398: foreach my $key (keys %perlvar) {
399: my $value=$perlvar{$key};
400: print(OUT <<END);
401: PerlSetVar $key $value
402: END
403: }
404: close(OUT);
405: }
406: </perlscript>
407: </file>
408: <file>
409: <target dist='default'>/</target>
410: <perlscript mode='fg'>
411: sub securesetting {
412: my (%perlvar)=@_;
413: my $securestatus='unknown';
414: my $securenum='';
415: if ( $perlvar{'loncAllowInsecure'}&& $perlvar{'londAllowInsecure'}) {
416: $securestatus='no'; $securenum='4';
417: } elsif ( $perlvar{'loncAllowInsecure'}&& !$perlvar{'londAllowInsecure'}) {
418: $securestatus='lond'; $securenum='3';
419: } elsif (!$perlvar{'loncAllowInsecure'}&& $perlvar{'londAllowInsecure'}) {
420: $securestatus='lonc'; $securenum='2';
421: } elsif (!$perlvar{'loncAllowInsecure'}&& !$perlvar{'londAllowInsecure'}) {
422: $securestatus='yes (lond and lonc)'; $securenum='1';
423: }
424: return ($securestatus,$securenum);
425: }
426: # read values from loncapa.conf
427: my $confdir='/etc/httpd/conf/';
428: my $filename='loncapa.conf';
429: my %perlvar;
430: my ($securestatus,$securenum);
431: if (-e "$confdir$filename") {
432: open(CONFIG,'<'.$confdir.$filename) or
433: die("Can't read $confdir$filename");
434: while (my $configline=<CONFIG>) {
435: if ($configline =~ /^[^\#]*PerlSetVar/) {
436: my ($unused,$varname,$varvalue)=split(/\s+/,$configline);
437: chomp($varvalue);
438: $perlvar{$varname}=$varvalue;
439: }
440: }
441: close(CONFIG);
442: }
443: unless ($perlvar{'lonLoadLim'} and $perlvar{'lonLoadLim'}!~/\{\[\[\[\[/) {
444: $perlvar{'lonLoadLim'}='2.00';
445: }
446: unless ($perlvar{'lonUserLoadLim'} and $perlvar{'lonUserLoadLim'}!~/\{\[\[\[\[/) {
447: $perlvar{'lonUserLoadLim'}='0';
448: }
449: unless ($perlvar{'lonExpire'} and $perlvar{'lonExpire'}!~/\{\[\[\[\[/) {
450: $perlvar{'lonExpire'}='86400';
451: }
452: unless ($perlvar{'londAllowInsecure'} and $perlvar{'londAllowInsecure'}!~/\{\[\[\[\[/) {
453: $perlvar{'londAllowInsecure'}='1';
454: }
455: unless ($perlvar{'loncAllowInsecure'} and $perlvar{'loncAllowInsecure'}!~/\{\[\[\[\[/) {
456: $perlvar{'loncAllowInsecure'}='1';
457: }
458: ($securestatus,$securenum)=&securesetting(%perlvar);
459: unless ($perlvar{'lonReceipt'} and $perlvar{'lonReceipt'}!~/\{\[\[\[\[/) {
460: my $lonReceipt='';
461: srand(time ^ $$ ^ unpack "%L*", `ps axww | gzip`);
462: my @alnum=(0..9,a..z);
463: foreach my $i (1..20) {
464: $lonReceipt.=$alnum[int(rand(36))];
465: }
466: $perlvar{'lonReceipt'}=$lonReceipt;
467: }
468: my %perlvarstatic;
469: if (-e "${confdir}loncapa_apache.conf") {
470: open(CONFIG,'<'.$confdir.'loncapa_apache.conf') or
471: die("Can't read ${confdir}loncapa_apache.conf");
472: while (my $configline=<CONFIG>) {
473: if ($configline =~ /^[^\#]*PerlSetVar/) {
474: my ($unused,$varname,$varvalue)=split(/\s+/,$configline);
475: chomp($varvalue);
476: $perlvarstatic{$varname}=$varvalue;
477: }
478: }
479: close(CONFIG);
480: }
481: if (!$domainDescription && $lonCluster ne 'existing') {
482: open(IN,'<../'.$lonCluster.'_domain.tab');
483: while(<IN>) {
484: if (/^$perlvar{'lonDefDomain'}\:/) {
485: (undef,$domainDescription,$domainTabExtras)=split(/:/,$_,3);
486: chomp($domainDescription);
487: chomp($domainTabExtras);
488: last;
489: }
490: }
491: close(IN);
492: }
493: if (!$domainDescription) {
494: open(IN,'</home/httpd/lonTabs/domain.tab');
495: while(<IN>) {
496: if (/^$perlvar{'lonDefDomain'}\:/) {
497: (undef,$domainDescription,$domainTabExtras)=split(/:/,$_,3);
498: chomp($domainDescription);
499: chomp($domainTabExtras);
500: last;
501: }
502: }
503: close(IN);
504: }
505:
506: # implement editing logic below, interactively
507: # update loncapa.conf until 8 is entered
508:
509: $flag=0;
510:
511: while (!$flag) {
512: print(<<END);
513:
514: ===============================================================================
515: This is now the current configuration of your machine.
516: 1) Domain Name: $perlvar{'lonDefDomain'}
517: 2) Domain Description: $domainDescription
518: 3) Machine Name: $perlvar{'lonHostID'}
519: 4) System Administrator's E-mail Address: $perlvar{'lonAdmEMail'}
520: 5) Role: $perlvar{'lonRole'}
521: 6) Cache Expiration Time: $perlvar{'lonExpire'}
522: 7) Server Load: $perlvar{'lonLoadLim'}
523: 8) User Load: $perlvar{'lonUserLoadLim'}
524: 9) Allow only secure connections: $securestatus
525: 10) Everything is correct up above
526: END
527: my $hbug=-1;
528: my $dbug=-1;
529: {
530: my $v=$perlvar{'lonHostID'};
531: $hbug=0;
532: $hbug=1 if $v=~/\W/;
533: $hbug=1 if $v=~/\_/;
534: }
535: {
536: my $v=$1;
537: $dbug=0;
538: $dbug=1 if $v=~/\W/;
539: $dbug=1 if $v=~/\_/;
540: }
541:
542: if ($hbug) {
543: print "**** ERROR **** ".
544: "Invalid lonHostID (should only be letters and/or digits)\n";
545: }
546: if ($dbug) {
547: print "**** ERROR **** ".
548: "Invalid lonDefDomain (should only be letters and/or digits)\n";
549: }
550:
551: print(<<END);
552: ENTER A CHOICE OF 1-9 TO CHANGE, otherwise ENTER 10:
553: END
554: my $choice=<>;
555: chomp($choice);
556: if ($choice==1) {
557: print(<<END);
558: 1) Domain Name: $perlvar{'lonDefDomain'}
559: ENTER NEW VALUE (this is an internal value used to identify a group of
560: LON-CAPA machines, it must be alphanumerical, we suggest
561: using a part of your actual DNS domain. For example, for
562: the machine loncapa.msu.edu, we set the Domain to msu):
563: END
564: my $choice2=<>;
565: chomp($choice2);
566: $perlvar{'lonDefDomain'}=$choice2;
567: }
568: elsif ($choice==2) {
569: print(<<END);
570: 2) Domain Description: $domainDescription
571: ENTER NEW VALUE (this should be a string that describes your domain, spaces
572: and punctuation are fine except for ':'):
573: END
574: my $choice2=<>;
575: chomp($choice2);
576: $domainDescription=$choice2;
577: }
578: elsif ($choice==3) {
579: print(<<END);
580: 3) Machine Name: $perlvar{'lonHostID'}
581: ENTER NEW VALUE (this will be the name of the machine in the LON-CAPA network
582: it cannot contain any of '_' '-' '.' or ':'. We suggest that
583: if you are in the domain 'example' and are the first library
584: server you enter 'examplel1') :
585: END
586: my $choice2=<>;
587: chomp($choice2);
588: $perlvar{'lonHostID'}=$choice2;
589: }
590: elsif ($choice==4) {
591: print(<<END);
592: 4) System Administrator's E-mail Address: $perlvar{'lonAdmEMail'}
593: ENTER NEW VALUE:
594: END
595: my $choice2=<>;
596: chomp($choice2);
597: $perlvar{'lonAdmEMail'}=$choice2;
598: }
599: elsif ($choice==5) {
600: print(<<END);
601: 5) Role: $perlvar{'lonRole'}
602: ENTER NEW VALUE (this should be either 'access' or 'library'
603: if in doubt select 'library'):
604: END
605: my $choice2=<>;
606: chomp($choice2);
607: $perlvar{'lonRole'}=$choice2;
608: }
609: elsif ($choice==6) {
610: print(<<END);
611: 6) Cache Expiration Time: $perlvar{'lonExpire'}
612: ENTER NEW VALUE (in seconds, 86400 is a reasonable value):
613: END
614: my $choice2=<>;
615: chomp($choice2);
616: $perlvar{'lonExpire'}=$choice2;
617: }
618: elsif ($choice==7) {
619: print(<<END);
620: 7) Server Load: $perlvar{'lonLoadLim'}
621: ENTER NEW VALUE:
622: END
623: my $choice2=<>;
624: chomp($choice2);
625: $perlvar{'lonLoadLim'}=$choice2;
626: }
627: elsif ($choice==8) {
628: print(<<END);
629: 8) User Load: $perlvar{'lonUserLoadLim'}
630: Numer of users that can login before machine is 'overloaded'
631: ENTER NEW VALUE (integer value, 0 means there is no limit):
632: END
633: my $choice2=<>;
634: chomp($choice2);
635: $perlvar{'lonUserLoadLim'}=$choice2;
636: }
637: elsif ($choice==9) {
638: print(<<END);
639: 9) Allow only secure connections: $securestatus
640: The Lon-CAPA communication daemons lonc and lond can be configured to
641: allow only secure connections by default.
642:
643: POSSIBLE CHOICES:
644: 1) allow only secure connections and don't connect to machines that
645: can not be connected to securely
646: 2) allow only secure connections but allow this machine to connect to
647: machines that don't support secure connections
648: 3) allow insecure connections to this machine but only allow connections
649: to machines that support secure connections
650: 4) allow insecure connections
651: ENTER NEW VALUE (currenly $securenum):
652: END
653: my $choice2=<>;
654: chomp($choice2);
655: if ($choice2 eq '1') {
656: $perlvar{'loncAllowInsecure'}=0;$perlvar{'londAllowInsecure'}=0;
657: } elsif ($choice2 eq '2') {
658: $perlvar{'loncAllowInsecure'}=0;$perlvar{'londAllowInsecure'}=1;
659: } elsif ($choice2 eq '3') {
660: $perlvar{'loncAllowInsecure'}=1;$perlvar{'londAllowInsecure'}=0;
661: } elsif ($choice2 eq '4') {
662: $perlvar{'loncAllowInsecure'}=1;$perlvar{'londAllowInsecure'}=1;
663: }
664: ($securestatus,$securenum)=&securesetting(%perlvar);
665: }
666: elsif ($choice==10) {
667: $flag=1;
668: }
669: else {
670:
671: }
672: }
673: open(OUT,">$confdir$filename") or
674: die("Cannot output to $confdir$filename\n");
675: foreach my $key (keys %perlvar) {
676: my $value=$perlvar{$key};
677: print(OUT <<END) unless $perlvarstatic{$key};
678: PerlSetVar $key $value
679: END
680: }
681: close(OUT);
682: </perlscript>
683: </file>
684: <file>
685: <target dist='default'>loncom/hosts.tab</target>
686: <perlscript mode='fg'>
687: unless (-l "<TARGET />") {
688: my $hostname=`hostname`;chomp($hostname);
689: my $hostaddress=`hostname -i $hostname`;chomp($hostaddress);
690: $hostaddress=~s/\s//;
691: $date=`date -I`; chomp($date);
692: $lonHostID=$perlvar{'lonHostID'};
693: $lonHostID=~s/\W//g;
694: $lineexistflag=0;
695: $hostidexistflag=0;
696: $line2insert=<<END;
697: $perlvar{'lonHostID'}:$perlvar{'lonDefDomain'}:$perlvar{'lonRole'}:$hostname:$hostaddress
698: END
699: $domaininsert="$perlvar{'lonDefDomain'}:$domainDescription:$domainTabExtras\n";
700: if ($lonCluster eq 'standalone') {
701: open(OUT,'>../'.$lonCluster.'_hosts.tab') or
702: die('file generation error');
703: print(OUT $line2insert);
704: close(OUT);
705: open(OUT,'>../'.$lonCluster.'_domain.tab') or
706: die('file generation error');
707: print(OUT $domaininsert);
708: close(OUT);
709: }
710: if ($flag==1) {
711: `rm -f ../hosts.tab`;
712: open(IN,'<../'.$lonCluster.'_hosts.tab');
713: while(<IN>) {
714: if (/^$line2insert$/) {
715: $lineexistflag=1;
716: }
717: if (/^$lonHostID\:/) {
718: $hostidexistflag=1;
719: }
720: }
721: close(IN);
722: if ($hostidexistflag and !$lineexistflag) {
723: print <<END;
724: WARNING: $lonHostID already exists inside
725: loncapa/loncom/${lonCluster}_hosts.tab. The entry inside
726: ${lonCluster}_hosts.tab does not match your settings.
727: The entry inside ${lonCluster}_hosts.tab is being replaced
728: with your new values.
729: END
730: `grep -v "$lonHostID:" ../${lonCluster}_hosts.tab > ../new_${lonCluster}_hosts.tab`;
731: open(OUT,'>>../new_'.$lonCluster.'_hosts.tab') or
732: die("cannot open loncom/${lonCluster}_hosts.tab for output\n");
733: print(OUT $line2insert);
734: close(OUT);
735: `ln -s new_${lonCluster}_hosts.tab ../hosts.tab`;
736: # email appropriate message
737: system('ping -c 1 -W 5 www.lon-capa.org > /dev/null || ping -c 1 -W 5 www.msu.edu > /dev/null || ping -c 1 -W 5 www.mit.edu > /dev/null');
738: `echo "REPLACE:$lonCluster:$lonHostID:$date:$line2insert" | mail -s "REPLACE:$lonCluster:$lonHostID:$date" installrecord\@mail.lon-capa.org` unless $?;
739: }
740: elsif ($hostidexistflag and $lineexistflag) {
741: print <<END;
742: Entry exists in ${lonCluster}_hosts.tab.
743: END
744: `ln -s ${lonCluster}_hosts.tab ../hosts.tab`;
745: # email appropriate message
746: `echo "STABLEUPDATE:$lonCluster:$lonHostID:$date:$line2insert" | mail -s "STABLEUPDATE:$lonCluster:$lonHostID:$date" installrecord\@mail.lon-capa.org`;
747: }
748: elsif (!$hostidexistflag and !$lineexistflag) {
749: print <<END;
750: New entry for $lonCluster.
751: END
752: `cat ../${lonCluster}_hosts.tab > ../new_${lonCluster}_hosts.tab`;
753: open(OUT,'>>../new_'.$lonCluster.'_hosts.tab') or
754: die("cannot open loncom/new_${lonCluster}_hosts.tab for output\n");
755: print(OUT $line2insert);
756: close(OUT);
757: `ln -s new_${lonCluster}_hosts.tab ../hosts.tab`;
758: # email appropriate message
759: `echo "INSERT:$lonCluster:$lonHostID:$date:$line2insert" | mail -s "INSERT:$lonCluster:$lonHostID:$date" installrecord\@mail.lon-capa.org`;
760: }
761: }
762: $lineexistflag=0;
763: if ($flag==1) {
764: `rm -f ../domain.tab`;
765: open(IN,'<../'.$lonCluster.'_domain.tab');
766: while(<IN>) {
767: if (/^$domaininsert$/) {
768: $lineexistflag=1;
769: }
770: if (/^$perlvar{'lonDefDomain'}\:/) {
771: $domainexistflag=1;
772: }
773: }
774: close(IN);
775: if ($domainexistflag and !$lineexistflag) {
776: print <<END;
777: WARNING: $perlvar{'lonDefDomain'} already exists inside
778: loncapa/loncom/${lonCluster}_domain.tab. The entry inside
779: ${lonCluster}_domain.tab does not match your settings.
780: The entry inside ${lonCluster}_domain.tab is being replaced
781: with your new values.
782: END
783: `grep -v "$perlvar{'lonDefDomain'}:" ../${lonCluster}_domain.tab > ../new_${lonCluster}_domain.tab`;
784: open(OUT,'>>../new_'.$lonCluster.'_domain.tab') or
785: die("cannot open loncom/${lonCluster}_domain.tab for output\n");
786: print(OUT $domaininsert);
787: close(OUT);
788: `ln -s new_${lonCluster}_domain.tab ../domain.tab`;
789: # email appropriate message
790: system('ping -c 1 -W 5 www.lon-capa.org > /dev/null || ping -c 1 -W 5 www.msu.edu > /dev/null || ping -c 1 -W 5 www.mit.edu > /dev/null');
791: `echo "REPLACEdom:$lonCluster:$lonHostID:$date:$domaninsert" | mail -s "REPLACEdom:$lonCluster:$lonHostID:$date" installrecord\@mail.lon-capa.org` unless $?;
792: }
793: elsif ($domainexistflag and $lineexistflag) {
794: print <<END;
795: Entry exists in ${lonCluster}_domain.tab.
796: END
797: `ln -s ${lonCluster}_domain.tab ../domain.tab`;
798: # email appropriate message
799: `echo "STABLEUPDATEdom:$lonCluster:$lonHostID:$date:$domaininsert" | mail -s "STABLEUPDATEdom:$lonCluster:$lonHostID:$date" installrecord\@mail.lon-capa.org`;
800: }
801: elsif (!$domainexistflag and !$lineexistflag) {
802: print <<END;
803: New entry for $lonCluster.
804: END
805: `cat ../${lonCluster}_domain.tab > ../new_${lonCluster}_domain.tab`;
806: open(OUT,'>>../new_'.$lonCluster.'_domain.tab') or
807: die("cannot open loncom/new_${lonCluster}_domain.tab for output\n");
808: print(OUT $domaininsert);
809: close(OUT);
810: `ln -s new_${lonCluster}_domain.tab ../domain.tab`;
811: # email appropriate message
812: `echo "INSERTdom:$lonCluster:$lonHostID:$date:$domaininsert" | mail -s "INSERTdom:$lonCluster:$lonHostID:$date" installrecord\@mail.lon-capa.org`;
813: }
814: }
815: }
816: </perlscript>
817: </file>
818: </files>
819: </piml>
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>