Annotation of doc/install/linux/install.pl, revision 1.4
1.1 raeburn 1: #!/usr/bin/perl
2: # The LearningOnline Network
3: # Pre-installation script for LON-CAPA
4: #
5: # Copyright Michigan State University Board of Trustees
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: # http://www.lon-capa.org/
24: #
25:
26: use strict;
27: use File::Copy;
28: use Term::ReadKey;
29: use DBI;
30: use LCLocalization::localize;
31:
32: # ========================================================= The language handle
33:
34: my %languages = (
35: ar => 'Arabic',
36: de => 'German',
37: en => 'English',
38: es => 'Spanish (Castellan)',
39: fa => 'Persian',
40: fr => 'French',
41: he => 'Hebrew',
42: ja => 'Japanese',
43: pt => 'Portuguese',
44: ru => 'Russian',
45: tr => 'Turkish',
46: zh => 'Chinese Simplified'
47: );
48:
49: use vars qw($lh $lang);
50: $lang = 'en';
51: if (@ARGV > 0) {
52: foreach my $poss (keys(%languages)) {
53: if ($ARGV[0] eq $poss) {
54: $lang = $ARGV[0];
55: }
56: }
57: }
58:
59: &get_language_handle($lang);
60:
61: # Check user has root privs
62: if (0 != $<) {
63: print &mt('This script must be run as root.')."\n".
64: &mt('Stopping execution.')."\n";
65: exit;
66: }
67:
68:
69: # Globals: filehandle LOG is global.
70: if (!open(LOG,">>loncapa_install.log")) {
71: print &mt('Unable to open log file.')."\n".
72: &mt('Stopping execution.')."\n";
73: exit;
74: } else {
1.4 ! raeburn 75: print LOG '$Id: install.pl,v 1.3 2011/03/18 17:53:34 raeburn Exp $'."\n";
1.1 raeburn 76: }
77:
78: #
1.2 raeburn 79: # Helper routines and routines to establish recommended actions
1.1 raeburn 80: #
81:
82: sub get_language_handle {
83: my @languages = @_;
84: $lh=LCLocalization::localize->get_handle(@languages);
85: }
86:
87: sub mt (@) {
88: if ($lh) {
89: if ($_[0] eq '') {
90: if (wantarray) {
91: return @_;
92: } else {
93: return $_[0];
94: }
95: } else {
96: return $lh->maketext(@_);
97: }
98: } else {
99: if (wantarray) {
100: return @_;
101: } else {
102: return $_[0];
103: }
104: }
105: }
106:
107: sub texthash {
108: my (%hash) = @_;
109: foreach (keys(%hash)) {
110: $hash{$_}=&mt($hash{$_});
111: }
112: return %hash;
113: }
114:
115:
116: sub skip_if_nonempty {
117: my ($string,$error)=@_;
118: return if (! defined($error));
119: chomp($string);chomp($error);
120: if ($string ne '') {
121: print_and_log("$error\n".&mt('Stopping execution.')."\n");
122: return 1;
123: }
124: return;
125: }
126:
127: sub writelog {
128: while ($_ = shift) {
129: chomp();
130: print LOG "$_\n";
131: }
132: }
133:
134: sub print_and_log {
135: while ($_=shift) {
136: chomp();
137: print "$_\n";
138: print LOG "$_\n";
139: }
140: }
141:
142: sub get_user_selection {
143: my ($defaultrun) = @_;
144: my $do_action = 0;
145: my $choice = <STDIN>;
146: chomp($choice);
147: $choice =~ s/(^\s+|\s+$)//g;
148: my $yes = &mt('y');
149: if ($defaultrun) {
150: if (($choice eq '') || ($choice =~ /^\Q$yes\E/i)) {
151: $do_action = 1;
152: }
153: } else {
154: if ($choice =~ /^\Q$yes\E/i) {
155: $do_action = 1;
156: }
157: }
158: return $do_action;
159: }
160:
161: sub get_distro {
162: my ($distro,$gotprereqs,$updatecmd,$packagecmd,$installnow);
163: $packagecmd = '/bin/rpm -q LONCAPA-prerequisites ';
164: if (-e '/etc/redhat-release') {
165: open(IN,'</etc/redhat-release');
166: my $versionstring=<IN>;
167: chomp($versionstring);
168: close(IN);
169: if ($versionstring =~ /^Red Hat Linux release ([\d\.]+) /) {
170: my $version = $1;
171: if ($version=~/^7\./) {
172: $distro='redhat7';
173: } elsif ($version=~/^8\./) {
174: $distro='redhat8';
175: } elsif ($version=~/^9/) {
176: $distro='redhat9';
177: }
178: } elsif ($versionstring =~ /Fedora( Core)? release ([\d\.]+) /) {
179: my $version=$2;
180: if ($version - int($version) > .9) {
181: $distro = 'fedora'.(int($version)+1);
182: } else {
183: $distro = 'fedora'.int($version);
184: }
185: $updatecmd = 'yum install LONCAPA-prerequisites';
186: $installnow = 'yum -y install LONCAPA-prerequisites';
187: } elsif ($versionstring =~ /Red Hat Enterprise Linux [AE]S release ([\d\.]+) /) {
188: $distro = 'rhes'.$1;
189: $updatecmd = 'up2date -i LONCAPA-prerequisites';
190: } elsif ($versionstring =~ /Red Hat Enterprise Linux Server release (\d+)/) {
191: $distro = 'rhes'.$1;
192: $updatecmd = 'yum install LONCAPA-prerequisites';
193: $installnow = 'yum -y install LONCAPA-prerequisites';
194: } elsif ($versionstring =~ /CentOS release (\d+)/) {
195: $distro = 'centos'.$1;
196: $updatecmd = 'yum install LONCAPA-prerequisites';
197: $installnow = 'yum -y install LONCAPA-prerequisites';
198: } elsif ($versionstring =~ /Scientific Linux SL release ([\d.]+) /) {
199: my $ver = $1;
200: $ver =~ s/\.\d+$//;
201: $distro = 'scientific'.$ver;
202: $updatecmd = 'yum install LONCAPA-prerequisites';
203: $installnow = 'yum -y install LONCAPA-prerequisites';
204: } else {
205: print &mt('Unable to interpret [_1] to determine system type.',
206: '/etc/redhat-release')."\n";
207: }
208: } elsif (-e '/etc/SuSE-release') {
209: open(IN,'</etc/SuSE-release');
210: my $versionstring=<IN>;
211: chomp($versionstring);
212: close(IN);
213: if ($versionstring =~ /^SUSE LINUX Enterprise Server ([\d\.]+) /i) {
214: $distro='sles'.$1;
215: if ($1 >= 10) {
216: $updatecmd = 'zypper install LONCAPA-prerequisites';
217: } else {
218: $updatecmd = 'yast -i LONCAPA-prerequisites';
219: }
220: } elsif ($versionstring =~ /^SuSE Linux ([\d\.]+) /i) {
221: $distro = 'suse'.$1;
222: $updatecmd = 'yast -i LONCAPA-preprequisites';
223: } elsif ($versionstring =~ /^openSUSE ([\d\.]+) /i) {
224: $distro = 'suse'.$1;
225: if ($1 >= 10.3 ) {
226: $updatecmd = 'zypper install LONCAPA-prerequisites';
227: } else {
228: $updatecmd = 'yast -i LONCAPA-prerequisites';
229: }
230: } else {
231: print &mt('Unable to interpret [_1] to determine system type.',
232: '/etc/SuSE-release')."\n";
233: }
234: } elsif (-e '/etc/issue') {
235: open(IN,'</etc/issue');
236: my $versionstring=<IN>;
237: chomp($versionstring);
238: close(IN);
239: $packagecmd = '/usr/bin/dpkg -l loncapa-prerequisites ';
240: $updatecmd = 'apt-get install loncapa-prerequisites';
241: if ($versionstring =~ /^Ubuntu (\d+)\.\d+/i) {
242: $distro = 'ubuntu'.$1;
243: $updatecmd = 'sudo apt-get install loncapa-prerequisites';
244: } elsif ($versionstring =~ /^Debian\s+GNU\/Linux\s+(\d+)\.\d+/i) {
245: $distro = 'debian'.$1;
246: } elsif (-e '/etc/debian_version') {
247: open(IN,'</etc/debian_version');
248: my $version=<IN>;
249: chomp($version);
250: close(IN);
251: if ($version =~ /^(\d+)\.\d+\.?\d*/) {
252: $distro='debian'.$1;
253: } else {
254: print &mt('Unable to interpret [_1] to determine system type.',
255: '/etc/debian_version')."\n";
256: }
257: } else {
258: print &mt('Unable to interpret [_1] to determine system type.',
259: '/etc/issue')."\n";
260: }
261: } elsif (-e '/etc/debian_version') {
262: open(IN,'</etc/debian_version');
263: my $version=<IN>;
264: chomp($version);
265: close(IN);
266: if ($version =~ /^(\d+)\.\d+\.?\d*/) {
267: $distro='debian'.$1;
268: $packagecmd = '/usr/bin/dpkg -l loncapa-prerequisites ';
269: $updatecmd = 'apt-get install loncapa-prerequisites';
270: } else {
271: print &mt('Unable to interpret [_1] to determine system type.',
272: '/etc/debian_version')."\n";
273: }
274: } else {
275: print &mt('Unknown installation: expecting a debian, ubuntu, suse, sles, redhat, fedora or scientific linux system.')."\n";
276: }
277: return ($distro,$packagecmd,$updatecmd,$installnow);
278: }
279:
280: sub check_prerequisites {
281: my ($packagecmd,$distro) = @_;
282: my $gotprereqs;
283: if ($packagecmd ne '') {
284: if (open(PIPE,"$packagecmd|")) {
285: if ($distro =~ /^(debian|ubuntu)/) {
286: my @lines = <PIPE>;
287: chomp(@lines);
288: foreach my $line (@lines) {
289: if ($line =~ /^ii\s+loncapa-prerequisites\s+([\w\.]+)/) {
290: $gotprereqs = $1;
291: }
292: }
293: } else {
294: my $line = <PIPE>;
295: chomp($line);
296: if ($line =~ /^LONCAPA-prerequisites\-([\d\-]+)\.(\w+)$/) {
297: $gotprereqs = $1;
298: }
299: }
300: close(PIPE);
301: } else {
302: print &mt('Error: could not determine if LONCAPA-prerequisites package is installed')."\n";
303: }
304: }
305: return $gotprereqs;
306: }
307:
308: sub check_required {
309: my ($instdir,$dsn) = @_;
310: my ($distro,$packagecmd,$updatecmd,$installnow) = &get_distro();
311: if ($distro eq '') {
312: return;
313: }
314: my $gotprereqs = &check_prerequisites($packagecmd,$distro);
315: if ($gotprereqs eq '') {
316: return ($distro,$gotprereqs,$packagecmd,$updatecmd,$installnow);
317: }
318: my ($mysqlon,$mysqlsetup,$dbh,$has_pass,$has_lcdb,%recommended,$downloadstatus,
319: $filetouse,$production,$testing);
320: my $wwwuid = &uid_of_www();
321: my $wwwgid = getgrnam('www');
322: if (($wwwuid eq '') || ($wwwgid eq '')) {
323: $recommended{'wwwuser'} = 1;
324: }
325: unless( -e "/usr/local/sbin/pwauth") {
326: $recommended{'pwauth'} = 1;
327: }
328: $mysqlon = &check_mysql_running($distro);
329: if ($mysqlon) {
330: my $mysql_has_wwwuser = &check_mysql_wwwuser();
331: ($mysqlsetup,$has_pass,$dbh) =
332: &check_mysql_setup($instdir,$dsn);
333: if ($mysqlsetup eq 'noroot') {
334: $recommended{'mysqlperms'} = 1;
335: } else {
336: unless ($mysql_has_wwwuser) {
337: $recommended{'mysqlperms'} = 1;
338: }
339: }
340: if ($dbh) {
341: $has_lcdb = &check_loncapa_mysqldb($dbh);
342: }
343: unless ($has_lcdb) {
344: $recommended{'mysql'} = 1;
345: }
346: }
347: my $tostop;
348: $recommended{'firewall'} = &chkfirewall($distro);
349: ($recommended{'runlevels'},$tostop) = &chkconfig($distro);
350: $recommended{'apache'} = &chkapache($distro,$instdir);
351: $recommended{'stopsrvcs'} = &chksrvcs($distro,$tostop);
352: ($recommended{'download'},$downloadstatus,$filetouse,$production,$testing)
353: = &need_download();
354: return ($distro,$gotprereqs,$packagecmd,$updatecmd,$installnow,
355: \%recommended,$dbh,$has_pass,$has_lcdb,$downloadstatus,
356: $filetouse,$production,$testing);
357: }
358:
359: sub check_mysql_running {
360: my ($distro) = @_;
361: my $mysqldaemon ='mysqld';
362: if ($distro =~ /^(suse|sles|debian|ubuntu)/) {
363: $mysqldaemon = 'mysql';
364: }
1.4 ! raeburn 365: if (open(PIPE,"ps -ef |grep mysqld_safe |grep -v grep 2>&1 |")) {
1.1 raeburn 366: my $status = <PIPE>;
367: close(PIPE);
368: chomp($status);
1.4 ! raeburn 369: if ($status =~ /^root\s+\d+\s+/) {
1.1 raeburn 370: print_and_log(&mt('MySQL is running.')."\n");
371: return 1;
372: } else {
373: system("/etc/rc.d/init.d/$mysqldaemon start");
374: print_and_log(&mt('Waiting for MySQL to start.')."\n");
375: sleep 5;
376: if (open (PIPE, "/etc/init.d/$mysqldaemon 2>&1 |")) {
377: my $status = <PIPE>;
378: close(PIPE);
379: chomp($status);
380: if ($status =~ /\(pid\s+\d\)/) {
381: print_and_log(&mt('MySQL is running.')."\n");
382: return 1;
383: } else {
384: print_and_log(&mt('Unable to start MySQL.')."\n");
385: }
386: } else {
387: print_and_log(&mt('Unable to start MySQL.')."\n");
388: }
389: }
390: } else {
391: print &mt('Could not determine if MySQL is running.')."\n";
392: }
393: return;
394: }
395:
396: sub chkconfig {
397: my ($distro) = @_;
398: my (%needfix,%tostop);
399: my $checker_bin = '/sbin/chkconfig';
400: my $mysqldaemon ='mysqld';
401: my $webserver = 'httpd';
402: my $cupsdaemon = 'cups';
403: my @runlevels = qw/3 4 5/;
404: my @norunlevels = qw/0 1 6/;
405: if ($distro =~ /^(suse|sles)/) {
406: @runlevels = qw/3 5/;
407: @norunlevels = qw/0 2 1 6/;
408: $mysqldaemon = 'mysql';
409: $webserver = 'apache2';
410: if ($distro =~ /^(suse|sles)9/) {
411: $webserver = 'apache';
412: }
413: } elsif ($distro =~ /^(debian|ubuntu)/) {
414: @runlevels = qw/2 3 4 5/;
415: @norunlevels = qw/0 1 6/;
416: $checker_bin = '/usr/sbin/sysv-rc-conf';
417: $mysqldaemon = 'mysql';
418: $webserver = 'apache2';
419: }
420: if (! -x $checker_bin) {
421: print &mt('Could not check runlevel status for MySQL or Apache.')."\n";
422: return;
423: }
424: my $rlstr = join('',@runlevels);
425: my $nrlstr = join('',@norunlevels);
426: foreach my $type ('apache','mysql','cups') {
427: my $service;
428: if ($type eq 'apache') {
429: $service = $webserver;
430: } elsif ($type eq 'mysql') {
431: $service = $mysqldaemon;
432: } elsif ($type eq 'cups') {
433: $service = $cupsdaemon;
434: }
435: my $command = $checker_bin.' --list '.$service;
436: my $results = `$command`;
437: my $tofix;
438: if ($results eq '') {
439: if (($type eq 'apache') || ($type eq 'mysql')) {
440: if ($distro =~ /^(debian|ubuntu)/) {
441: $tofix = "$checker_bin --level $nrlstr $service off\n";
442: } else {
443: $tofix = "$checker_bin --add $service\n";
444: }
445: }
446: } else {
447: my %curr_runlevels;
448: for (my $rl=0; $rl<=6; $rl++) {
449: if ($results =~ /$rl:on/) { $curr_runlevels{$rl}++; }
450: }
451: if (($type eq 'apache') || ($type eq 'mysql')) {
452: my $warning;
453: foreach my $rl (@runlevels) {
454: if (!exists($curr_runlevels{$rl})) {
455: $warning = 1;
456: }
457: }
458: if ($warning) {
459: $tofix = "$checker_bin --level $rlstr $service on\n";
460: }
461: } elsif (keys(%curr_runlevels) > 0) {
462: $tostop{$type} = 1;
463: }
464: }
465: if ($tofix) {
466: $needfix{$type} = $tofix;
467: }
468: }
469: if ($distro =~ /^(suse|sles)([\d\.]+)$/) {
470: my $name = $1;
471: my $version = $2;
472: my ($major,$minor);
473: if ($name eq 'suse') {
474: ($major,$minor) = split(/\./,$version);
475: } else {
476: $major = $version;
477: }
478: if ($major > 10) {
479: $needfix{'insserv'} = &check_SuSEfirewall2_setup();
480: }
481: }
482: return (\%needfix,\%tostop);
483: }
484:
485: sub chkfirewall {
486: my $configfirewall = 1;
487: my %ports = (
488: http => 80,
489: https => 443,
490: );
491: if (&firewall_is_active()) {
492: my $iptables = &get_pathto_iptables();
493: if ($iptables eq '') {
494: print &mt('Firewall not checked as path to iptables not determined.')."\n";
495: } else {
496: my @fwchains = &get_fw_chains($iptables);
497: if (@fwchains) {
498: my %activefw;
499: foreach my $service ('http','https') {
500: foreach my $fwchain (@fwchains) {
501: if (&firewall_is_port_open($iptables,$fwchain,$ports{$service})) {
502: $activefw{$service} = 1;
503: last;
504: }
505: }
506: }
507: if ($activefw{'http'}) {
508: $configfirewall = 0;
509: }
510: } else {
511: print &mt('Firewall not checked as iptables Chains not identified.')."\n";
512: }
513: }
514: } else {
515: print &mt('Firewall not enabled.')."\n";
516: }
517: return $configfirewall;
518: }
519:
520: sub chkapache {
521: my ($distro,$instdir) = @_;
522: my $fixapache = 1;
523: if ($distro =~ /^(debian|ubuntu)/) {
524: if (!-e "$instdir/apache2.conf") {
525: $fixapache = 0;
526: print &mt('Warning: No LON-CAPA Apache configuration file found for installation check.')."\n";
527: } elsif ((-e "/etc/apache2/sites-available/loncapa") && (-e "$instdir/apache2.conf")) {
528: if (open(PIPE, "diff --brief $instdir/apache2.conf /etc/apache2/sites-available/loncapa |")) {
529: my $diffres = <PIPE>;
530: close(PIPE);
531: chomp($diffres);
532: unless ($diffres) {
533: $fixapache = 0;
534: }
535: }
536: }
537: } elsif ($distro =~ /^(?:suse|sles)([\d\.]+)$/) {
538: my $apache = 'apache';
539: if ($1 >= 10) {
540: my $apache = 'apache2';
541: }
542: if (!-e "$instdir/default-server.conf") {
543: $fixapache = 0;
544: print &mt('Warning: No LON-CAPA Apache configuration file found for installation check.')."\n";
545: } elsif ((-e "/etc/$apache/default-server.conf") && (-e "$instdir/default-server.conf")) {
546: if (open(PIPE, "diff --brief $instdir/default-server.conf /etc/$apache/default-server.conf |")) {
547: my $diffres = <PIPE>;
548: close(PIPE);
549: chomp($diffres);
550: unless ($diffres) {
551: $fixapache = 0;
552: }
553: }
554: }
555: } else {
556: if (!-e "$instdir/httpd.conf") {
557: $fixapache = 0;
558: print &mt('Warning: No LON-CAPA Apache configuration file found for installation check.')."\n";
559: } elsif ((-e "/etc/httpd/conf/httpd.conf") && (-e "$instdir/httpd.conf")) {
560: if (open(PIPE, "diff --brief $instdir/httpd.conf /etc/httpd/conf/httpd.conf |")) {
561: my $diffres = <PIPE>;
562: close(PIPE);
563: chomp($diffres);
564: print "Diff is ||$diffres||\n";
565: unless ($diffres) {
566: $fixapache = 0;
567: }
568: }
569: }
570: }
571: return $fixapache;
572: }
573:
574: sub chksrvcs {
575: my ($distro,$tostop) = @_;
576: my %stopsrvcs;
577: if (ref($tostop) eq 'HASH') {
578: %stopsrvcs = %{$tostop};
579: }
580: foreach my $service ('cups') {
581: next if (exists($stopsrvcs{$service}));
582: my $daemon = $service;
583: if ($service eq 'cups') {
584: $daemon = 'cupsd';
585: }
586: my $cmd = "ps -ef |grep '$daemon' |grep -v grep";
587: if (open(PIPE,'-|',$cmd)) {
588: my $daemonrunning = <PIPE>;
589: chomp($daemonrunning);
590: close(PIPE);
591: if ($daemonrunning) {
592: $stopsrvcs{$service} = 1;
593: }
594: }
595: }
596: return \%stopsrvcs;
597: }
598:
599: sub need_download {
600: my $needs_download = 1;
601: my ($production,$testing,$stdsizes) = &download_versionslist();
602: my ($rootdir,$localcurrent,$localtesting,%tarball,%localsize,%bymodtime,
603: %bysize,$filetouse,$downloadstatus);
604: $rootdir = '/root';
605: if (opendir(my $dir,"$rootdir")) {
606: my (@lcdownloads,$version);
607: foreach my $file (readdir($dir)) {
608: if ($file =~ /^loncapa\-([\w\-.]+)\.tar\.gz$/) {
609: $version = $1;
610: } else {
611: next;
612: }
613: if (ref($stdsizes) eq 'HASH') {
614: if ($version eq 'current') {
615: my @stats = stat("$rootdir/$file");
616: $localcurrent = $stats[7];
1.4 ! raeburn 617: if ($localcurrent == $stdsizes->{$production}) {
1.1 raeburn 618: $needs_download = 0;
619: $filetouse = $file;
620: }
621: } elsif ($version eq 'testing') {
622: my @stats = stat("$rootdir/$file");
623: $localtesting = $stats[7];
1.4 ! raeburn 624: if ($localtesting == $stdsizes->{$testing}) {
1.1 raeburn 625: $needs_download = 0;
626: $filetouse = $file;
627: }
628: }
629: }
630: $tarball{$version} = $file;
631: push(@lcdownloads,$version);
632: }
633: if ($needs_download) {
634: if (@lcdownloads > 0) {
635: foreach my $version (@lcdownloads) {
636: my @stats = stat("$rootdir/$tarball{$version}");
637: my $mtime = $stats[9];
638: $localsize{$version} = $stats[7];
639: if ($mtime) {
640: push(@{$bymodtime{$mtime}},$version);
641: }
642: if ($localsize{$version}) {
643: push(@{$bysize{$localsize{$version}}},$version);
644: }
645: }
646: if ($testing) {
647: if (exists($localsize{$testing})) {
648: if ($stdsizes->{$testing} == $localsize{$testing}) {
649: $needs_download = 0;
650: $filetouse = 'loncapa-'.$testing.'.tar.gz';
651: }
652: }
653: }
654: if ($needs_download) {
655: if ($production) {
656: if (exists($localsize{$production})) {
657: if ($stdsizes->{$production} == $localsize{$production}) {
658: $needs_download = 0;
659: $filetouse = 'loncapa-'.$production.'.tar.gz';
660: }
661: }
662: }
663: }
664: if ($needs_download) {
665: my @sorted = sort { $b <=> $a } keys(%bymodtime);
666: my $newest = $sorted[0];
667: if (ref($bymodtime{$newest}) eq 'ARRAY') {
668: $downloadstatus =
669: "Latest LON-CAPA source download in $rootdir is: ".
670: join(',',@{$bymodtime{$newest}})." (downloaded ".
671: localtime($newest).")\n";
672: }
673: } else {
674: $downloadstatus =
675: "The $rootdir directory already contains the latest LON-CAPA version:".
676: "\n".$filetouse."\n"."which can be used for installation.\n";
677: }
678: } else {
679: $downloadstatus = "The $rootdir directory does not appear to contain any downloaded LON-CAPA source code files which can be used for installation.\n";
680: }
681: }
682: } else {
683: $downloadstatus = "Could not open $rootdir directory to look for existing downloads of LON-CAPA source code.\n";
684: }
685: return ($needs_download,$downloadstatus,$filetouse,$production,$testing);
686: }
687:
688: sub check_mysql_setup {
689: my ($instdir,$dsn) = @_;
690: my ($mysqlsetup,$has_pass);
691: my $dbh = DBI->connect($dsn,'root','',{'PrintError'=>0});
692: if ($dbh) {
693: $mysqlsetup = 'noroot';
694: } elsif ($DBI::err =~ /1045/) {
695: $has_pass = 1;
696: }
697: if ($has_pass) {
698: print &mt('You have already set a root password for the MySQL database.')."\n";
699: my $currpass = &get_mysql_password(&mt('Please enter the password now'));
700: $dbh = DBI->connect($dsn,'root',$currpass,{'PrintError'=>0});
701: if ($dbh) {
702: $mysqlsetup = 'rootok';
703: print_and_log(&mt('Password accepted.')."\n");
704: } else {
705: $mysqlsetup = 'rootfail';
706: print_and_log(&mt('Problem accessing MySQL.')."\n");
707: if ($DBI::err =~ /1045/) {
708: print_and_log(&mt('Perhaps the password was incorrect?')."\n");
709: print &mt('Try again?').' ';
710: $currpass = &get_mysql_password(&mt('Re-enter password now'));
711: $dbh = DBI->connect($dsn,'root',$currpass,{'PrintError'=>0});
712: if ($dbh) {
713: $mysqlsetup = 'rootok';
714: print_and_log(&mt('Password accepted.')."\n");
715: } else {
716: if ($DBI::err =~ /1045/) {
717: print_and_log(&mt('Incorrect password.')."\n");
718: }
719: }
720: }
721: }
722: } elsif ($mysqlsetup ne 'noroot') {
723: print_and_log(&mt('Problem accessing MySQL.')."\n");
724: $mysqlsetup = 'rootfail';
725: }
726: return ($mysqlsetup,$has_pass,$dbh);
727: }
728:
729: sub check_mysql_wwwuser {
730: my $mysql_wwwuser;
731: my $dbhn = DBI->connect("DBI:mysql:database=information_schema",'www','localhostkey');
732: if ($dbhn) {
733: $mysql_wwwuser = 1;
734: $dbhn->disconnect;
735: }
736: return $mysql_wwwuser;
737: }
738:
739: sub check_loncapa_mysqldb {
740: my ($dbh) = @_;
741: my $has_lcdb;
742: if (ref($dbh)) {
743: my $sth = $dbh->prepare("SHOW DATABASES");
744: $sth->execute();
745: while (my $dbname = $sth->fetchrow_array) {
746: if ($dbname eq 'loncapa') {
747: $has_lcdb = 1;
748: last;
749: }
750: }
751: $sth->finish();
752: }
753: return $has_lcdb;
754: }
755:
756: sub get_pathto_iptables {
757: my $iptables;
758: if (-e '/sbin/iptables') {
759: $iptables = '/sbin/iptables';
760: } elsif (-e '/usr/sbin/iptables') {
761: $iptables = '/usr/sbin/iptables';
762: } else {
763: print &mt('Unable to find iptables command.')."\n";
764: }
765: return $iptables;
766: }
767:
768: sub firewall_is_active {
769: if (-e '/proc/net/ip_tables_names') {
770: return 1;
771: } else {
772: return 0;
773: }
774: }
775:
776: sub get_fw_chains {
777: my ($iptables) = @_;
778: my @fw_chains;
779: my $suse_config = "/etc/sysconfig/SuSEfirewall2";
780: my $ubuntu_config = "/etc/ufw/ufw.conf";
781: if (-e $suse_config) {
782: push(@fw_chains,'input_ext');
783: } else {
784: my @posschains;
785: if (-e $ubuntu_config) {
786: @posschains = ('ufw-user-input','INPUT');
787: } else {
788: @posschains = ('RH-Firewall-1-INPUT','INPUT');
789: if (!-e '/etc/sysconfig/iptables') {
790: if (!-e '/var/lib/iptables') {
791: print &mt('Unable to find iptables file containing static definitions.')."\n";
792: }
793: push(@fw_chains,'RH-Firewall-1-INPUT');
794: }
795: }
796: if ($iptables eq '') {
797: $iptables = &get_pathto_iptables();
798: }
799: my %counts;
800: if (open(PIPE,"$iptables -L -n |")) {
801: while(<PIPE>) {
802: foreach my $chain (@posschains) {
803: if (/(\Q$chain\E)/) {
804: $counts{$1} ++;
805: }
806: }
807: }
808: close(PIPE);
809: }
810: foreach my $fw_chain (@posschains) {
811: if ($counts{$fw_chain}) {
812: unless(grep(/^\Q$fw_chain\E$/,@fw_chains)) {
813: push(@fw_chains,$fw_chain);
814: }
815: }
816: }
817: }
818: return @fw_chains;
819: }
820:
821: sub firewall_is_port_open {
822: my ($iptables,$fw_chain,$port) = @_;
823: # returns 1 if the firewall port is open, 0 if not.
824: #
825: # check if firewall is active or installed
826: return if (! &firewall_is_active());
827: my $count = 0;
828: if (open(PIPE,"$iptables -L $fw_chain -n |")) {
829: while(<PIPE>) {
830: if (/tcp dpt\:\Q$port\E/) {
831: $count ++;
832: last;
833: }
834: }
835: close(PIPE);
836: } else {
837: print &mt('Firewall status not checked: unable to run [_1].','iptables -L')."\n";
838: }
839: return $count;
840: }
841:
842: sub get_mysql_password {
843: my ($prompt) = @_;
844: local $| = 1;
845: print $prompt.': ';
846: my $newpasswd = '';
847: ReadMode 'raw';
848: my $key;
849: while(ord($key = ReadKey(0)) != 10) {
850: if(ord($key) == 127 || ord($key) == 8) {
851: chop($newpasswd);
852: print "\b \b";
853: } elsif(!ord($key) < 32) {
854: $newpasswd .= $key;
855: print '*';
856: }
857: }
858: ReadMode 'normal';
859: print "\n";
860: return $newpasswd;
861: }
862:
863: sub check_SuSEfirewall2_setup {
864: my ($instdir) = @_;
865: my $need_override = 1;
866: if ((-e "/etc/insserv/overrides/SuSEfirewall2_setup") && (-e "$instdir/SuSEfirewall2_setup")) {
867: if (open(PIPE, "diff --brief $instdir/SuSEfirewall2_setup /etc/insserv/overrides/SuSEfirewall2_setup |")) {
868: my $diffres = <PIPE>;
869: close(PIPE);
870: chomp($diffres);
871: unless ($diffres) {
872: $need_override = 0;
873: }
874: }
875: }
876: return $need_override;
877: }
878:
879: sub download_versionslist {
880: my ($production,$testing,%sizes);
881: if (-e "latest.txt") {
882: unlink("latest.txt");
883: }
884: my $rtncode = system("wget http://install.loncapa.org/versions/latest.txt ".
885: "> /dev/null 2>&1");
886: if (!$rtncode) {
887: if (open(my $fh,"<latest.txt")) {
888: my @info = <$fh>;
889: close($fh);
890: foreach my $line (@info) {
891: chomp();
892: if ($line =~ /^\QLATEST-IS: \E([\w\-.]+):(\d+)$/) {
893: $production = $1;
894: $sizes{$1} = $2;
895: } elsif ($line =~ /^LATEST-TESTING-IS: \E([\w\-.]+):(\d+)$/) {
896: $testing = $1;
897: $sizes{$1} = $2;
898: }
899: }
900: }
901: }
902: return ($production,$testing,\%sizes);
903: }
904:
905: #
906: # End helper routines.
907: # Main script starts here
908: #
909:
910: print "
911: ********************************************************************
912:
913: ".&mt('Welcome to LON-CAPA')."
914:
915: ".&mt('This script will configure your system for installation of LON-CAPA.')."
916:
917: ********************************************************************
918:
919: ".&mt('The following actions are available:')."
920:
1.4 ! raeburn 921: ".&mt('1.')." ".&mt('Create the www user/group.')."
1.1 raeburn 922: ".&mt('This is the user/group ownership under which Apache child processes run.')."
923: ".&mt('It also owns most directories within the /home/httpd directory.')."
924: ".&mt('This directory is where most LON-CAPA files and directories are stored.')."
1.4 ! raeburn 925: ".&mt('2.')." ".&mt('Install the package LON-CAPA uses to authenticate users.')."
! 926: ".&mt('3.')." ".&mt('Set-up the MySQL database.')."
! 927: ".&mt('4.')." ".&mt('Set-up MySQL permissions.')."
! 928: ".&mt('5.')." ".&mt('Configure Apache web server.')."
! 929: ".&mt('6.')." ".&mt('Configure start-up of services.')."
! 930: ".&mt('7.')." ".&mt('Check firewall settings.')."
! 931: ".&mt('8.')." ".&mt('Stop services not used by LON-CAPA,')."
1.1 raeburn 932: ".&mt('i.e., services for a print server: [_1] daemon.',"'cups'")."
1.4 ! raeburn 933: ".&mt('9.')." ".&mt('Download LON-CAPA source code in readiness for installation.')."
1.1 raeburn 934:
935: ".&mt('Typically, you will run this script only once, when you first install LON-CAPA.')."
936:
937: ".&mt('The script will analyze your system to determine which actions are recommended.')."
938: ".&mt('The script will then prompt you to choose the actions you would like taken.')."
939:
940: ".&mt('For each the recommended action will be selected if you hit Enter/Return.')."
941: ".&mt('To override the default, type the lower case option from the two options listed.')."
942: ".&mt('So, if the default is "yes", ~[Y/n~] will be shown -- type n to override.')."
943: ".&mt('Whereas if the default is "no", ~[y/N~] will be shown -- type y to override.')."
944:
945: ".&mt('To accept the default, simply hit Enter/Return on your keyboard.')."
946: ".&mt('Otherwise type: y or n then hit the Enter/Return key.')."
947:
948: ".&mt('Once a choice has been entered for all nine actions, required changes will be made.')."
949: ".&mt('Feedback will be displayed on screen, and also stored in: [_1].','loncapa_install.log')."
950:
951: ".&mt('Continue? ~[Y/n~] ');
952:
953: my $go_on = &get_user_selection(1);
954: if (!$go_on) {
955: exit;
956: }
957:
958: my $instdir = `pwd`;
959: chomp($instdir);
960:
961: my %callsub;
962: my @actions = ('wwwuser','pwauth','mysql','mysqlperms','apache',
963: 'runlevels','firewall','stopsrvcs','download');
964: my %prompts = &texthash(
965: wwwuser => "Create the 'www' user?",
966: pwauth => 'Install the package LON-CAPA uses to authenticate users?',
967: mysql => 'Set-up the MySQL database?',
968: mysqlperms => 'Set-up MySQL permissions?',
969: apache => 'Configure Apache web server?',
970: runlevels => 'Set overrides for start-up order of services?',
971: firewall => 'Configure firewall settings for Apache',
972: stopsrvcs => 'Stop extra services not required on a LON-CAPA server?',
973: download => 'Download LON-CAPA source code in readiness for installation?',
974: );
975:
976: print "\n".&mt('Checking system status ...')."\n";
977:
978: my $dsn = "DBI:mysql:database=mysql";
979: my ($distro,$gotprereqs,$packagecmd,$updatecmd,$installnow,$recommended,
980: $dbh,$has_pass,$has_lcdb,$downloadstatus,$filetouse,$production,
981: $testing) = &check_required($instdir,$dsn);
982: if ($distro eq '') {
983: print "\n".&mt('Linux distribution could not be verified as a supported distribution.')."\n".
984: &mt('The following are supported: [_1].',
985: 'CentOS, RedHat Enterprise, Fedora, Scientific Linux, '.
986: 'openSuSE, SLES, Ubuntu LTS, Debian')."\n\n".
987: &mt('Stopping execution.')."\n";
988: exit;
989: }
990: if (!$gotprereqs) {
991: print "\n".&mt('The LONCAPA-prequisites package is not installed.')."\n".
992: &mt('The following command can be used to install the package (and dependencies):')."\n\n".
993: $updatecmd."\n\n";
994: if ($installnow eq '') {
995: print &mt('Stopping execution.')."\n";
996: exit;
997: } else {
998: print &mt('Run command? ~[Y/n~]');
999: my $install_prereq = &get_user_selection(1);
1000: if ($install_prereq) {
1001: if (open(PIPE,'|-',$installnow)) {
1002: close(PIPE);
1003: $gotprereqs = &check_prerequisites($packagecmd,$distro);
1004: if (!$gotprereqs) {
1005: print &mt('The LONCAPA-prequisites package is not installed.')."\n".
1006: &mt('Stopping execution.')."\n";
1007: exit;
1008: } else {
1009: ($distro,$gotprereqs,$packagecmd,$updatecmd,$installnow,
1010: $recommended,$dbh,$has_pass,$has_lcdb,$downloadstatus,
1011: $filetouse) = &check_required($instdir,$dsn);
1012: }
1013: } else {
1014: print &mt('Failed to run command to install LONCAPA-prequisites')."\n";
1015: exit;
1016: }
1017: } else {
1018: print &mt('Stopping execution.')."\n";
1019: exit;
1020: }
1021: }
1022: }
1023: unless (ref($recommended) eq 'HASH') {
1024: print "\n".&mt('An error occurred determining which actions are recommended.')."\n\n".
1025: &mt('Stopping execution.')."\n";
1026: exit;
1027: }
1028:
1029: print "\n";
1030: my $num = 0;
1031: foreach my $action (@actions) {
1032: $num ++;
1033: my ($yesno,$defaultrun);
1034: if (ref($recommended) eq 'HASH') {
1.4 ! raeburn 1035: if (($action eq 'runlevels') || ($action eq 'stopsrvcs')) {
1.1 raeburn 1036: $yesno = '[y/N]';
1037: if (ref($recommended->{$action}) eq 'HASH') {
1038: if (keys(%{$recommended->{$action}}) > 0) {
1039: $yesno = &mt('~[Y/n~]');
1040: $defaultrun = 1;
1041: }
1042: }
1043: } else {
1044: if ($action eq 'download') {
1045: if ($downloadstatus) {
1046: print "\n$downloadstatus\n";
1047: }
1048: }
1049: if ($recommended->{$action}) {
1050: $yesno = mt('~[Y/n~]');
1051: $defaultrun = 1;
1052: } else {
1053: $yesno = &mt('~[y/N~]');
1054: }
1055: }
1056: print $num.'. '.$prompts{$action}." $yesno ";
1057: $callsub{$action} = &get_user_selection($defaultrun);
1058: }
1059: }
1060:
1061: my $lctarball = 'loncapa-current.tar.gz';
1062: my $sourcetarball = $lctarball;
1063: if ($callsub{'download'}) {
1064: my ($production,$testing,$sizes) = &download_versionslist();
1065: if ($production && $testing) {
1066: if ($production ne $testing) {
1067: print &mt('Two recent LON-CAPA releases are available: ')."\n".
1.3 raeburn 1068: &mt('1.').' '.&mt('A production release - version: [_1].',$production)."\n".
1069: &mt('2.').' '.&mt('A testing release - version: [_1].',$testing)."\n\n".
1.1 raeburn 1070: &mt('Download the production release? ~[Y/n~]');
1071: if (&get_user_selection(1)) {
1.4 ! raeburn 1072: $sourcetarball = 'loncapa-'.$production.'.tar.gz';
1.1 raeburn 1073: } else {
1074: print "\n".&mt('Download the testing release? ~[Y/n~]');
1075: if (&get_user_selection(1)) {
1.4 ! raeburn 1076: $sourcetarball = 'loncapa-'.$testing.'.tar.gz';
1.1 raeburn 1077: }
1078: }
1079: }
1080: } elsif ($production) {
1081: print &mt('The most recent LON-CAPA release is version: [_1].',$production)."\n".
1082: &mt('Download the production release? ~[Y/n~]');
1083: if (&get_user_selection(1)) {
1084: $sourcetarball = $production.'tar.gz';
1085: }
1086: }
1087: } elsif ($filetouse ne '') {
1088: $sourcetarball = $filetouse;
1089: }
1090:
1091: print_and_log("\n");
1092:
1093: # Each action: report if skipping, or perform action and provide feedback.
1094: if ($callsub{'wwwuser'}) {
1095: &setup_www();
1096: } else {
1097: &print_and_log(&mt('Skipping creation of user [_1].',"'www'")."\n");
1098: }
1099:
1100: if ($callsub{'pwauth'}) {
1.4 ! raeburn 1101: &build_and_install_mod_auth_external($instdir);
1.1 raeburn 1102: } else {
1103: &print_and_log(&mt('Skipping [_1] installation.',"'pwauth'")."\n");
1104: }
1105:
1106: if ($callsub{'mysql'}) {
1107: if ($dbh) {
1108: &setup_mysql($callsub{'mysqlperms'},$distro,$dbh,$has_pass,$has_lcdb);
1109: } else {
1110: print &mt('Unable to configure MySQL because access is denied.')."\n";
1111: }
1112: } else {
1113: &print_and_log(&mt('Skipping configuration of MySQL.')."\n");
1114: if ($callsub{'mysqlperms'}) {
1115: if ($dbh) {
1116: &setup_mysql_permissions($dbh,$has_pass);
1117: } else {
1118: print &mt('Unable to configure MySQL because access is denied.')."\n";
1119: }
1120: } else {
1121: &print_and_log(&mt('Skipping MySQL permissions setup.')."\n");
1122: }
1123: }
1124:
1125: if ($dbh) {
1126: if (!$dbh->disconnect) {
1127: &print_and_log(&mt('Failed to disconnect from MySQL:')."\n".
1128: $dbh->errstr);
1129: }
1130: }
1131:
1132: if ($callsub{'apache'}) {
1133: if ($distro =~ /^(suse|sles)/) {
1134: ©_apache2_suseconf($instdir);
1135: } elsif ($distro =~ /^(debian|ubuntu)/) {
1136: ©_apache2_debconf($instdir);
1137: } else {
1138: ©_httpd_conf($instdir);
1139: }
1140: } else {
1141: print_and_log(&mt('Skipping configuration of Apache web server.')."\n");
1142: }
1143:
1144: if ($callsub{'runlevels'}) {
1145: my $count = 0;
1146: if (ref($recommended) eq 'HASH') {
1147: if (ref($recommended->{'runlevels'}) eq 'HASH') {
1148: foreach my $type (keys(%{$recommended->{'runlevels'}})) {
1149: next if ($type eq 'insserv');
1150: $count ++;
1151: my $command = $recommended->{'runlevels'}{$type};
1152: if ($command ne '') {
1153: print_and_log(&mt('Runlevel update command run: [_1].',$command)."\n");
1154: system($command);
1155: }
1156: }
1157: if (!$count) {
1158: print_and_log(&mt('No runlevel updates required.')."\n");
1159: }
1160: }
1161: }
1162: &update_SuSEfirewall2_setup($instdir);
1163: } else {
1164: &print_and_log(&mt('Skipping setting override for start-up order of services.')."\n");
1165: }
1166:
1167: if ($callsub{'firewall'}) {
1168: if ($distro =~ /^(suse|sles)/) {
1169: print &mt('Use [_1].','yast')."\n";
1.4 ! raeburn 1170: } elsif ($distro =~ /^(debian|ubuntu)/) {
1.1 raeburn 1171: print &mt('Use [_1].','ufw')."\n";
1172: } else {
1173: print &mt('Use [_1].','setup')."\n";
1174: }
1175: } else {
1176: if ($distro =~ /^(suse|sles)/) {
1177: &print_and_log(&mt('Skipping Firewall configuration.')."\n");
1178: }
1179: }
1180:
1181: if ($callsub{'stopsrvcs'}) {
1182: &kill_extra_services($distro,$recommended->{'stopsrvcs'});
1183: } else {
1184: &print_and_log(&mt('Skipping stopping unnecessary services ([_1] and [_2] daemons).',"'cups'","'sendmail'")."\n");
1185: }
1186:
1187: my ($have_tarball,$updateshown);
1188: if ($callsub{'download'}) {
1189: ($have_tarball,$updateshown) = &download_loncapa($instdir,$sourcetarball);
1190: } else {
1191: print_and_log(&mt('Skipping download of LON-CAPA tar file.')."\n\n");
1192: print &mt('LON-CAPA is available for download from: [_1]',
1193: 'http://install.loncapa.org/')."\n";
1194: if (!-e '/etc/loncapa-release') {
1195: &print_and_log(&mt('LON-CAPA is not yet installed on your system.').
1196: "\n\n".
1197: &mt('You may retrieve the source for LON-CAPA by executing:')."\n".
1198: "wget http://install.loncapa.org/versions/$lctarball\n");
1199: } else {
1200: my $currentversion;
1201: if (open(my $fh,"</etc/loncapa-release")) {
1202: my $version = <$fh>;
1203: chomp($version);
1204: if ($version =~ /^\QLON-CAPA release \E([\w\-.]+)$/) {
1205: $currentversion = $1;
1206: }
1207: }
1208: if ($currentversion ne '') {
1209: print &mt('Version of LON-CAPA currently installed on this server is: [_1].',
1210: $currentversion),"\n";
1211: if ($production) {
1212: print &mt('The latest production release of LON-CAPA is [_1].',$production)."\n";
1213: }
1214: if ($testing) {
1215: print &mt('The latest testing release of LON-CAPA is [_1].',$testing)."\n";
1216: }
1217: }
1218: }
1219: if ($filetouse ne '') {
1220: $have_tarball = 1;
1221: }
1222: }
1223:
1224: print "\n".&mt('Requested configuration complete.')."\n\n";
1225: my $apachename;
1226: if ($have_tarball && !$updateshown) {
1227: my ($lcdir) = ($sourcetarball =~ /^([\w.\-]+)\.tar.gz$/);
1228: if (!-e '/etc/loncapa-release') {
1229: print &mt('If you are now ready to install LON-CAPA, enter the following commands:')."\n\n";
1230: } else {
1231: print &mt('If you are now ready to update LON-CAPA, enter the following commands:')."\n\n".
1232: "/etc/init.d/loncontrol stop\n";
1233: if ($distro =~ /^(suse|sles|debian|ubuntu)([\d.]+)/) {
1234: if (($1 eq 'suse') && ($2 < 10)) {
1235: $apachename = 'apache';
1236: } else {
1237: $apachename = 'apache2';
1238: }
1239: } else {
1240: $apachename = 'httpd';
1241: }
1242: print "/etc/init.d/$apachename stop\n";
1243: }
1244: print "cd /root\n".
1245: "tar zxf $sourcetarball\n".
1246: "cd $lcdir\n".
1247: "./UPDATE\n";
1248: if (-e '/etc/loncapa-release') {
1249: print "/etc/init.d/loncontrol start\n";
1250: print "/etc/init.d/$apachename start\n";
1251: }
1252: }
1253: exit;
1254:
1255: #
1256: # End main script
1257: #
1258:
1259: #
1260: # Routines for the actions
1261: #
1262:
1263: sub setup_www {
1264: ##
1265: ## Set up www
1266: ##
1267: print_and_log(&mt('Creating user [_1]',"'www'")."\n");
1268: # -- Add group
1269:
1270: my $status = `/usr/sbin/groupadd www`;
1271: if ($status =~ /\QGroup `www' already exists.\E/) {
1272: print &mt('Group [_1] already exists.',"'www'")."\n";
1273: } elsif ($status ne '') {
1274: print &mt('Unable to add group [_1].',"'www'")."\n";
1275: }
1276:
1277: my $gid = getgrnam('www');
1278:
1279: if (open (PIPE, "/usr/sbin/useradd -c LONCAPA -g $gid www 2>&1 |")) {
1280: $status = <PIPE>;
1281: close(PIPE);
1282: chomp($status);
1283: if ($status =~ /\QAccount `www' already exists.\E/) {
1284: print &mt('Account [_1] already exists.',"'www'")."\n";
1285: } elsif ($status ne '') {
1286: print &mt('Unable to add user [_1].',"'www'")."\n";
1287: }
1288: } else {
1289: print &mt('Unable to run command to add user [_1].',"'www'")."\n";
1290: }
1291:
1292: my $uid = &uid_of_www();
1293: if (($gid ne '') && ($uid ne '')) {
1294: if (!-e '/home/www') {
1295: mkdir('/home/www',0755);
1296: system('chown www:www /home/www');
1297: }
1298: }
1299: writelog ($status);
1300: }
1301:
1302: sub uid_of_www {
1303: my ($num) = (getpwnam('www'))[2];
1304: return $num;
1305: }
1306:
1307: sub build_and_install_mod_auth_external {
1308: my ($instdir) = @_;
1309: my $num = &uid_of_www();
1310: # Patch pwauth
1311: print_and_log(&mt('Building authentication system for LON-CAPA users.')."\n");
1312: my $patch = <<"ENDPATCH";
1313: 148c148
1314: < #define SERVER_UIDS 99 /* user "nobody" */
1315: ---
1316: > #define SERVER_UIDS $num /* user "www" */
1317: ENDPATCH
1318:
1319: if (! -e "/usr/bin/patch") {
1320: print_and_log(&mt('You must install the software development tools package: [_1], when installing Linux.',"'patch'")."\n");
1321: print_and_log(&mt('Authentication installation not completed.')."\n");
1322: return;
1323: }
1324: if (&skip_if_nonempty(`cd /tmp; tar zxf $instdir/pwauth-2.2.8.tar.gz`,
1325: &mt('Unable to extract pwauth')."\n")) {
1326: return;
1327: }
1328: my $dir = "/tmp/pwauth-2.2.8";
1329: if (open(PATCH,"| patch $dir/config.h")) {
1330: print PATCH $patch;
1331: close(PATCH);
1332: print_and_log("\n");
1333: ##
1334: ## Compile patched pwauth
1335: ##
1336: print_and_log(&mt('Compiling pwauth')."\n");
1337: my $result = `cd $dir/; make`;
1338: my $expected = <<"END";
1339: gcc -g -c -o pwauth.o pwauth.c
1340: gcc -o pwauth -g pwauth.o -lcrypt
1341: END
1342: if ($result eq $expected) {
1343: print_and_log(&mt('Apparent success compiling pwauth:').
1344: "\n".$result );
1345: # Install patched pwauth
1346: print_and_log(&mt('Copying pwauth to [_1]',' /usr/local/sbin')."\n");
1347: if (copy "$dir/pwauth","/usr/local/sbin/pwauth") {
1348: if (chmod (06755, "/usr/local/sbin/pwauth")) {
1349: print_and_log(&mt('[_1] copied successfully',"'pwauth'").
1350: "\n");
1351: } else {
1352: print &mt('Unable to set permissions on [_1].'.
1353: "/usr/local/sbin/pwauth")."\n";
1354: }
1355: } else {
1356: print &mt('Unable to copy [_1] to [_2]',
1357: "'$dir/pwauth'","/usr/local/sbin/pwauth")."\n$!\n";
1358: }
1359: } else {
1360: print &mt('Unable to compile patched [_1].'."'pwauth'")."\n";
1361: }
1362: } else {
1363: print &mt('Unable to start patch for [_1]',"'pwauth'")."\n";
1364: }
1365: print_and_log("\n");
1366: }
1367:
1368: sub kill_extra_services {
1369: my ($distro,$stopsrvcs) = @_;
1370: if (ref($stopsrvcs) eq 'HASH') {
1371: my @stopping = sort(keys(%{$stopsrvcs}));
1372: if (@stopping) {
1373: my $kill_list = join("',' ",@stopping);
1374: if ($kill_list) {
1375: $kill_list = "'".$kill_list."'";
1376: &print_and_log("\n".&mt('Killing unneccessary services ([_1] daemon(s)).',$kill_list)."\n");
1377: foreach my $daemon (@stopping) {
1378: my $service = $daemon;
1379: &print_and_log(`/etc/init.d/$service stop`);
1380: &print_and_log(&mt('Removing [_1] from startup.',$service)."\n");
1381: if ($daemon eq 'cupsd') {
1382: $service = 'cups';
1383: }
1.4 ! raeburn 1384: if ($distro =~ /^(debian|ubuntu)/) {
1.1 raeburn 1385: &print_and_log(`/usr/sbin/sysv-rc-conf $service off`);
1386: } else {
1387: &print_and_log(`chkconfig --del $service`);
1388: }
1389: }
1390: }
1391: }
1392: }
1393: return;
1394: }
1395:
1396: sub setup_mysql {
1397: my ($setup_mysql_permissions,$distro,$dbh,$has_pass,$has_lcdb) = @_;
1.4 ! raeburn 1398: my @mysql_lc_commands;
1.1 raeburn 1399: unless ($has_lcdb) {
1.4 ! raeburn 1400: push(@mysql_lc_commands,"CREATE DATABASE loncapa");
1.1 raeburn 1401: }
1.4 ! raeburn 1402: push(@mysql_lc_commands,"USE loncapa");
! 1403: push(@mysql_lc_commands,qq{
! 1404: CREATE TABLE IF NOT EXISTS metadata (title TEXT, author TEXT, subject TEXT, url TEXT, keywords TEXT, version TEXT, notes TEXT, abstract TEXT, mime TEXT, language TEXT, creationdate DATETIME, lastrevisiondate DATETIME, owner TEXT, copyright TEXT, FULLTEXT idx_title (title), FULLTEXT idx_author (author), FULLTEXT idx_subject (subject), FULLTEXT idx_url (url), FULLTEXT idx_keywords (keywords), FULLTEXT idx_version (version), FULLTEXT idx_notes (notes), FULLTEXT idx_abstract (abstract), FULLTEXT idx_mime (mime), FULLTEXT idx_language (language), FULLTEXT idx_owner (owner), FULLTEXT idx_copyright (copyright)) TYPE=MYISAM
! 1405: });
1.1 raeburn 1406: if ($setup_mysql_permissions) {
1.4 ! raeburn 1407: &setup_mysql_permissions($dbh,$has_pass,@mysql_lc_commands);
1.1 raeburn 1408: } else {
1409: print_and_log(&mt('Skipping MySQL permissions setup.')."\n");
1410: if ($dbh) {
1.4 ! raeburn 1411: if (@mysql_lc_commands) {
! 1412: foreach my $lccmd (@mysql_lc_commands) {
! 1413: $dbh->do($lccmd) || print $dbh->errstr."\n";
! 1414: }
! 1415: }
1.1 raeburn 1416: print_and_log(&mt('MySQL database set up complete.')."\n");
1417: } else {
1418: print_and_log(&mt('Problem accessing MySQL.')."\n");
1419: }
1420: }
1421: }
1422:
1423: sub setup_mysql_permissions {
1.4 ! raeburn 1424: my ($dbh,$has_pass,@mysql_lc_commands) = @_;
1.1 raeburn 1425: my $mysqlversion = &get_mysql_version();
1.4 ! raeburn 1426: my @mysql_commands = ("INSERT user (Host, User, Password) VALUES('localhost','www',password('localhostkey'));");
1.1 raeburn 1427: if ($mysqlversion < 4) {
1.4 ! raeburn 1428: push (@mysql_commands,"
! 1429: INSERT db (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Grant_priv,References_priv,Index_priv,Alter_priv) VALUES('localhost','loncapa','www','Y','Y','Y','Y','Y','Y','N','Y','Y','Y')");
! 1430: } else {
! 1431: push (@mysql_commands,"
! 1432: INSERT db (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Grant_priv,References_priv,Index_priv,Alter_priv,Create_tmp_table_priv,Lock_tables_priv) VALUES('localhost','loncapa','www','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y')");
1.1 raeburn 1433: }
1.4 ! raeburn 1434: push(@mysql_commands,"DELETE FROM user WHERE host<>'localhost'");
1.1 raeburn 1435: if ($has_pass) {
1436: if ($dbh) {
1.4 ! raeburn 1437: push(@mysql_commands,"FLUSH PRIVILEGES");
! 1438: if (@mysql_commands) {
! 1439: foreach my $cmd (@mysql_commands) {
! 1440: $dbh->do($cmd) || print $dbh->errstr."\n";
! 1441: }
! 1442: }
! 1443: if (@mysql_lc_commands) {
! 1444: foreach my $lccmd (@mysql_lc_commands) {
! 1445: $dbh->do($lccmd) || print $dbh->errstr."\n";
! 1446: }
! 1447: }
1.1 raeburn 1448: print_and_log(&mt('Permissions set for LON-CAPA MySQL user: [_1]',"'www'")."\n");
1449: } else {
1450: print_and_log(&mt('Problem accessing MySQL.')."\n".
1451: &mt('Permissions not set.')."\n");
1452: }
1453: } else {
1454: my ($firstpass,$secondpass,$got_passwd,$newmysqlpass);
1455: print &mt('Please enter a root password for the mysql database.')."\n".
1456: &mt('It does not have to match your root account password, but you will need to remember it.')."\n";
1457: my $maxtries = 10;
1458: my $trial = 0;
1459: while ((!$got_passwd) && ($trial < $maxtries)) {
1460: $firstpass = &get_mysql_password(&mt('Enter password'));
1461: if (length($firstpass) > 5) {
1462: $secondpass = &get_mysql_password(&mt('Enter password a second time'));
1463: if ($firstpass eq $secondpass) {
1464: $got_passwd = 1;
1465: $newmysqlpass = $firstpass;
1466: } else {
1467: print(&mt('Passwords did not match. Please try again.')."\n");
1468: }
1469: $trial ++;
1470: } else {
1471: print(&mt('Password too short.')."\n".
1472: &mt('Please choose a password with at least six characters.')."\n");
1473: }
1474: }
1475: if ($got_passwd) {
1.4 ! raeburn 1476: my (@newpass_cmds) = &new_mysql_rootpasswd($newmysqlpass);
! 1477: push(@mysql_commands,@newpass_cmds);
1.1 raeburn 1478: } else {
1479: print_and_log(&mt('Failed to get MySQL root password from user input.')."\n");
1480: }
1481: if ($dbh) {
1.4 ! raeburn 1482: if (@mysql_commands) {
! 1483: foreach my $cmd (@mysql_commands) {
! 1484: $dbh->do($cmd) || print $dbh->errstr."\n";
! 1485:
! 1486: }
! 1487: }
! 1488: if (@mysql_lc_commands) {
! 1489: foreach my $lccmd (@mysql_lc_commands) {
! 1490: $dbh->do($lccmd) || print $dbh->errstr."\n";
! 1491: }
! 1492: }
1.1 raeburn 1493: if ($got_passwd) {
1494: print_and_log(&mt('MySQL root password stored.')."\n".
1495: &mt('Permissions set for LON-CAPA MySQL user: [_1].',"'www'")."\n");
1496: } else {
1497: print_and_log(&mt('Permissions set for LON-CAPA MySQL user: [_1].',"'www'")."\n");
1498: }
1499: } else {
1500: print_and_log(&mt('Problem accessing MySQL.')."\n".
1501: &mt('Permissions not set.')."\n");
1502: }
1503: }
1504: }
1505:
1506: sub new_mysql_rootpasswd {
1507: my ($currmysqlpass) = @_;
1.4 ! raeburn 1508: return ("SET PASSWORD FOR 'root'\@'localhost'=PASSWORD('$currmysqlpass')",
! 1509: "FLUSH PRIVILEGES;");
1.1 raeburn 1510: }
1511:
1512: sub get_mysql_version {
1513: my $version;
1514: if (open(PIPE," mysql -V |")) {
1515: my $info = <PIPE>;
1516: chomp($info);
1517: close(PIPE);
1518: ($version) = ($info =~ /(\d+\.\d+)\.\d+,/);
1519: } else {
1520: print &mt('Could not determine which version of MySQL is installed.').
1521: "\n";
1522: }
1523: return $version;
1524: }
1525:
1526: ###########################################################
1527: ##
1528: ## RHEL/CentOS/Fedora/Scientific Linux
1529: ## Copy LON-CAPA httpd.conf to /etc/httpd/conf
1530: ##
1531: ###########################################################
1532:
1533: sub copy_httpd_conf {
1534: my ($instdir) = @_;
1535: print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',"'httpd.conf'",
1536: "'/etc/httpd/conf/httpd.conf'")."\n");
1537: copy "/etc/httpd/conf/httpd.conf","/etc/httpd/conf/httpd.conf.original";
1538: copy "$instdir/httpd.conf","/etc/httpd/conf/httpd.conf";
1539: chmod 0444,"/etc/httpd/conf/httpd.conf";
1540: print_and_log("\n");
1541: }
1542:
1543: #########################################################
1544: ##
1545: ## Ubuntu/Debian -- copy our apache2 configuration file to
1546: ## sites-available and set the symlink from sites-enabled.
1547: ##
1548: #########################################################
1549:
1550: sub copy_apache2_debconf {
1551: my ($instdir) = @_;
1.4 ! raeburn 1552: print_and_log(&mt('Copying loncapa [_1] config file to [_2] and pointing [_3] to it from sites-enabled.',"'apache2'","'/etc/apache2/sites-available'","'000-default symlink'")."\n");
1.1 raeburn 1553: my $apache2_enabled_dir = '/etc/apache2/sites-enabled';
1554: my $apache2_available_dir = '/etc/apache2/sites-available';
1555: if (-l "$apache2_enabled_dir/000-default") {
1556: unlink("$apache2_enabled_dir/000-default");
1557: }
1558: if (-e "$apache2_available_dir/loncapa") {
1559: copy("$apache2_available_dir/loncapa","$apache2_available_dir/loncapa.original");
1560: }
1561: copy("$instdir/apache2.conf","$apache2_available_dir/loncapa");
1562: chmod(0444,"$apache2_available_dir/loncapa");
1563: symlink("$apache2_available_dir/loncapa","$apache2_enabled_dir/000-default");
1564: print_and_log("\n");
1565: }
1566:
1567: ###########################################################
1568: ##
1569: ## openSuSE/SLES Copy apache2 config files:
1570: ## default-server.conf, uid.conf, /etc/sysconfig/apache2
1571: ## and create symlink from /srv/www/conf to /etc/apache2
1572: ##
1573: ###########################################################
1574:
1575: sub copy_apache2_suseconf {
1576: my ($instdir) = @_;
1577: print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',
1578: "'default-server.conf'",
1579: "'/etc/apache2/default-server.conf'")."\n");
1580: if (!-e "/etc/apache2/default-server.conf.original") {
1581: copy "/etc/apache2/default-server.conf","/etc/apache2/default-server.conf.original";
1582: }
1583: copy "$instdir/default-server.conf","/etc/apache2/default-server.conf";
1584: chmod 0444,"/etc/apache2/default-server.conf";
1585: # Make symlink for conf directory (included in loncapa_apache.conf)
1586: my $can_symlink = (eval { symlink('/etc/apache2','/srv/www/conf'); }, $@ eq '');
1587: if ($can_symlink) {
1588: &print_and_log(&mt('Symlink created for [_1] to [_2].',
1589: "'/srv/www/conf'","'/etc/apache2'")."\n");
1590: } else {
1591: &print_and_log(&mt('Symlink creation failed for [_1] to [_2]. You will need to perform this action from the command line.',"'/srv/www/conf'","'/etc/apache2'")."\n");
1592: }
1593: ©_apache2_conf_files($instdir);
1594: ©_sysconfig_apache2_file($instdir);
1595: print_and_log("\n");
1596: }
1597:
1598: ###############################################
1599: ##
1600: ## Modify uid.conf
1601: ##
1602: ###############################################
1603: sub copy_apache2_conf_files {
1604: my ($instdir) = @_;
1605: print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',
1606: "'uid.conf'","'/etc/apache2/uid.conf'")."\n");
1607: if (!-e "/etc/apache2/uid.conf.original") {
1608: copy "/etc/apache2/uid.conf","/etc/apache2/uid.conf.original";
1609: }
1610: copy "$instdir/uid.conf","/etc/apache2/uid.conf";
1611: chmod 0444,"/etc/apache2/uid.conf";
1612: }
1613:
1614: ###############################################
1615: ##
1616: ## Modify /etc/sysconfig/apache2
1617: ##
1618: ###############################################
1619: sub copy_sysconfig_apache2_file {
1620: my ($instdir) = @_;
1621: print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',"'sysconfig/apache2'","'/etc/sysconfig/apache2'")."\n");
1622: if (!-e "/etc/sysconfig/apache2.original") {
1623: copy "/etc/sysconfig/apache2","/etc/sysconfig/apache2.original";
1624: }
1625: copy "$instdir/sysconfig_apache2","/etc/sysconfig/apache2";
1626: chmod 0444,"/etc/sysconfig/apache2";
1627: }
1628:
1629: ###############################################
1630: ##
1631: ## Add/Modify /etc/insserv/overrides
1632: ##
1633: ###############################################
1634:
1635: sub update_SuSEfirewall2_setup {
1636: my ($instdir) = @_;
1637: print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',"'SuSEfirewall2_setup'","'/etc/insserv/overrides/SuSEfirewall2_setup'")."\n");
1638: if (!-e "/etc/insserv/overrides/SuSEfirewall2_setup") {
1639: if (!-d "/etc/insserv") {
1640: mkdir("/etc/insserv",0755);
1641: }
1642: if (!-d "/etc/insserv/overrides") {
1643: mkdir("/etc/insserv/overrides",0755);
1644: }
1645: } elsif (!-e "/etc/insserv/overrides/SuSEfirewall2_setup.original") {
1646: copy "/etc/insserv/overrides/SuSEfirewall2_setup","/etc/insserv/overrides/SuSEfirewall2_setup.original"
1647: }
1648: copy "$instdir/SuSEfirewall2_setup","/etc/insserv/overrides/SuSEfirewall2_setup";
1649: chmod 0444,"/etc/insserv/overrides/SuSEfirewall2_setup";
1650: }
1651:
1652: sub download_loncapa {
1653: my ($instdir,$lctarball) = @_;
1654: my ($have_tarball,$updateshown);
1655: if (! -e "$instdir/$lctarball") {
1656: print_and_log(&mt('Retrieving LON-CAPA source files from: [_1]',
1657: 'http://install.loncapa.org')."\n");
1658: system("wget http://install.loncapa.org/versions/$lctarball ".
1659: "2>/dev/null 1>/dev/null");
1660: if (! -e "./$lctarball") {
1661: print &mt('Unable to retrieve LON-CAPA source files from: [_1].',
1662: "http://install.loncapa.org/versions/$lctarball")."\n";
1663: } else {
1664: $have_tarball = 1;
1665: }
1666: print_and_log("\n");
1667: } else {
1668: $have_tarball = 1;
1669: print_and_log("
1670: ------------------------------------------------------------------------
1671:
1672: ".&mt('You seem to have a version of loncapa-current.tar.gz in [_1]',$instdir)."\n".
1673: &mt('This copy will be used and a new version will NOT be downloaded.')."\n".
1674: &mt('If you wish, you may download a new version by executing:')."
1675:
1.2 raeburn 1676: wget http://install.loncapa.org/versions/loncapa-current.tar.gz
1.1 raeburn 1677:
1678: ------------------------------------------------------------------------
1679: ");
1680: }
1681:
1682: ##
1683: ## untar loncapa.tar.gz
1684: ##
1685: if ($have_tarball) {
1686: print_and_log(&mt('Extracting LON-CAPA source files')."\n");
1687: writelog(`cd ~root; tar zxf $instdir/$lctarball`);
1688: print_and_log("\n");
1689: print &mt('LON-CAPA source files extracted.')."\n".
1690: &mt('It remains for you to execute the following commands:')."
1691:
1692: cd /root/loncapa-N.N (N.N should correspond to a version number like '0.4')
1693: ./UPDATE
1694:
1695: ".&mt('If you have any trouble, please see [_1] and [_2]',
1696: 'http://install.loncapa.org/','http://help.loncapa.org/')."\n";
1697: $updateshown = 1;
1698: }
1699: return ($have_tarball,$updateshown);
1700: }
1701:
1702: close LOG;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>