1: <!-- updatequery.piml -->
2: <!-- Scott Harrison -->
3:
4: <!-- $Id: updatequery.piml,v 1.16 2002/06/12 17:07:55 harris41 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(<<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'>/home/httpd/lonTabs/hosts.tab</target>
56: <perlscript mode='fg'>
57: $|=1;
58: unless (-e "<TARGET />") {
59: print(<<END);
60: WELCOME TO LON-CAPA!
61:
62: If you have questions, please visit http://install.lon-capa.org
63: or contact sharrison\@mail.lon-capa.org.
64:
65: ===============================================================================
66: The following 4 values are needed to configure LON-CAPA:
67: * Machine Role
68: * LON-CAPA Domain Name
69: * LON-CAPA Machine ID Name, and
70: * System Administration E-mail Address.
71: END
72:
73: open(OUT,'>/tmp/loncapa_updatequery.out');
74: close(OUT);
75:
76: # query for Machine Role
77: print(<<END);
78: **** Machine Role ****
79: Library server (recommended if first-time installation of LON-CAPA):
80: Servers that are repositories of authoritative educational resources.
81: These servers also provide the construction space by which instructors
82: assemble their classroom online material.
83: Access server:
84: Servers that load-balance high-traffic delivery of educational resources
85: over the world-wide web.
86: 1) Will this be a library server? (recommended if this is your first install)
87: 2) Or, will this be an access server?
88: END
89: my $flag=0;
90: my $r='';
91: my $lonRole;
92: while (!$flag) {
93: print "ENTER A CHOICE OF 1 or 2:\n";
94: my $choice=<>;
95: chomp($choice);
96: if ($choice==1) {
97: open(OUT,'>>/tmp/loncapa_updatequery.out');
98: print(OUT 'lonRole'."\t".'library'."\n");
99: close(OUT);
100: $lonRole='library';
101: $r='l';
102: $flag=1;
103: }
104: elsif ($choice==2) {
105: open(OUT,'>>/tmp/loncapa_updatequery.out');
106: print(OUT 'lonRole'."\t".'access'."\n");
107: close(OUT);
108: $lonRole='access';
109: $r='a';
110: $flag=2;
111: }
112: else {
113:
114: }
115: }
116:
117: # need to recommend a machine ID name (ipdomain.l.somenumber)
118: my $hostname=`hostname`; chomp($hostname);
119: my $ipdomain='';
120: if ($hostname=~/([^\.]*)\.([^\.]*)$/) {
121: $ipdomain=$1;
122: }
123:
124: print(<<END);
125:
126: **** Domain ****
127: [this does NOT need to correspond to internet address domains,
128: examples might be "msu" or "bionet" or "vermontcc"]
129: END
130:
131: # get domain name
132: # accept if valid, if not valid, tell user and repeat
133: $flag=0;
134: my $lonDefDomain;
135: while (!$flag) {
136: if ($ipdomain) {
137: print(<<END);
138: ENTER LONCAPA DOMAIN [$ipdomain]:
139: END
140: }
141: else {
142: print(<<END);
143: ENTER LONCAPA DOMAIN:
144: END
145: }
146: my $choice=<>;
147: chomp($choice);
148: if ($ipdomain and $choice=~/^\s*$/) {
149: $choice=$ipdomain;
150: open(OUT,'>>/tmp/loncapa_updatequery.out');
151: print(OUT 'lonDefDomain'."\t".$choice."\n");
152: close(OUT);
153: $lonDefDomain=$choice;
154: $flag=1;
155: }
156: elsif ($choice!~/\_/ and $choice=~/^\w+$/) {
157: open(OUT,'>>/tmp/loncapa_updatequery.out');
158: print(OUT 'lonDefDomain'."\t".$choice."\n");
159: close(OUT);
160: $lonDefDomain=$choice;
161: $r='l';
162: $flag=1;
163: }
164: else {
165: print "Invalid input (only alphanumeric characters supported).\n";
166: }
167: }
168:
169: my $lonHostID;
170: if ($lonDefDomain) {
171: $lonHostID=$lonDefDomain.$r.int(1+rand(9)); # should be probably also detect
172: # against the hosts.tab
173: }
174:
175: print(<<END);
176:
177: **** Machine ID Name ****
178: [this does NOT need to correspond to internet address names;
179: this name MUST be unique to the whole LON-CAPA network;
180: we recommend that you use a name based off of your institution;
181: good examples: "msul1" or "bionetl1";
182: bad examples: "loncapabox" or "studentsinside"]
183: END
184: # get machine name
185: # accept if valid, if not valid, tell user and repeat
186: $flag=0;
187: while (!$flag) {
188: if ($ipdomain) {
189: print(<<END);
190: ENTER LONCAPA MACHINE ID [$lonHostID]:
191: END
192: }
193: else {
194: print(<<END);
195: ENTER LONCAPA MACHINE ID:
196: END
197: }
198: my $choice=<>;
199: chomp($choice);
200: if ($lonHostID and $choice=~/^\s*$/) {
201: $choice=$lonHostID;
202: open(OUT,'>>/tmp/loncapa_updatequery.out');
203: print(OUT 'lonHostID'."\t".$choice."\n");
204: close(OUT);
205: $lonHostID=$choice;
206: $flag=1;
207: }
208: elsif ($choice!~/\_/ and $choice=~/^\w+$/) {
209: open(OUT,'>>/tmp/loncapa_updatequery.out');
210: print(OUT 'lonHostID'."\t".$choice."\n");
211: close(OUT);
212: $lonHostID=$choice;
213: $flag=1;
214: }
215: else {
216: print "Invalid input (only alphanumeric characters supported).\n";
217: }
218: }
219:
220: # get e-mail address
221: # accept if valid, if not valid, tell user and repeat
222: $flag=0;
223: my $lonAdmEMail;
224: while (!$flag) {
225: print(<<END);
226:
227: **** System Administrator's E-mail ****
228: E-mail address of the person who will manage this machine
229: [should be in the form somebody\@somewhere]
230: ENTER E-MAIL ADDRESS:
231: END
232:
233: my $choice=<>;
234: chomp($choice);
235: if ($choice=~/\@/) {
236: open(OUT,'>>/tmp/loncapa_updatequery.out');
237: print(OUT 'lonAdmEMail'."\t".$choice."\n");
238: close(OUT);
239: $lonAdmEMail=$choice;
240: $flag=1;
241: }
242: else {
243: print "Invalid input (this needs to look like an e-mail address!).\n";
244: }
245: }
246:
247: # update loncapa.conf
248: my $confdir='/etc/httpd/conf/';
249: #my $confdir='';
250: my $filename='loncapa.conf';
251: my %perlvar;
252: if (-e "$confdir$filename") {
253: open(CONFIG,'<'.$confdir.$filename) or die("Can't read $confdir$filename");
254: while (my $configline=<CONFIG>) {
255: if ($configline =~ /^[^\#]*PerlSetVar/) {
256: my ($unused,$varname,$varvalue)=split(/\s+/,$configline);
257: chomp($varvalue);
258: $perlvar{$varname}=$varvalue if $varvalue!~/^\{\[\[\[\[/;
259: }
260: }
261: close(CONFIG);
262: }
263: $perlvar{'lonHostID'}=$lonHostID;
264: $perlvar{'lonDefDomain'}=$lonDefDomain;
265: $perlvar{'lonAdmEMail'}=$lonAdmEMail;
266: $perlvar{'lonRole'}=$lonRole;
267: unless ($perlvar{'lonLoadLim'} and $perlvar{'lonLoadLim'}!~/\{\[\[\[\[/) {
268: $perlvar{'lonLoadLim'}='2.00';
269: }
270: unless ($perlvar{'lonExpire'} and $perlvar{'lonExpire'}!~/\{\[\[\[\[/) {
271: $perlvar{'lonExpire'}='86400';
272: }
273: unless ($perlvar{'lonReceipt'} and $perlvar{'lonReceipt'}!~/\{\[\[\[\[/) {
274: my $lonReceipt='';
275: srand(time ^ $$ ^ unpack "%L*", `ps axww | gzip`);
276: my @alnum=(0..9,a..z);
277: foreach my $i (1..20) {
278: $lonReceipt.=$alnum[int(rand(36))];
279: }
280: $perlvar{'lonReceipt'}=$lonReceipt;
281: }
282: open(OUT,">$confdir$filename") or
283: die("Cannot output to $confdir$filename\n");
284: foreach my $key (keys %perlvar) {
285: my $value=$perlvar{$key};
286: print(OUT <<END);
287: PerlSetVar $key $value
288: END
289: }
290: close(OUT);
291: }
292: </perlscript>
293: </file>
294: <file>
295: <target dist='default'>/</target>
296: <perlscript mode='fg'>
297: # read values from loncapa.conf
298: my $confdir='/etc/httpd/conf/';
299: my $filename='loncapa.conf';
300: my %perlvar;
301: if (-e "$confdir$filename") {
302: open(CONFIG,'<'.$confdir.$filename) or
303: die("Can't read $confdir$filename");
304: while (my $configline=<CONFIG>) {
305: if ($configline =~ /^[^\#]*PerlSetVar/) {
306: my ($unused,$varname,$varvalue)=split(/\s+/,$configline);
307: chomp($varvalue);
308: $perlvar{$varname}=$varvalue;
309: }
310: }
311: close(CONFIG);
312: }
313: unless ($perlvar{'lonLoadLim'} and $perlvar{'lonLoadLim'}!~/\{\[\[\[\[/) {
314: $perlvar{'lonLoadLim'}='2.00';
315: }
316: unless ($perlvar{'lonExpire'} and $perlvar{'lonExpire'}!~/\{\[\[\[\[/) {
317: $perlvar{'lonExpire'}='86400';
318: }
319: unless ($perlvar{'lonReceipt'} and $perlvar{'lonReceipt'}!~/\{\[\[\[\[/) {
320: my $lonReceipt='';
321: srand(time ^ $$ ^ unpack "%L*", `ps axww | gzip`);
322: my @alnum=(0..9,a..z);
323: foreach my $i (1..20) {
324: $lonReceipt.=$alnum[int(rand(36))];
325: }
326: $perlvar{'lonReceipt'}=$lonReceipt;
327: }
328: my %perlvarstatic;
329: if (-e "${confdir}loncapa_apache.conf") {
330: open(CONFIG,'<'.$confdir.'loncapa_apache.conf') or
331: die("Can't read ${confdir}loncapa_apache.conf");
332: while (my $configline=<CONFIG>) {
333: if ($configline =~ /^[^\#]*PerlSetVar/) {
334: my ($unused,$varname,$varvalue)=split(/\s+/,$configline);
335: chomp($varvalue);
336: $perlvarstatic{$varname}=$varvalue;
337: }
338: }
339: close(CONFIG);
340: }
341: # implement editing logic below, interactively
342: # update loncapa.conf until 7 is entered
343:
344: $flag=0;
345: while (!$flag) {
346: print(<<END);
347:
348: ===============================================================================
349: This is now the current configuration of your machine.
350: 1) Domain Name: $perlvar{'lonDefDomain'}
351: 2) Machine Name: $perlvar{'lonHostID'}
352: 3) System Administrator's E-mail Address: $perlvar{'lonAdmEMail'}
353: 4) Role: $perlvar{'lonRole'}
354: 5) Cache Expiration Time: $perlvar{'lonExpire'}
355: 6) Server Load: $perlvar{'lonLoadLim'}
356: 7) Everything is correct up above
357: END
358: print(<<END);
359: ENTER A CHOICE OF 1-6 TO CHANGE, otherwise ENTER 7:
360: END
361: my $choice=<>;
362: chomp($choice);
363: if ($choice==1) {
364: print(<<END);
365: 1) Domain Name: $perlvar{'lonDefDomain'}
366: ENTER NEW VALUE:
367: END
368: my $choice2=<>;
369: chomp($choice2);
370: $perlvar{'lonDefDomain'}=$choice2;
371: }
372: elsif ($choice==2) {
373: print(<<END);
374: 2) Machine Name: $perlvar{'lonHostID'}
375: ENTER NEW VALUE:
376: END
377: my $choice2=<>;
378: chomp($choice2);
379: $perlvar{'lonHostID'}=$choice2;
380: }
381: elsif ($choice==3) {
382: print(<<END);
383: 3) System Administrator's E-mail Address: $perlvar{'lonAdmEMail'}
384: ENTER NEW VALUE:
385: END
386: my $choice2=<>;
387: chomp($choice2);
388: $perlvar{'lonAdmEMail'}=$choice2;
389: }
390: elsif ($choice==4) {
391: print(<<END);
392: 4) Role: $perlvar{'lonRole'}
393: ENTER NEW VALUE:
394: END
395: my $choice2=<>;
396: chomp($choice2);
397: $perlvar{'lonRole'}=$choice2;
398: }
399: elsif ($choice==5) {
400: print(<<END);
401: 5) Cache Expiration Time: $perlvar{'lonExpire'}
402: ENTER NEW VALUE:
403: END
404: my $choice2=<>;
405: chomp($choice2);
406: $perlvar{'lonExpire'}=$choice2;
407: }
408: elsif ($choice==6) {
409: print(<<END);
410: 6) Server Load: $perlvar{'lonLoadLim'}
411: ENTER NEW VALUE:
412: END
413: my $choice2=<>;
414: chomp($choice2);
415: $perlvar{'lonLoadLim'}=$choice2;
416: }
417: elsif ($choice==7) {
418: $flag=1;
419: }
420: else {
421:
422: }
423: }
424: open(OUT,">$confdir$filename") or
425: die("Cannot output to $confdir$filename\n");
426: foreach my $key (keys %perlvar) {
427: my $value=$perlvar{$key};
428: print(OUT <<END) unless $perlvarstatic{$key};
429: PerlSetVar $key $value
430: END
431: }
432: close(OUT);
433: </perlscript>
434: </file>
435: <file>
436: <target dist='default'>loncom/hosts.tab</target>
437: <perlscript mode='fg'>
438: unless (-l "<TARGET />") {
439: print(<<END);
440:
441: ===============================================================================
442: What hosts.tab would you like to have installed?
443: (hosts.tab is a listing of all other internet machines
444: that a server system considers to be valid server systems
445: on the LON-CAPA network)
446:
447: 1) PRODUCTION - you want to deliver courses today or sometime very soon
448: on this machine
449: 2) STAND-ALONE - you want this machine to run in 'stand-alone' mode and
450: not be connected to other LON-CAPA machines for now
451: 3) DEVELOPMENT - you want to play with or explore LON-CAPA
452: 4) PRESERVE the existing hosts.tab (/home/httpd/lonTabs/hosts.tab)
453:
454: END
455: # Option number 26 will install rawhide_hosts.tab, but
456: # the typical user does not want to be part of an intensive
457: # machine test cluster.
458:
459: # get input
460: # if valid then process, otherwise loop
461: my $hostname=`hostname`;chomp($hostname);
462: my $hostaddress=`hostname -i $hostname`;chomp($hostaddress);
463: $flag=0;
464: while (!$flag) {
465: print "ENTER 1, 2, 3, or 4:\n";
466: my $choice=<>;
467: chomp($choice);
468: $line2insert=<<END;
469: $perlvar{'lonHostID'}:$perlvar{'lonDefDomain'}:$perlvar{'lonRole'}:$hostname:$hostaddress
470: END
471: $date=`date -I`; chomp($date);
472: $lonHostID=$perlvar{'lonHostID'};
473: $lonHostID=~s/\W//g;
474: $lineexistflag=0;
475: $hostidexistflag=0;
476: if ($choice==1) {
477: $lonCluster='production'; $flag=1;
478: }
479: elsif ($choice==2) {
480: $lonCluster='standalone'; $flag=1;
481: open(OUT,'>../'.$lonCluster.'_hosts.tab') or
482: die('file generation error');
483: print(OUT $line2insert);
484: close(OUT);
485: }
486: elsif ($choice==3) {
487: $lonCluster='development'; $flag=1;
488: }
489: elsif ($choice==4) {
490: $lonCluster='existing'; $flag=1;
491: if (-e '/home/httpd/lonTabs/hosts.tab') {
492: `cp /home/httpd/lonTabs/hosts.tab ../existing_hosts.tab`;
493: }
494: else {
495: print <<END;
496: There is no existing /home/httpd/lonTabs/hosts.tab
497: END
498: die('');
499: }
500: }
501: elsif ($choice==26) {
502: $lonCluster='rawhide'; $flag=1;
503: }
504: if ($flag==1) {
505: `rm -f ../hosts.tab`;
506: open(IN,'<../'.$lonCluster.'_hosts.tab');
507: while(<IN>) {
508: if (/^$line2insert$/) {
509: $lineexistflag=1;
510: }
511: if (/^$lonHostID\:/) {
512: $hostidexistflag=1;
513: }
514: }
515: close(IN);
516: if ($hostidexistflag and !$lineexistflag) {
517: print <<END;
518: WARNING: $lonHostID already exists inside
519: loncapa/loncom/${lonCluster}_hosts.tab. The entry inside
520: ${lonCluster}_hosts.tab does not match your settings.
521: The entry inside ${lonCluster}_hosts.tab is being replaced
522: with your new values.
523: END
524: `grep -v "$lonHostID:" ../${lonCluster}_hosts.tab > ../new_${lonCluster}_hosts.tab`;
525: open(OUT,'>>../new_'.$lonCluster.'_hosts.tab') or
526: die("cannot open loncom/${lonCluster}_hosts.tab for output\n");
527: print(OUT $line2insert);
528: close(OUT);
529: `ln -s new_${lonCluster}_hosts.tab ../hosts.tab`;
530: # email appropriate message
531: `echo "REPLACE:$lonCluster:$lonHostID:$date:$line2insert" | mail -s "REPLACE:$lonCluster:$lonHostID:$date" installrecord\@mail.lon-capa.org`;
532: }
533: elsif ($hostidexistflag and $lineexistflag) {
534: print <<END;
535: Entry exists in ${lonCluster}_hosts.tab.
536: END
537: `ln -s ${lonCluster}_hosts.tab ../hosts.tab`;
538: # email appropriate message
539: `echo "STABLEUPDATE:$lonCluster:$lonHostID:$date:$line2insert" | mail -s "STABLEUPDATE:$lonCluster:$lonHostID:$date" installrecord\@mail.lon-capa.org`;
540: }
541: elsif (!$hostidexistflag and !$lineexistflag) {
542: print <<END;
543: New entry for $lonCluster.
544: END
545: `cat ../${lonCluster}_hosts.tab > ../new_${lonCluster}_hosts.tab`;
546: open(OUT,'>../new_'.$lonCluster.'_hosts.tab') or
547: die("cannot open loncom/${lonCluster}_hosts.tab for output\n");
548: print(OUT $line2insert);
549: close(OUT);
550: `ln -s new_${lonCluster}_hosts.tab ../hosts.tab`;
551: # email appropriate message
552: `echo "INSERT:$lonCluster:$lonHostID:$date:$line2insert" | mail -s "INSERT:$lonCluster:$lonHostID:$date" installrecord\@mail.lon-capa.org`;
553: }
554: }
555: }
556:
557: }
558: </perlscript>
559: </file>
560: </files>
561: </piml>
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>