Annotation of doc/install/linux/install.pl, revision 1.13
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.13 ! raeburn 75: print LOG '$Id: install.pl,v 1.12 2011/05/08 13:20:03 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';
1.11 raeburn 198: } elsif ($versionstring =~ /Scientific Linux (SL )?release ([\d.]+) /) {
1.1 raeburn 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;
1.12 raeburn 222: $updatecmd = 'yast -i LONCAPA-prerequisites';
1.1 raeburn 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);
1.8 raeburn 296: if ($line =~ /^LONCAPA\-prerequisites\-([\d\-]+)\.(?:[.\w]+)$/) {
1.1 raeburn 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:
1.6 raeburn 308: sub check_locale {
309: my ($distro) = @_;
1.8 raeburn 310: my ($fh,$langvar,$command);
311: $langvar = 'LANG';
1.6 raeburn 312: if ($distro =~ /^(ubuntu|debian)/) {
313: if (!open($fh,"</etc/default/locale")) {
314: print &mt('Failed to open: [_1], default locale not checked.',
315: '/etc/default/locale');
316: }
1.8 raeburn 317: } elsif ($distro =~ /^(suse|sles)/) {
318: if (!open($fh,"</etc/sysconfig/language")) {
319: print &mt('Failed to open: [_1], default locale not checked.',
320: '/etc/sysconfig/language');
321: }
322: $langvar = 'RC_LANG';
1.6 raeburn 323: } else {
324: if (!open($fh,"</etc/sysconfig/i18n")) {
325: print &mt('Failed to open: [_1], default locale not checked.',
326: '/etc/sysconfig/i18n');
327: }
328: }
329: my @data = <$fh>;
330: chomp(@data);
331: foreach my $item (@data) {
1.8 raeburn 332: if ($item =~ /^\Q$langvar\E=\"([^\"]*)\"/) {
1.6 raeburn 333: my $default = $1;
334: if ($default ne 'en_US.UTF-8') {
335: if ($distro =~ /^debian/) {
336: $command = 'dpkg-reconfigure locales';
337: } elsif ($distro =~ /^ubuntu/) {
338: $command = 'sudo set-language-env -E';
1.7 raeburn 339: } elsif ($distro =~ /^(suse|sles)/) {
340: $command = 'yast language';
1.6 raeburn 341: } else {
342: $command = 'system-config-language';
343: }
344: }
345: last;
346: }
347: }
348: close($fh);
349: return $command;
350: }
351:
1.1 raeburn 352: sub check_required {
353: my ($instdir,$dsn) = @_;
354: my ($distro,$packagecmd,$updatecmd,$installnow) = &get_distro();
355: if ($distro eq '') {
356: return;
357: }
358: my $gotprereqs = &check_prerequisites($packagecmd,$distro);
359: if ($gotprereqs eq '') {
1.6 raeburn 360: return ($distro,$gotprereqs);
361: }
362: my $localecmd = &check_locale($distro);
363: unless ($localecmd eq '') {
364: return ($distro,$gotprereqs,$localecmd);
1.1 raeburn 365: }
366: my ($mysqlon,$mysqlsetup,$dbh,$has_pass,$has_lcdb,%recommended,$downloadstatus,
1.5 raeburn 367: $filetouse,$production,$testing,$apachefw,$tostop);
1.1 raeburn 368: my $wwwuid = &uid_of_www();
369: my $wwwgid = getgrnam('www');
370: if (($wwwuid eq '') || ($wwwgid eq '')) {
371: $recommended{'wwwuser'} = 1;
372: }
373: unless( -e "/usr/local/sbin/pwauth") {
374: $recommended{'pwauth'} = 1;
375: }
376: $mysqlon = &check_mysql_running($distro);
377: if ($mysqlon) {
378: my $mysql_has_wwwuser = &check_mysql_wwwuser();
379: ($mysqlsetup,$has_pass,$dbh) =
380: &check_mysql_setup($instdir,$dsn);
381: if ($mysqlsetup eq 'noroot') {
382: $recommended{'mysqlperms'} = 1;
383: } else {
384: unless ($mysql_has_wwwuser) {
385: $recommended{'mysqlperms'} = 1;
386: }
387: }
388: if ($dbh) {
389: $has_lcdb = &check_loncapa_mysqldb($dbh);
390: }
391: unless ($has_lcdb) {
392: $recommended{'mysql'} = 1;
393: }
394: }
1.5 raeburn 395: ($recommended{'firewall'},$apachefw) = &chkfirewall($distro);
1.8 raeburn 396: ($recommended{'runlevels'},$tostop) = &chkconfig($distro,$instdir);
1.1 raeburn 397: $recommended{'apache'} = &chkapache($distro,$instdir);
398: $recommended{'stopsrvcs'} = &chksrvcs($distro,$tostop);
399: ($recommended{'download'},$downloadstatus,$filetouse,$production,$testing)
400: = &need_download();
1.6 raeburn 401: return ($distro,$gotprereqs,$localecmd,$packagecmd,$updatecmd,$installnow,
1.1 raeburn 402: \%recommended,$dbh,$has_pass,$has_lcdb,$downloadstatus,
1.5 raeburn 403: $filetouse,$production,$testing,$apachefw);
1.1 raeburn 404: }
405:
406: sub check_mysql_running {
407: my ($distro) = @_;
408: my $mysqldaemon ='mysqld';
409: if ($distro =~ /^(suse|sles|debian|ubuntu)/) {
410: $mysqldaemon = 'mysql';
411: }
1.6 raeburn 412: my $process = 'mysqld_safe';
413: my $proc_owner = 'root';
414: if ($distro =~ /^ubuntu(\w+)/) {
415: if ($1 >= 10) {
416: $process = 'mysqld';
417: $proc_owner = 'mysql';
418: }
419: }
420: if (open(PIPE,"ps -ef |grep $process |grep -v grep 2>&1 |")) {
1.1 raeburn 421: my $status = <PIPE>;
422: close(PIPE);
423: chomp($status);
1.6 raeburn 424: if ($status =~ /^\Q$proc_owner\E\s+\d+\s+/) {
1.1 raeburn 425: print_and_log(&mt('MySQL is running.')."\n");
426: return 1;
427: } else {
1.12 raeburn 428: system("/etc/init.d/$mysqldaemon start >/dev/null 2>&1 ");
1.1 raeburn 429: print_and_log(&mt('Waiting for MySQL to start.')."\n");
430: sleep 5;
1.12 raeburn 431: if (open(PIPE,"ps -ef |grep $process |grep -v grep 2>&1 |")) {
432: $status = <PIPE>;
1.1 raeburn 433: close(PIPE);
434: chomp($status);
1.12 raeburn 435: if ($status =~ /^\Q$proc_owner\E\s+\d+\s+/) {
1.1 raeburn 436: print_and_log(&mt('MySQL is running.')."\n");
437: return 1;
438: } else {
1.12 raeburn 439: print_and_log(&mt('Still waiting for MySQL to start.')."\n");
440: sleep 5;
441: if (open(PIPE,"ps -ef |grep $process |grep -v grep 2>&1 |")) {
442: $status = <PIPE>;
443: close(PIPE);
444: chomp($status);
445: if ($status =~ /^\Q$proc_owner\E\s+\d+\s+/) {
446: print_and_log(&mt('MySQL is running.')."\n");
447: return 1;
448: } else {
449: print_and_log(&mt('Given up waiting for MySQL to start.')."\n");
450: }
451: }
1.1 raeburn 452: }
453: }
454: }
455: } else {
456: print &mt('Could not determine if MySQL is running.')."\n";
457: }
458: return;
459: }
460:
461: sub chkconfig {
1.8 raeburn 462: my ($distro,$instdir) = @_;
1.1 raeburn 463: my (%needfix,%tostop);
464: my $checker_bin = '/sbin/chkconfig';
1.6 raeburn 465: my %daemon = (
466: mysql => 'mysqld',
467: apache => 'httpd',
468: cups => 'cups',
469: ntp => 'ntpd',
470: memcached => 'memcached',
471: );
1.1 raeburn 472: my @runlevels = qw/3 4 5/;
473: my @norunlevels = qw/0 1 6/;
474: if ($distro =~ /^(suse|sles)/) {
475: @runlevels = qw/3 5/;
476: @norunlevels = qw/0 2 1 6/;
1.6 raeburn 477: $daemon{'mysql'} = 'mysql';
478: $daemon{'apache'} = 'apache2';
1.8 raeburn 479: $daemon{'ntp'} = 'ntp';
1.1 raeburn 480: if ($distro =~ /^(suse|sles)9/) {
1.6 raeburn 481: $daemon{'apache'} = 'apache';
1.1 raeburn 482: }
1.6 raeburn 483: } elsif ($distro =~ /^(?:debian|ubuntu)(\d+)/) {
484: my $version = $1;
1.1 raeburn 485: @runlevels = qw/2 3 4 5/;
486: @norunlevels = qw/0 1 6/;
487: $checker_bin = '/usr/sbin/sysv-rc-conf';
1.6 raeburn 488: $daemon{'mysql'} = 'mysql';
489: $daemon{'apache'} = 'apache2';
490: $daemon{'ntp'} = 'ntp';
491: if (($distro =~ /^ubuntu/) && ($version <= 8)) {
492: $daemon{'cups'} = 'cupsys';
493: }
1.1 raeburn 494: }
495: if (! -x $checker_bin) {
1.6 raeburn 496: print &mt('Could not check runlevel status for MySQL or Apache')."\n";
1.1 raeburn 497: return;
498: }
499: my $rlstr = join('',@runlevels);
500: my $nrlstr = join('',@norunlevels);
1.6 raeburn 501: foreach my $type ('apache','mysql','ntp','cups','memcached') {
502: my $service = $daemon{$type};
1.11 raeburn 503: my $command = $checker_bin.' --list '.$service.' 2>/dev/null';
1.6 raeburn 504: if ($type eq 'cups') {
505: if ($distro =~ /^(?:debian|ubuntu)(\d+)/) {
506: my $version = $1;
507: if (($distro =~ /^ubuntu/) && ($version <= 8)) {
1.11 raeburn 508: $command = $checker_bin.' --list cupsys 2>/dev/null';
1.6 raeburn 509: }
510: }
1.1 raeburn 511: }
512: my $results = `$command`;
513: my $tofix;
514: if ($results eq '') {
1.6 raeburn 515: if (($type eq 'apache') || ($type eq 'mysql') || ($type eq 'ntp')) {
1.1 raeburn 516: if ($distro =~ /^(debian|ubuntu)/) {
1.6 raeburn 517: $tofix = "update-rc.d $type defaults";
1.1 raeburn 518: } else {
519: $tofix = "$checker_bin --add $service\n";
520: }
521: }
522: } else {
523: my %curr_runlevels;
524: for (my $rl=0; $rl<=6; $rl++) {
525: if ($results =~ /$rl:on/) { $curr_runlevels{$rl}++; }
526: }
1.5 raeburn 527: if (($type eq 'apache') || ($type eq 'mysql') || ($type eq 'ntp')) {
1.1 raeburn 528: my $warning;
529: foreach my $rl (@runlevels) {
530: if (!exists($curr_runlevels{$rl})) {
531: $warning = 1;
532: }
533: }
534: if ($warning) {
535: $tofix = "$checker_bin --level $rlstr $service on\n";
536: }
537: } elsif (keys(%curr_runlevels) > 0) {
538: $tostop{$type} = 1;
539: }
540: }
541: if ($tofix) {
542: $needfix{$type} = $tofix;
1.5 raeburn 543: }
1.1 raeburn 544: }
545: if ($distro =~ /^(suse|sles)([\d\.]+)$/) {
546: my $name = $1;
547: my $version = $2;
548: my ($major,$minor);
549: if ($name eq 'suse') {
550: ($major,$minor) = split(/\./,$version);
551: } else {
552: $major = $version;
553: }
554: if ($major > 10) {
1.8 raeburn 555: if (&check_SuSEfirewall2_setup($instdir)) {
556: $needfix{'insserv'} = 1;
557: }
1.1 raeburn 558: }
559: }
560: return (\%needfix,\%tostop);
561: }
562:
563: sub chkfirewall {
1.5 raeburn 564: my ($distro) = @_;
1.1 raeburn 565: my $configfirewall = 1;
566: my %ports = (
567: http => 80,
568: https => 443,
569: );
1.5 raeburn 570: my %activefw;
1.1 raeburn 571: if (&firewall_is_active()) {
572: my $iptables = &get_pathto_iptables();
573: if ($iptables eq '') {
574: print &mt('Firewall not checked as path to iptables not determined.')."\n";
575: } else {
1.5 raeburn 576: my @fwchains = &get_fw_chains($iptables,$distro);
1.1 raeburn 577: if (@fwchains) {
578: foreach my $service ('http','https') {
579: foreach my $fwchain (@fwchains) {
580: if (&firewall_is_port_open($iptables,$fwchain,$ports{$service})) {
581: $activefw{$service} = 1;
582: last;
583: }
584: }
585: }
586: if ($activefw{'http'}) {
587: $configfirewall = 0;
588: }
589: } else {
590: print &mt('Firewall not checked as iptables Chains not identified.')."\n";
591: }
592: }
593: } else {
594: print &mt('Firewall not enabled.')."\n";
595: }
1.5 raeburn 596: return ($configfirewall,\%activefw);
1.1 raeburn 597: }
598:
599: sub chkapache {
600: my ($distro,$instdir) = @_;
601: my $fixapache = 1;
602: if ($distro =~ /^(debian|ubuntu)/) {
1.9 raeburn 603: if (!-e "$instdir/debian-ubuntu/apache2.conf") {
1.1 raeburn 604: $fixapache = 0;
605: print &mt('Warning: No LON-CAPA Apache configuration file found for installation check.')."\n";
1.9 raeburn 606: } elsif ((-e "/etc/apache2/sites-available/loncapa") && (-e "$instdir/debian-ubuntu/apache2.conf")) {
607: if (open(PIPE, "diff --brief $instdir/debian-ubuntu/apache2.conf /etc/apache2/sites-available/loncapa |")) {
1.1 raeburn 608: my $diffres = <PIPE>;
609: close(PIPE);
610: chomp($diffres);
611: unless ($diffres) {
612: $fixapache = 0;
613: }
614: }
615: }
1.6 raeburn 616: if (!$fixapache) {
617: foreach my $module ('headers.load','expires.load') {
618: unless (-l "/etc/apache2/mods-enabled/$module") {
619: $fixapache = 1;
620: }
621: }
622: }
1.1 raeburn 623: } elsif ($distro =~ /^(?:suse|sles)([\d\.]+)$/) {
624: my $apache = 'apache';
625: if ($1 >= 10) {
1.8 raeburn 626: $apache = 'apache2';
1.1 raeburn 627: }
1.9 raeburn 628: if (!-e "$instdir/sles-suse/default-server.conf") {
1.1 raeburn 629: $fixapache = 0;
630: print &mt('Warning: No LON-CAPA Apache configuration file found for installation check.')."\n";
1.9 raeburn 631: } elsif ((-e "/etc/$apache/default-server.conf") && (-e "$instdir/sles-suse/default-server.conf")) {
632: if (open(PIPE, "diff --brief $instdir/sles-suse/default-server.conf /etc/$apache/default-server.conf |")) {
633: my $diffres = <PIPE>;
634: close(PIPE);
635: chomp($diffres);
636: unless ($diffres) {
637: $fixapache = 0;
638: }
639: }
640: }
641: } elsif ($distro eq 'rhes4') {
642: if (!-e "$instdir/rhes4/httpd.conf") {
643: $fixapache = 0;
644: print &mt('Warning: No LON-CAPA Apache configuration file found for installation check.')."\n";
645: } elsif ((-e "/etc/httpd/conf/httpd.conf") && (-e "$instdir/rhes4/httpd.conf")) {
646: if (open(PIPE, "diff --brief $instdir/rhes4/httpd.conf /etc/httpd/conf/httpd.conf |")) {
1.1 raeburn 647: my $diffres = <PIPE>;
648: close(PIPE);
649: chomp($diffres);
650: unless ($diffres) {
651: $fixapache = 0;
652: }
653: }
654: }
655: } else {
1.9 raeburn 656: if (!-e "$instdir/centos-rhes-fedora-sl/httpd.conf") {
1.1 raeburn 657: $fixapache = 0;
658: print &mt('Warning: No LON-CAPA Apache configuration file found for installation check.')."\n";
1.9 raeburn 659: } elsif ((-e "/etc/httpd/conf/httpd.conf") && (-e "$instdir/centos-rhes-fedora-sl/httpd.conf")) {
660: if (open(PIPE, "diff --brief $instdir/centos-rhes-fedora-sl/httpd.conf /etc/httpd/conf/httpd.conf |")) {
1.1 raeburn 661: my $diffres = <PIPE>;
662: close(PIPE);
663: chomp($diffres);
664: unless ($diffres) {
665: $fixapache = 0;
666: }
667: }
668: }
669: }
670: return $fixapache;
671: }
672:
673: sub chksrvcs {
674: my ($distro,$tostop) = @_;
675: my %stopsrvcs;
676: if (ref($tostop) eq 'HASH') {
677: %stopsrvcs = %{$tostop};
678: }
1.6 raeburn 679: foreach my $service ('cups','memcached') {
1.1 raeburn 680: next if (exists($stopsrvcs{$service}));
681: my $daemon = $service;
682: if ($service eq 'cups') {
683: $daemon = 'cupsd';
684: }
685: my $cmd = "ps -ef |grep '$daemon' |grep -v grep";
686: if (open(PIPE,'-|',$cmd)) {
687: my $daemonrunning = <PIPE>;
688: chomp($daemonrunning);
689: close(PIPE);
690: if ($daemonrunning) {
1.12 raeburn 691: if ($service eq 'memcached') {
692: my $cmd = '/usr/sbin/memcached';
693: if ($distro =~ /^centos|fedora|scientific|rhes/) {
694: $cmd = '/usr/bin/memcached';
695: }
696: unless ($daemonrunning =~ m{^www[^/]+\Q$cmd -m 400 -v\E$}) {
1.10 raeburn 697: $stopsrvcs{$service} = 1;
698: }
699: } else {
700: $stopsrvcs{$service} = 1;
701: }
1.1 raeburn 702: }
703: }
1.10 raeburn 704: }
1.1 raeburn 705: return \%stopsrvcs;
706: }
707:
708: sub need_download {
709: my $needs_download = 1;
710: my ($production,$testing,$stdsizes) = &download_versionslist();
711: my ($rootdir,$localcurrent,$localtesting,%tarball,%localsize,%bymodtime,
712: %bysize,$filetouse,$downloadstatus);
713: $rootdir = '/root';
714: if (opendir(my $dir,"$rootdir")) {
715: my (@lcdownloads,$version);
716: foreach my $file (readdir($dir)) {
717: if ($file =~ /^loncapa\-([\w\-.]+)\.tar\.gz$/) {
718: $version = $1;
719: } else {
720: next;
721: }
722: if (ref($stdsizes) eq 'HASH') {
723: if ($version eq 'current') {
724: my @stats = stat("$rootdir/$file");
725: $localcurrent = $stats[7];
1.4 raeburn 726: if ($localcurrent == $stdsizes->{$production}) {
1.1 raeburn 727: $needs_download = 0;
728: $filetouse = $file;
729: }
730: } elsif ($version eq 'testing') {
731: my @stats = stat("$rootdir/$file");
732: $localtesting = $stats[7];
1.4 raeburn 733: if ($localtesting == $stdsizes->{$testing}) {
1.1 raeburn 734: $needs_download = 0;
735: $filetouse = $file;
736: }
737: }
738: }
739: $tarball{$version} = $file;
740: push(@lcdownloads,$version);
741: }
742: if ($needs_download) {
743: if (@lcdownloads > 0) {
744: foreach my $version (@lcdownloads) {
745: my @stats = stat("$rootdir/$tarball{$version}");
746: my $mtime = $stats[9];
747: $localsize{$version} = $stats[7];
748: if ($mtime) {
749: push(@{$bymodtime{$mtime}},$version);
750: }
751: if ($localsize{$version}) {
752: push(@{$bysize{$localsize{$version}}},$version);
753: }
754: }
755: if ($testing) {
756: if (exists($localsize{$testing})) {
757: if ($stdsizes->{$testing} == $localsize{$testing}) {
758: $needs_download = 0;
759: $filetouse = 'loncapa-'.$testing.'.tar.gz';
760: }
761: }
762: }
763: if ($needs_download) {
764: if ($production) {
765: if (exists($localsize{$production})) {
766: if ($stdsizes->{$production} == $localsize{$production}) {
767: $needs_download = 0;
768: $filetouse = 'loncapa-'.$production.'.tar.gz';
769: }
770: }
771: }
772: }
773: if ($needs_download) {
774: my @sorted = sort { $b <=> $a } keys(%bymodtime);
775: my $newest = $sorted[0];
776: if (ref($bymodtime{$newest}) eq 'ARRAY') {
777: $downloadstatus =
778: "Latest LON-CAPA source download in $rootdir is: ".
779: join(',',@{$bymodtime{$newest}})." (downloaded ".
780: localtime($newest).")\n";
781: }
782: } else {
783: $downloadstatus =
784: "The $rootdir directory already contains the latest LON-CAPA version:".
785: "\n".$filetouse."\n"."which can be used for installation.\n";
786: }
787: } else {
788: $downloadstatus = "The $rootdir directory does not appear to contain any downloaded LON-CAPA source code files which can be used for installation.\n";
789: }
790: }
791: } else {
792: $downloadstatus = "Could not open $rootdir directory to look for existing downloads of LON-CAPA source code.\n";
793: }
794: return ($needs_download,$downloadstatus,$filetouse,$production,$testing);
795: }
796:
797: sub check_mysql_setup {
798: my ($instdir,$dsn) = @_;
799: my ($mysqlsetup,$has_pass);
800: my $dbh = DBI->connect($dsn,'root','',{'PrintError'=>0});
801: if ($dbh) {
802: $mysqlsetup = 'noroot';
803: } elsif ($DBI::err =~ /1045/) {
804: $has_pass = 1;
805: }
806: if ($has_pass) {
807: print &mt('You have already set a root password for the MySQL database.')."\n";
808: my $currpass = &get_mysql_password(&mt('Please enter the password now'));
809: $dbh = DBI->connect($dsn,'root',$currpass,{'PrintError'=>0});
810: if ($dbh) {
811: $mysqlsetup = 'rootok';
812: print_and_log(&mt('Password accepted.')."\n");
813: } else {
814: $mysqlsetup = 'rootfail';
815: print_and_log(&mt('Problem accessing MySQL.')."\n");
816: if ($DBI::err =~ /1045/) {
817: print_and_log(&mt('Perhaps the password was incorrect?')."\n");
818: print &mt('Try again?').' ';
819: $currpass = &get_mysql_password(&mt('Re-enter password now'));
820: $dbh = DBI->connect($dsn,'root',$currpass,{'PrintError'=>0});
821: if ($dbh) {
822: $mysqlsetup = 'rootok';
823: print_and_log(&mt('Password accepted.')."\n");
824: } else {
825: if ($DBI::err =~ /1045/) {
826: print_and_log(&mt('Incorrect password.')."\n");
827: }
828: }
829: }
830: }
831: } elsif ($mysqlsetup ne 'noroot') {
832: print_and_log(&mt('Problem accessing MySQL.')."\n");
833: $mysqlsetup = 'rootfail';
834: }
835: return ($mysqlsetup,$has_pass,$dbh);
836: }
837:
838: sub check_mysql_wwwuser {
839: my $mysql_wwwuser;
1.12 raeburn 840: my $dbhn = DBI->connect("DBI:mysql:database=information_schema",'www','localhostkey',
841: {PrintError => +0}) || return;
1.1 raeburn 842: if ($dbhn) {
843: $mysql_wwwuser = 1;
844: $dbhn->disconnect;
845: }
846: return $mysql_wwwuser;
847: }
848:
849: sub check_loncapa_mysqldb {
850: my ($dbh) = @_;
851: my $has_lcdb;
852: if (ref($dbh)) {
853: my $sth = $dbh->prepare("SHOW DATABASES");
854: $sth->execute();
855: while (my $dbname = $sth->fetchrow_array) {
856: if ($dbname eq 'loncapa') {
857: $has_lcdb = 1;
858: last;
859: }
860: }
861: $sth->finish();
862: }
863: return $has_lcdb;
864: }
865:
866: sub get_pathto_iptables {
867: my $iptables;
868: if (-e '/sbin/iptables') {
869: $iptables = '/sbin/iptables';
870: } elsif (-e '/usr/sbin/iptables') {
871: $iptables = '/usr/sbin/iptables';
872: } else {
873: print &mt('Unable to find iptables command.')."\n";
874: }
875: return $iptables;
876: }
877:
878: sub firewall_is_active {
879: if (-e '/proc/net/ip_tables_names') {
880: return 1;
881: } else {
882: return 0;
883: }
884: }
885:
886: sub get_fw_chains {
1.5 raeburn 887: my ($iptables,$distro) = @_;
1.1 raeburn 888: my @fw_chains;
889: my $suse_config = "/etc/sysconfig/SuSEfirewall2";
890: my $ubuntu_config = "/etc/ufw/ufw.conf";
891: if (-e $suse_config) {
892: push(@fw_chains,'input_ext');
893: } else {
894: my @posschains;
895: if (-e $ubuntu_config) {
896: @posschains = ('ufw-user-input','INPUT');
1.5 raeburn 897: } elsif ($distro =~ /^debian5/) {
898: @posschains = ('INPUT');
1.1 raeburn 899: } else {
900: @posschains = ('RH-Firewall-1-INPUT','INPUT');
901: if (!-e '/etc/sysconfig/iptables') {
902: if (!-e '/var/lib/iptables') {
903: print &mt('Unable to find iptables file containing static definitions.')."\n";
904: }
905: push(@fw_chains,'RH-Firewall-1-INPUT');
906: }
907: }
908: if ($iptables eq '') {
909: $iptables = &get_pathto_iptables();
910: }
911: my %counts;
912: if (open(PIPE,"$iptables -L -n |")) {
913: while(<PIPE>) {
914: foreach my $chain (@posschains) {
915: if (/(\Q$chain\E)/) {
916: $counts{$1} ++;
917: }
918: }
919: }
920: close(PIPE);
921: }
922: foreach my $fw_chain (@posschains) {
923: if ($counts{$fw_chain}) {
924: unless(grep(/^\Q$fw_chain\E$/,@fw_chains)) {
925: push(@fw_chains,$fw_chain);
926: }
927: }
928: }
929: }
930: return @fw_chains;
931: }
932:
933: sub firewall_is_port_open {
934: my ($iptables,$fw_chain,$port) = @_;
935: # returns 1 if the firewall port is open, 0 if not.
936: #
937: # check if firewall is active or installed
938: return if (! &firewall_is_active());
939: my $count = 0;
940: if (open(PIPE,"$iptables -L $fw_chain -n |")) {
941: while(<PIPE>) {
942: if (/tcp dpt\:\Q$port\E/) {
943: $count ++;
944: last;
945: }
946: }
947: close(PIPE);
948: } else {
949: print &mt('Firewall status not checked: unable to run [_1].','iptables -L')."\n";
950: }
951: return $count;
952: }
953:
954: sub get_mysql_password {
955: my ($prompt) = @_;
956: local $| = 1;
957: print $prompt.': ';
958: my $newpasswd = '';
959: ReadMode 'raw';
960: my $key;
961: while(ord($key = ReadKey(0)) != 10) {
962: if(ord($key) == 127 || ord($key) == 8) {
963: chop($newpasswd);
964: print "\b \b";
965: } elsif(!ord($key) < 32) {
966: $newpasswd .= $key;
967: print '*';
968: }
969: }
970: ReadMode 'normal';
971: print "\n";
972: return $newpasswd;
973: }
974:
975: sub check_SuSEfirewall2_setup {
976: my ($instdir) = @_;
977: my $need_override = 1;
1.9 raeburn 978: if ((-e "/etc/insserv/overrides/SuSEfirewall2_setup") && (-e "$instdir/sles-suse/SuSEfirewall2_setup")) {
979: if (open(PIPE, "diff --brief $instdir/sles-suse/SuSEfirewall2_setup /etc/insserv/overrides/SuSEfirewall2_setup |")) {
1.1 raeburn 980: my $diffres = <PIPE>;
981: close(PIPE);
982: chomp($diffres);
983: unless ($diffres) {
984: $need_override = 0;
985: }
986: }
987: }
988: return $need_override;
989: }
990:
991: sub download_versionslist {
992: my ($production,$testing,%sizes);
993: if (-e "latest.txt") {
994: unlink("latest.txt");
995: }
996: my $rtncode = system("wget http://install.loncapa.org/versions/latest.txt ".
997: "> /dev/null 2>&1");
998: if (!$rtncode) {
999: if (open(my $fh,"<latest.txt")) {
1000: my @info = <$fh>;
1001: close($fh);
1002: foreach my $line (@info) {
1003: chomp();
1004: if ($line =~ /^\QLATEST-IS: \E([\w\-.]+):(\d+)$/) {
1005: $production = $1;
1006: $sizes{$1} = $2;
1007: } elsif ($line =~ /^LATEST-TESTING-IS: \E([\w\-.]+):(\d+)$/) {
1008: $testing = $1;
1009: $sizes{$1} = $2;
1010: }
1011: }
1012: }
1013: }
1014: return ($production,$testing,\%sizes);
1015: }
1016:
1017: #
1018: # End helper routines.
1019: # Main script starts here
1020: #
1021:
1022: print "
1023: ********************************************************************
1024:
1025: ".&mt('Welcome to LON-CAPA')."
1026:
1027: ".&mt('This script will configure your system for installation of LON-CAPA.')."
1028:
1029: ********************************************************************
1030:
1031: ".&mt('The following actions are available:')."
1032:
1.4 raeburn 1033: ".&mt('1.')." ".&mt('Create the www user/group.')."
1.1 raeburn 1034: ".&mt('This is the user/group ownership under which Apache child processes run.')."
1035: ".&mt('It also owns most directories within the /home/httpd directory.')."
1036: ".&mt('This directory is where most LON-CAPA files and directories are stored.')."
1.4 raeburn 1037: ".&mt('2.')." ".&mt('Install the package LON-CAPA uses to authenticate users.')."
1038: ".&mt('3.')." ".&mt('Set-up the MySQL database.')."
1039: ".&mt('4.')." ".&mt('Set-up MySQL permissions.')."
1040: ".&mt('5.')." ".&mt('Configure Apache web server.')."
1041: ".&mt('6.')." ".&mt('Configure start-up of services.')."
1042: ".&mt('7.')." ".&mt('Check firewall settings.')."
1043: ".&mt('8.')." ".&mt('Stop services not used by LON-CAPA,')."
1.1 raeburn 1044: ".&mt('i.e., services for a print server: [_1] daemon.',"'cups'")."
1.4 raeburn 1045: ".&mt('9.')." ".&mt('Download LON-CAPA source code in readiness for installation.')."
1.1 raeburn 1046:
1047: ".&mt('Typically, you will run this script only once, when you first install LON-CAPA.')."
1048:
1049: ".&mt('The script will analyze your system to determine which actions are recommended.')."
1050: ".&mt('The script will then prompt you to choose the actions you would like taken.')."
1051:
1052: ".&mt('For each the recommended action will be selected if you hit Enter/Return.')."
1053: ".&mt('To override the default, type the lower case option from the two options listed.')."
1054: ".&mt('So, if the default is "yes", ~[Y/n~] will be shown -- type n to override.')."
1055: ".&mt('Whereas if the default is "no", ~[y/N~] will be shown -- type y to override.')."
1056:
1057: ".&mt('To accept the default, simply hit Enter/Return on your keyboard.')."
1058: ".&mt('Otherwise type: y or n then hit the Enter/Return key.')."
1059:
1060: ".&mt('Once a choice has been entered for all nine actions, required changes will be made.')."
1061: ".&mt('Feedback will be displayed on screen, and also stored in: [_1].','loncapa_install.log')."
1062:
1063: ".&mt('Continue? ~[Y/n~] ');
1064:
1065: my $go_on = &get_user_selection(1);
1066: if (!$go_on) {
1067: exit;
1068: }
1069:
1070: my $instdir = `pwd`;
1071: chomp($instdir);
1072:
1073: my %callsub;
1074: my @actions = ('wwwuser','pwauth','mysql','mysqlperms','apache',
1075: 'runlevels','firewall','stopsrvcs','download');
1076: my %prompts = &texthash(
1077: wwwuser => "Create the 'www' user?",
1078: pwauth => 'Install the package LON-CAPA uses to authenticate users?',
1079: mysql => 'Set-up the MySQL database?',
1080: mysqlperms => 'Set-up MySQL permissions?',
1081: apache => 'Configure Apache web server?',
1082: runlevels => 'Set overrides for start-up order of services?',
1083: firewall => 'Configure firewall settings for Apache',
1084: stopsrvcs => 'Stop extra services not required on a LON-CAPA server?',
1085: download => 'Download LON-CAPA source code in readiness for installation?',
1086: );
1087:
1088: print "\n".&mt('Checking system status ...')."\n";
1089:
1090: my $dsn = "DBI:mysql:database=mysql";
1.6 raeburn 1091: my ($distro,$gotprereqs,$localecmd,$packagecmd,$updatecmd,$installnow,$recommended,
1.1 raeburn 1092: $dbh,$has_pass,$has_lcdb,$downloadstatus,$filetouse,$production,
1.5 raeburn 1093: $testing,$apachefw) = &check_required($instdir,$dsn);
1.1 raeburn 1094: if ($distro eq '') {
1095: print "\n".&mt('Linux distribution could not be verified as a supported distribution.')."\n".
1096: &mt('The following are supported: [_1].',
1097: 'CentOS, RedHat Enterprise, Fedora, Scientific Linux, '.
1098: 'openSuSE, SLES, Ubuntu LTS, Debian')."\n\n".
1099: &mt('Stopping execution.')."\n";
1100: exit;
1101: }
1.6 raeburn 1102: if ($localecmd ne '') {
1103: print "\n".&mt('Although the LON-CAPA application itself is localized for a number of different languages, the default locale language for the Linux OS on which it runs should be US English.')."\n";
1104: print "\n".&mt('Run the following command from the command line to set the default language for your OS, and then run this LON-CAPA installation set-up script again.')."\n\n".
1105: $localecmd."\n\n".
1106: &mt('Stopping execution.')."\n";
1107: exit;
1108: }
1.1 raeburn 1109: if (!$gotprereqs) {
1.12 raeburn 1110: print "\n".&mt('The LONCAPA-prerequisites package is not installed.')."\n".
1.1 raeburn 1111: &mt('The following command can be used to install the package (and dependencies):')."\n\n".
1112: $updatecmd."\n\n";
1113: if ($installnow eq '') {
1114: print &mt('Stopping execution.')."\n";
1115: exit;
1116: } else {
1117: print &mt('Run command? ~[Y/n~]');
1118: my $install_prereq = &get_user_selection(1);
1119: if ($install_prereq) {
1120: if (open(PIPE,'|-',$installnow)) {
1121: close(PIPE);
1122: $gotprereqs = &check_prerequisites($packagecmd,$distro);
1123: if (!$gotprereqs) {
1.12 raeburn 1124: print &mt('The LONCAPA-prerequisites package is not installed.')."\n".
1.1 raeburn 1125: &mt('Stopping execution.')."\n";
1126: exit;
1127: } else {
1.6 raeburn 1128: ($distro,$gotprereqs,$localecmd,$packagecmd,$updatecmd,$installnow,
1.1 raeburn 1129: $recommended,$dbh,$has_pass,$has_lcdb,$downloadstatus,
1.5 raeburn 1130: $filetouse,$production,$testing,$apachefw) =
1131: &check_required($instdir,$dsn);
1.1 raeburn 1132: }
1133: } else {
1.12 raeburn 1134: print &mt('Failed to run command to install LONCAPA-prerequisites')."\n";
1.1 raeburn 1135: exit;
1136: }
1137: } else {
1138: print &mt('Stopping execution.')."\n";
1139: exit;
1140: }
1141: }
1142: }
1143: unless (ref($recommended) eq 'HASH') {
1144: print "\n".&mt('An error occurred determining which actions are recommended.')."\n\n".
1145: &mt('Stopping execution.')."\n";
1146: exit;
1147: }
1148:
1149: print "\n";
1150: my $num = 0;
1151: foreach my $action (@actions) {
1152: $num ++;
1153: my ($yesno,$defaultrun);
1154: if (ref($recommended) eq 'HASH') {
1.4 raeburn 1155: if (($action eq 'runlevels') || ($action eq 'stopsrvcs')) {
1.1 raeburn 1156: $yesno = '[y/N]';
1157: if (ref($recommended->{$action}) eq 'HASH') {
1158: if (keys(%{$recommended->{$action}}) > 0) {
1159: $yesno = &mt('~[Y/n~]');
1160: $defaultrun = 1;
1161: }
1162: }
1163: } else {
1164: if ($action eq 'download') {
1165: if ($downloadstatus) {
1166: print "\n$downloadstatus\n";
1167: }
1168: }
1169: if ($recommended->{$action}) {
1170: $yesno = mt('~[Y/n~]');
1171: $defaultrun = 1;
1172: } else {
1173: $yesno = &mt('~[y/N~]');
1174: }
1175: }
1176: print $num.'. '.$prompts{$action}." $yesno ";
1177: $callsub{$action} = &get_user_selection($defaultrun);
1178: }
1179: }
1180:
1181: my $lctarball = 'loncapa-current.tar.gz';
1182: my $sourcetarball = $lctarball;
1183: if ($callsub{'download'}) {
1184: my ($production,$testing,$sizes) = &download_versionslist();
1185: if ($production && $testing) {
1186: if ($production ne $testing) {
1187: print &mt('Two recent LON-CAPA releases are available: ')."\n".
1.3 raeburn 1188: &mt('1.').' '.&mt('A production release - version: [_1].',$production)."\n".
1189: &mt('2.').' '.&mt('A testing release - version: [_1].',$testing)."\n\n".
1.1 raeburn 1190: &mt('Download the production release? ~[Y/n~]');
1191: if (&get_user_selection(1)) {
1.4 raeburn 1192: $sourcetarball = 'loncapa-'.$production.'.tar.gz';
1.1 raeburn 1193: } else {
1194: print "\n".&mt('Download the testing release? ~[Y/n~]');
1195: if (&get_user_selection(1)) {
1.4 raeburn 1196: $sourcetarball = 'loncapa-'.$testing.'.tar.gz';
1.1 raeburn 1197: }
1198: }
1199: }
1200: } elsif ($production) {
1201: print &mt('The most recent LON-CAPA release is version: [_1].',$production)."\n".
1202: &mt('Download the production release? ~[Y/n~]');
1203: if (&get_user_selection(1)) {
1204: $sourcetarball = $production.'tar.gz';
1205: }
1206: }
1207: } elsif ($filetouse ne '') {
1208: $sourcetarball = $filetouse;
1209: }
1210:
1211: print_and_log("\n");
1212:
1213: # Each action: report if skipping, or perform action and provide feedback.
1214: if ($callsub{'wwwuser'}) {
1215: &setup_www();
1216: } else {
1217: &print_and_log(&mt('Skipping creation of user [_1].',"'www'")."\n");
1218: }
1219:
1220: if ($callsub{'pwauth'}) {
1.4 raeburn 1221: &build_and_install_mod_auth_external($instdir);
1.1 raeburn 1222: } else {
1223: &print_and_log(&mt('Skipping [_1] installation.',"'pwauth'")."\n");
1224: }
1225:
1226: if ($callsub{'mysql'}) {
1227: if ($dbh) {
1228: &setup_mysql($callsub{'mysqlperms'},$distro,$dbh,$has_pass,$has_lcdb);
1229: } else {
1230: print &mt('Unable to configure MySQL because access is denied.')."\n";
1231: }
1232: } else {
1233: &print_and_log(&mt('Skipping configuration of MySQL.')."\n");
1234: if ($callsub{'mysqlperms'}) {
1235: if ($dbh) {
1236: &setup_mysql_permissions($dbh,$has_pass);
1237: } else {
1238: print &mt('Unable to configure MySQL because access is denied.')."\n";
1239: }
1240: } else {
1241: &print_and_log(&mt('Skipping MySQL permissions setup.')."\n");
1242: }
1243: }
1244:
1245: if ($dbh) {
1246: if (!$dbh->disconnect) {
1247: &print_and_log(&mt('Failed to disconnect from MySQL:')."\n".
1248: $dbh->errstr);
1249: }
1250: }
1251:
1252: if ($callsub{'apache'}) {
1253: if ($distro =~ /^(suse|sles)/) {
1254: ©_apache2_suseconf($instdir);
1255: } elsif ($distro =~ /^(debian|ubuntu)/) {
1256: ©_apache2_debconf($instdir);
1257: } else {
1258: ©_httpd_conf($instdir);
1259: }
1260: } else {
1261: print_and_log(&mt('Skipping configuration of Apache web server.')."\n");
1262: }
1263:
1264: if ($callsub{'runlevels'}) {
1265: my $count = 0;
1266: if (ref($recommended) eq 'HASH') {
1267: if (ref($recommended->{'runlevels'}) eq 'HASH') {
1268: foreach my $type (keys(%{$recommended->{'runlevels'}})) {
1269: next if ($type eq 'insserv');
1270: $count ++;
1271: my $command = $recommended->{'runlevels'}{$type};
1272: if ($command ne '') {
1273: print_and_log(&mt('Runlevel update command run: [_1].',$command)."\n");
1274: system($command);
1275: }
1276: }
1277: if (!$count) {
1278: print_and_log(&mt('No runlevel updates required.')."\n");
1279: }
1280: }
1281: }
1.11 raeburn 1282: if ($distro =~ /^(suse|sles)/) {
1283: &update_SuSEfirewall2_setup($instdir);
1284: }
1.1 raeburn 1285: } else {
1286: &print_and_log(&mt('Skipping setting override for start-up order of services.')."\n");
1287: }
1288:
1289: if ($callsub{'firewall'}) {
1290: if ($distro =~ /^(suse|sles)/) {
1.5 raeburn 1291: print &mt('Use [_1] to configure the firewall to allow access for [_2].',
1292: 'yast -- Security and Users -> Firewall -> Interfaces',
1293: 'ssh, http, https')."\n";
1294: } elsif ($distro =~ /^(debian|ubuntu)(\d+)/) {
1295: if (($1 eq 'ubuntu') || ($2 > 5)) {
1296: print &mt('Use [_1] to configure the firewall to allow access for [_2].',
1297: 'ufw','ssh, http, https')."\n";
1298: } else {
1299: my $fwadded = &get_iptables_rules($distro,$instdir,$apachefw);
1300: if ($fwadded) {
1301: print &mt('Enable firewall? ~[Y/n~]');
1302: my $enable_iptables = &get_user_selection(1);
1303: if ($enable_iptables) {
1304: system('/etc/network/if-pre-up.d/iptables');
1305: print &mt('Firewall enabled using rules defined in [_1].',
1306: '/etc/iptables.loncapa.rules');
1307: }
1308: }
1309: }
1.11 raeburn 1310: } elsif ($distro =~ /^scientific/) {
1311: print &mt('Use [_1] to configure the firewall to allow access for [_2].',
1312: 'system-config-firewall-tui -- Customize',
1313: 'ssh, http')."\n";
1.1 raeburn 1314: } else {
1.5 raeburn 1315: print &mt('Use [_1] to configure the firewall to allow access for [_2].',
1.11 raeburn 1316: 'setup -- Firewall configuration -> Customize',
1.5 raeburn 1317: 'ssh, http, https')."\n";
1.1 raeburn 1318: }
1319: } else {
1.5 raeburn 1320: &print_and_log(&mt('Skipping Firewall configuration.')."\n");
1.1 raeburn 1321: }
1322:
1323: if ($callsub{'stopsrvcs'}) {
1324: &kill_extra_services($distro,$recommended->{'stopsrvcs'});
1325: } else {
1.10 raeburn 1326: &print_and_log(&mt('Skipping stopping unnecessary service ([_1] daemons).',"'cups','memcached'")."\n");
1.1 raeburn 1327: }
1328:
1329: my ($have_tarball,$updateshown);
1330: if ($callsub{'download'}) {
1331: ($have_tarball,$updateshown) = &download_loncapa($instdir,$sourcetarball);
1332: } else {
1333: print_and_log(&mt('Skipping download of LON-CAPA tar file.')."\n\n");
1334: print &mt('LON-CAPA is available for download from: [_1]',
1335: 'http://install.loncapa.org/')."\n";
1336: if (!-e '/etc/loncapa-release') {
1337: &print_and_log(&mt('LON-CAPA is not yet installed on your system.').
1338: "\n\n".
1339: &mt('You may retrieve the source for LON-CAPA by executing:')."\n".
1340: "wget http://install.loncapa.org/versions/$lctarball\n");
1341: } else {
1342: my $currentversion;
1343: if (open(my $fh,"</etc/loncapa-release")) {
1344: my $version = <$fh>;
1345: chomp($version);
1346: if ($version =~ /^\QLON-CAPA release \E([\w\-.]+)$/) {
1347: $currentversion = $1;
1348: }
1349: }
1350: if ($currentversion ne '') {
1351: print &mt('Version of LON-CAPA currently installed on this server is: [_1].',
1352: $currentversion),"\n";
1353: if ($production) {
1354: print &mt('The latest production release of LON-CAPA is [_1].',$production)."\n";
1355: }
1356: if ($testing) {
1357: print &mt('The latest testing release of LON-CAPA is [_1].',$testing)."\n";
1358: }
1359: }
1360: }
1361: if ($filetouse ne '') {
1362: $have_tarball = 1;
1363: }
1364: }
1365:
1366: print "\n".&mt('Requested configuration complete.')."\n\n";
1367: my $apachename;
1368: if ($have_tarball && !$updateshown) {
1369: my ($lcdir) = ($sourcetarball =~ /^([\w.\-]+)\.tar.gz$/);
1370: if (!-e '/etc/loncapa-release') {
1371: print &mt('If you are now ready to install LON-CAPA, enter the following commands:')."\n\n";
1372: } else {
1373: print &mt('If you are now ready to update LON-CAPA, enter the following commands:')."\n\n".
1374: "/etc/init.d/loncontrol stop\n";
1375: if ($distro =~ /^(suse|sles|debian|ubuntu)([\d.]+)/) {
1376: if (($1 eq 'suse') && ($2 < 10)) {
1377: $apachename = 'apache';
1378: } else {
1379: $apachename = 'apache2';
1380: }
1381: } else {
1382: $apachename = 'httpd';
1383: }
1384: print "/etc/init.d/$apachename stop\n";
1385: }
1386: print "cd /root\n".
1387: "tar zxf $sourcetarball\n".
1388: "cd $lcdir\n".
1389: "./UPDATE\n";
1390: if (-e '/etc/loncapa-release') {
1391: print "/etc/init.d/loncontrol start\n";
1392: print "/etc/init.d/$apachename start\n";
1393: }
1394: }
1395: exit;
1396:
1397: #
1398: # End main script
1399: #
1400:
1401: #
1402: # Routines for the actions
1403: #
1404:
1405: sub setup_www {
1406: ##
1407: ## Set up www
1408: ##
1409: print_and_log(&mt('Creating user [_1]',"'www'")."\n");
1410: # -- Add group
1411:
1412: my $status = `/usr/sbin/groupadd www`;
1413: if ($status =~ /\QGroup `www' already exists.\E/) {
1414: print &mt('Group [_1] already exists.',"'www'")."\n";
1415: } elsif ($status ne '') {
1416: print &mt('Unable to add group [_1].',"'www'")."\n";
1417: }
1418:
1419: my $gid = getgrnam('www');
1420:
1421: if (open (PIPE, "/usr/sbin/useradd -c LONCAPA -g $gid www 2>&1 |")) {
1422: $status = <PIPE>;
1423: close(PIPE);
1424: chomp($status);
1425: if ($status =~ /\QAccount `www' already exists.\E/) {
1426: print &mt('Account [_1] already exists.',"'www'")."\n";
1427: } elsif ($status ne '') {
1428: print &mt('Unable to add user [_1].',"'www'")."\n";
1429: }
1430: } else {
1431: print &mt('Unable to run command to add user [_1].',"'www'")."\n";
1432: }
1433:
1434: my $uid = &uid_of_www();
1435: if (($gid ne '') && ($uid ne '')) {
1436: if (!-e '/home/www') {
1437: mkdir('/home/www',0755);
1438: system('chown www:www /home/www');
1439: }
1440: }
1441: writelog ($status);
1442: }
1443:
1444: sub uid_of_www {
1445: my ($num) = (getpwnam('www'))[2];
1446: return $num;
1447: }
1448:
1449: sub build_and_install_mod_auth_external {
1450: my ($instdir) = @_;
1451: my $num = &uid_of_www();
1452: # Patch pwauth
1453: print_and_log(&mt('Building authentication system for LON-CAPA users.')."\n");
1454: my $patch = <<"ENDPATCH";
1455: 148c148
1456: < #define SERVER_UIDS 99 /* user "nobody" */
1457: ---
1458: > #define SERVER_UIDS $num /* user "www" */
1459: ENDPATCH
1460:
1461: if (! -e "/usr/bin/patch") {
1462: print_and_log(&mt('You must install the software development tools package: [_1], when installing Linux.',"'patch'")."\n");
1463: print_and_log(&mt('Authentication installation not completed.')."\n");
1464: return;
1465: }
1466: if (&skip_if_nonempty(`cd /tmp; tar zxf $instdir/pwauth-2.2.8.tar.gz`,
1467: &mt('Unable to extract pwauth')."\n")) {
1468: return;
1469: }
1470: my $dir = "/tmp/pwauth-2.2.8";
1471: if (open(PATCH,"| patch $dir/config.h")) {
1472: print PATCH $patch;
1473: close(PATCH);
1474: print_and_log("\n");
1475: ##
1476: ## Compile patched pwauth
1477: ##
1478: print_and_log(&mt('Compiling pwauth')."\n");
1.12 raeburn 1479: my $result = `cd $dir/; make 2>/dev/null `;
1.1 raeburn 1480: my $expected = <<"END";
1481: gcc -g -c -o pwauth.o pwauth.c
1482: gcc -o pwauth -g pwauth.o -lcrypt
1483: END
1484: if ($result eq $expected) {
1485: print_and_log(&mt('Apparent success compiling pwauth:').
1486: "\n".$result );
1487: # Install patched pwauth
1488: print_and_log(&mt('Copying pwauth to [_1]',' /usr/local/sbin')."\n");
1489: if (copy "$dir/pwauth","/usr/local/sbin/pwauth") {
1.5 raeburn 1490: if (chmod(06755, "/usr/local/sbin/pwauth")) {
1.1 raeburn 1491: print_and_log(&mt('[_1] copied successfully',"'pwauth'").
1492: "\n");
1493: } else {
1494: print &mt('Unable to set permissions on [_1].'.
1495: "/usr/local/sbin/pwauth")."\n";
1496: }
1497: } else {
1498: print &mt('Unable to copy [_1] to [_2]',
1499: "'$dir/pwauth'","/usr/local/sbin/pwauth")."\n$!\n";
1500: }
1501: } else {
1502: print &mt('Unable to compile patched [_1].'."'pwauth'")."\n";
1503: }
1504: } else {
1505: print &mt('Unable to start patch for [_1]',"'pwauth'")."\n";
1506: }
1507: print_and_log("\n");
1508: }
1509:
1510: sub kill_extra_services {
1511: my ($distro,$stopsrvcs) = @_;
1512: if (ref($stopsrvcs) eq 'HASH') {
1513: my @stopping = sort(keys(%{$stopsrvcs}));
1514: if (@stopping) {
1.6 raeburn 1515: my $kill_list = join("', '",@stopping);
1.1 raeburn 1516: if ($kill_list) {
1517: $kill_list = "'".$kill_list."'";
1.6 raeburn 1518: &print_and_log("\n".&mt('Killing unnecessary services ([_1] daemon(s)).',$kill_list)."\n");
1519: foreach my $service (@stopping) {
1520: my $daemon = $service;
1521: if ($service eq 'cups') {
1522: $daemon = 'cupsd';
1523: if ($distro =~ /^(?:debian|ubuntu)(\d+)/) {
1524: my $version = $1;
1525: if (($distro =~ /^ubuntu/) && ($version <= 8)) {
1526: $daemon = 'cupsys';
1527: }
1.12 raeburn 1528: } else {
1.8 raeburn 1529: $daemon = 'cups';
1.6 raeburn 1530: }
1531: }
1.12 raeburn 1532: my $cmd = "ps -ef |grep '$daemon' |grep -v grep";
1533: if (open(PIPE,'-|',$cmd)) {
1534: my $daemonrunning = <PIPE>;
1535: chomp($daemonrunning);
1536: close(PIPE);
1537: if ($daemonrunning) {
1538: &print_and_log(`/etc/init.d/$daemon stop`);
1539: }
1540: }
1.1 raeburn 1541: &print_and_log(&mt('Removing [_1] from startup.',$service)."\n");
1.4 raeburn 1542: if ($distro =~ /^(debian|ubuntu)/) {
1.6 raeburn 1543: &print_and_log(`update-rc.d -f $daemon remove`);
1.1 raeburn 1544: } else {
1.12 raeburn 1545: &print_and_log(`/sbin/chkconfig --del $service`);
1.1 raeburn 1546: }
1547: }
1548: }
1549: }
1550: }
1551: return;
1552: }
1553:
1554: sub setup_mysql {
1555: my ($setup_mysql_permissions,$distro,$dbh,$has_pass,$has_lcdb) = @_;
1.4 raeburn 1556: my @mysql_lc_commands;
1.1 raeburn 1557: unless ($has_lcdb) {
1.4 raeburn 1558: push(@mysql_lc_commands,"CREATE DATABASE loncapa");
1.1 raeburn 1559: }
1.4 raeburn 1560: push(@mysql_lc_commands,"USE loncapa");
1561: push(@mysql_lc_commands,qq{
1.13 ! raeburn 1562: 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, domain TEXT, dependencies TEXT, modifyinguser TEXT, authorspace TEXT, lowestgradelevel TEXT, highestgradelevel TEXT, standards TEXT, count INT, course INT, course_list TEXT, goto INT, goto_list TEXT, comefrom INT, comefrom_list TEXT, sequsage INT, sequsage_list TEXT, stdno INT, stdno_list TEXT, avetries FLOAT, avetries_list TEXT, difficulty FLOAT, difficulty_list TEXT, disc FLOAT, disc_list TEXT, clear FLOAT, technical FLOAT, correct FLOAT, helpful FLOAT, depth FLOAT, hostname 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
1.4 raeburn 1563: });
1.1 raeburn 1564: if ($setup_mysql_permissions) {
1.4 raeburn 1565: &setup_mysql_permissions($dbh,$has_pass,@mysql_lc_commands);
1.1 raeburn 1566: } else {
1567: print_and_log(&mt('Skipping MySQL permissions setup.')."\n");
1568: if ($dbh) {
1.4 raeburn 1569: if (@mysql_lc_commands) {
1570: foreach my $lccmd (@mysql_lc_commands) {
1571: $dbh->do($lccmd) || print $dbh->errstr."\n";
1572: }
1573: }
1.1 raeburn 1574: print_and_log(&mt('MySQL database set up complete.')."\n");
1575: } else {
1576: print_and_log(&mt('Problem accessing MySQL.')."\n");
1577: }
1578: }
1579: }
1580:
1581: sub setup_mysql_permissions {
1.4 raeburn 1582: my ($dbh,$has_pass,@mysql_lc_commands) = @_;
1.1 raeburn 1583: my $mysqlversion = &get_mysql_version();
1.4 raeburn 1584: my @mysql_commands = ("INSERT user (Host, User, Password) VALUES('localhost','www',password('localhostkey'));");
1.1 raeburn 1585: if ($mysqlversion < 4) {
1.4 raeburn 1586: push (@mysql_commands,"
1587: 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')");
1588: } else {
1589: push (@mysql_commands,"
1590: 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 1591: }
1.4 raeburn 1592: push(@mysql_commands,"DELETE FROM user WHERE host<>'localhost'");
1.1 raeburn 1593: if ($has_pass) {
1594: if ($dbh) {
1.4 raeburn 1595: push(@mysql_commands,"FLUSH PRIVILEGES");
1596: if (@mysql_commands) {
1597: foreach my $cmd (@mysql_commands) {
1598: $dbh->do($cmd) || print $dbh->errstr."\n";
1599: }
1600: }
1601: if (@mysql_lc_commands) {
1602: foreach my $lccmd (@mysql_lc_commands) {
1603: $dbh->do($lccmd) || print $dbh->errstr."\n";
1604: }
1605: }
1.1 raeburn 1606: print_and_log(&mt('Permissions set for LON-CAPA MySQL user: [_1]',"'www'")."\n");
1607: } else {
1608: print_and_log(&mt('Problem accessing MySQL.')."\n".
1609: &mt('Permissions not set.')."\n");
1610: }
1611: } else {
1612: my ($firstpass,$secondpass,$got_passwd,$newmysqlpass);
1613: print &mt('Please enter a root password for the mysql database.')."\n".
1614: &mt('It does not have to match your root account password, but you will need to remember it.')."\n";
1615: my $maxtries = 10;
1616: my $trial = 0;
1617: while ((!$got_passwd) && ($trial < $maxtries)) {
1618: $firstpass = &get_mysql_password(&mt('Enter password'));
1619: if (length($firstpass) > 5) {
1620: $secondpass = &get_mysql_password(&mt('Enter password a second time'));
1621: if ($firstpass eq $secondpass) {
1622: $got_passwd = 1;
1623: $newmysqlpass = $firstpass;
1624: } else {
1625: print(&mt('Passwords did not match. Please try again.')."\n");
1626: }
1627: $trial ++;
1628: } else {
1629: print(&mt('Password too short.')."\n".
1630: &mt('Please choose a password with at least six characters.')."\n");
1631: }
1632: }
1633: if ($got_passwd) {
1.4 raeburn 1634: my (@newpass_cmds) = &new_mysql_rootpasswd($newmysqlpass);
1635: push(@mysql_commands,@newpass_cmds);
1.1 raeburn 1636: } else {
1637: print_and_log(&mt('Failed to get MySQL root password from user input.')."\n");
1638: }
1639: if ($dbh) {
1.4 raeburn 1640: if (@mysql_commands) {
1641: foreach my $cmd (@mysql_commands) {
1642: $dbh->do($cmd) || print $dbh->errstr."\n";
1643:
1644: }
1645: }
1646: if (@mysql_lc_commands) {
1647: foreach my $lccmd (@mysql_lc_commands) {
1648: $dbh->do($lccmd) || print $dbh->errstr."\n";
1649: }
1650: }
1.1 raeburn 1651: if ($got_passwd) {
1652: print_and_log(&mt('MySQL root password stored.')."\n".
1653: &mt('Permissions set for LON-CAPA MySQL user: [_1].',"'www'")."\n");
1654: } else {
1655: print_and_log(&mt('Permissions set for LON-CAPA MySQL user: [_1].',"'www'")."\n");
1656: }
1657: } else {
1658: print_and_log(&mt('Problem accessing MySQL.')."\n".
1659: &mt('Permissions not set.')."\n");
1660: }
1661: }
1662: }
1663:
1664: sub new_mysql_rootpasswd {
1665: my ($currmysqlpass) = @_;
1.4 raeburn 1666: return ("SET PASSWORD FOR 'root'\@'localhost'=PASSWORD('$currmysqlpass')",
1667: "FLUSH PRIVILEGES;");
1.1 raeburn 1668: }
1669:
1670: sub get_mysql_version {
1671: my $version;
1672: if (open(PIPE," mysql -V |")) {
1673: my $info = <PIPE>;
1674: chomp($info);
1675: close(PIPE);
1676: ($version) = ($info =~ /(\d+\.\d+)\.\d+,/);
1677: } else {
1678: print &mt('Could not determine which version of MySQL is installed.').
1679: "\n";
1680: }
1681: return $version;
1682: }
1683:
1684: ###########################################################
1685: ##
1686: ## RHEL/CentOS/Fedora/Scientific Linux
1687: ## Copy LON-CAPA httpd.conf to /etc/httpd/conf
1688: ##
1689: ###########################################################
1690:
1691: sub copy_httpd_conf {
1692: my ($instdir) = @_;
1693: print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',"'httpd.conf'",
1694: "'/etc/httpd/conf/httpd.conf'")."\n");
1695: copy "/etc/httpd/conf/httpd.conf","/etc/httpd/conf/httpd.conf.original";
1.11 raeburn 1696: copy "$instdir/centos-rhes-fedora-sl/httpd.conf","/etc/httpd/conf/httpd.conf";
1.5 raeburn 1697: chmod(0444,"/etc/httpd/conf/httpd.conf");
1.1 raeburn 1698: print_and_log("\n");
1699: }
1700:
1701: #########################################################
1702: ##
1703: ## Ubuntu/Debian -- copy our apache2 configuration file to
1704: ## sites-available and set the symlink from sites-enabled.
1705: ##
1706: #########################################################
1707:
1708: sub copy_apache2_debconf {
1709: my ($instdir) = @_;
1.4 raeburn 1710: 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.6 raeburn 1711: my $apache2_sites_enabled_dir = '/etc/apache2/sites-enabled';
1712: my $apache2_sites_available_dir = '/etc/apache2/sites-available';
1713: if (-l "$apache2_sites_enabled_dir/000-default") {
1714: unlink("$apache2_sites_enabled_dir/000-default");
1715: }
1716: if (-e "$apache2_sites_available_dir/loncapa") {
1717: copy("$apache2_sites_available_dir/loncapa","$apache2_sites_available_dir/loncapa.original");
1718: }
1.9 raeburn 1719: copy("$instdir/debian-ubuntu/apache2.conf","$apache2_sites_available_dir/loncapa");
1.6 raeburn 1720: chmod(0444,"$apache2_sites_available_dir/loncapa");
1721: symlink("$apache2_sites_available_dir/loncapa","$apache2_sites_enabled_dir/000-default");
1722: my $apache2_mods_enabled_dir = '/etc/apache2/mods-enabled';
1723: my $apache2_mods_available_dir = '/etc/apache2/mods-available';
1724: foreach my $module ('headers.load','expires.load') {
1725: unless (-l "$apache2_mods_enabled_dir/$module") {
1726: symlink("$apache2_mods_available_dir/$module","$apache2_mods_enabled_dir/$module");
1727: print_and_log(&mt('Enabling "[_1]" Apache module.',$module)."\n");
1728: }
1729: }
1.1 raeburn 1730: print_and_log("\n");
1731: }
1732:
1733: ###########################################################
1734: ##
1735: ## openSuSE/SLES Copy apache2 config files:
1736: ## default-server.conf, uid.conf, /etc/sysconfig/apache2
1737: ## and create symlink from /srv/www/conf to /etc/apache2
1738: ##
1739: ###########################################################
1740:
1741: sub copy_apache2_suseconf {
1742: my ($instdir) = @_;
1743: print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',
1744: "'default-server.conf'",
1745: "'/etc/apache2/default-server.conf'")."\n");
1746: if (!-e "/etc/apache2/default-server.conf.original") {
1747: copy "/etc/apache2/default-server.conf","/etc/apache2/default-server.conf.original";
1748: }
1.9 raeburn 1749: copy "$instdir/sles-suse/default-server.conf","/etc/apache2/default-server.conf";
1.5 raeburn 1750: chmod(0444,"/etc/apache2/default-server.conf");
1.1 raeburn 1751: # Make symlink for conf directory (included in loncapa_apache.conf)
1752: my $can_symlink = (eval { symlink('/etc/apache2','/srv/www/conf'); }, $@ eq '');
1753: if ($can_symlink) {
1754: &print_and_log(&mt('Symlink created for [_1] to [_2].',
1755: "'/srv/www/conf'","'/etc/apache2'")."\n");
1756: } else {
1757: &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");
1758: }
1759: ©_apache2_conf_files($instdir);
1760: ©_sysconfig_apache2_file($instdir);
1761: print_and_log("\n");
1762: }
1763:
1764: ###############################################
1765: ##
1766: ## Modify uid.conf
1767: ##
1768: ###############################################
1769: sub copy_apache2_conf_files {
1770: my ($instdir) = @_;
1771: print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',
1772: "'uid.conf'","'/etc/apache2/uid.conf'")."\n");
1773: if (!-e "/etc/apache2/uid.conf.original") {
1774: copy "/etc/apache2/uid.conf","/etc/apache2/uid.conf.original";
1775: }
1.9 raeburn 1776: copy "$instdir/sles-suse/uid.conf","/etc/apache2/uid.conf";
1.5 raeburn 1777: chmod(0444,"/etc/apache2/uid.conf");
1.1 raeburn 1778: }
1779:
1780: ###############################################
1781: ##
1782: ## Modify /etc/sysconfig/apache2
1783: ##
1784: ###############################################
1785: sub copy_sysconfig_apache2_file {
1786: my ($instdir) = @_;
1787: print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',"'sysconfig/apache2'","'/etc/sysconfig/apache2'")."\n");
1788: if (!-e "/etc/sysconfig/apache2.original") {
1789: copy "/etc/sysconfig/apache2","/etc/sysconfig/apache2.original";
1790: }
1.9 raeburn 1791: copy "$instdir/sles-suse/sysconfig_apache2","/etc/sysconfig/apache2";
1.5 raeburn 1792: chmod(0444,"/etc/sysconfig/apache2");
1.1 raeburn 1793: }
1794:
1795: ###############################################
1796: ##
1797: ## Add/Modify /etc/insserv/overrides
1798: ##
1799: ###############################################
1800:
1801: sub update_SuSEfirewall2_setup {
1802: my ($instdir) = @_;
1803: print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',"'SuSEfirewall2_setup'","'/etc/insserv/overrides/SuSEfirewall2_setup'")."\n");
1804: if (!-e "/etc/insserv/overrides/SuSEfirewall2_setup") {
1805: if (!-d "/etc/insserv") {
1806: mkdir("/etc/insserv",0755);
1807: }
1808: if (!-d "/etc/insserv/overrides") {
1809: mkdir("/etc/insserv/overrides",0755);
1810: }
1811: } elsif (!-e "/etc/insserv/overrides/SuSEfirewall2_setup.original") {
1812: copy "/etc/insserv/overrides/SuSEfirewall2_setup","/etc/insserv/overrides/SuSEfirewall2_setup.original"
1813: }
1.9 raeburn 1814: copy "$instdir/sles-suse/SuSEfirewall2_setup","/etc/insserv/overrides/SuSEfirewall2_setup";
1.5 raeburn 1815: chmod(0444,"/etc/insserv/overrides/SuSEfirewall2_setup");
1816: }
1817:
1818: sub get_iptables_rules {
1819: my ($distro,$instdir,$apachefw) = @_;
1820: my (@fwchains,@ports);
1821: if (&firewall_is_active()) {
1822: my $iptables = &get_pathto_iptables();
1823: if ($iptables ne '') {
1824: @fwchains = &get_fw_chains($iptables,$distro);
1825: }
1826: }
1827: if (ref($apachefw) eq 'HASH') {
1828: foreach my $service ('http','https') {
1829: unless ($apachefw->{$service}) {
1830: push (@ports,$service);
1831: }
1832: }
1833: } else {
1834: @ports = ('http','https');
1835: }
1836: if (@ports == 0) {
1837: return;
1838: }
1839: my $ask_to_enable;
1840: if (-e "/etc/iptables.loncapa.rules") {
1.9 raeburn 1841: if (open(PIPE, "diff --brief $instdir/debian-ubuntu/iptables.loncapa.rules /etc/iptables.loncapa.rules |")) {
1.5 raeburn 1842: my $diffres = <PIPE>;
1843: close(PIPE);
1844: chomp($diffres);
1845: if ($diffres) {
1846: print &mt('Warning: [_1] exists but differs from LON-CAPA supplied file.','/etc/iptables.loncapa.rules')."\n";
1847: }
1848: } else {
1849: print &mt('Error: unable to open [_1] to compare contents with LON-CAPA supplied file.','/etc/iptables.loncapa.rules')."\n";
1850: }
1851: } else {
1.9 raeburn 1852: if (-e "$instdir/debian-ubuntu/iptables.loncapa.rules") {
1853: copy "$instdir/debian-ubuntu/iptables.loncapa.rules","/etc/iptables.loncapa.rules";
1.5 raeburn 1854: chmod(0600,"/etc/iptables.loncapa.rules");
1855: }
1856: }
1857: if (-e "/etc/iptables.loncapa.rules") {
1858: if (-e "/etc/network/if-pre-up.d/iptables") {
1.9 raeburn 1859: if (open(PIPE, "diff --brief $instdir/debian-ubuntu/iptables /etc/network/if-pre-up/iptables |")) {
1.5 raeburn 1860: my $diffres = <PIPE>;
1861: close(PIPE);
1862: chomp($diffres);
1863: if ($diffres) {
1864: print &mt('Warning: [_1] exists but differs from LON-CAPA supplied file.','/etc/network/if-pre-up.d/iptables')."\n";
1865: }
1866: } else {
1867: print &mt('Error: unable to open [_1] to compare contents with LON-CAPA supplied file.','/etc/network/if-pre-up.d/iptables')."\n";
1868: }
1869: } else {
1.9 raeburn 1870: copy "$instdir/debian-ubuntu/iptables","/etc/network/if-pre-up.d/iptables";
1.5 raeburn 1871: chmod(0755,"/etc/network/if-pre-up.d/iptables");
1872: print_and_log(&mt('Installed script "[_1]" to add iptables rules to block all ports except 22, 80, and 443 when network is enabled during boot.','/etc/network/if-pre-up.d/iptables'));
1873: $ask_to_enable = 1;
1874: }
1875: }
1876: return $ask_to_enable;
1.1 raeburn 1877: }
1878:
1879: sub download_loncapa {
1880: my ($instdir,$lctarball) = @_;
1881: my ($have_tarball,$updateshown);
1882: if (! -e "$instdir/$lctarball") {
1883: print_and_log(&mt('Retrieving LON-CAPA source files from: [_1]',
1884: 'http://install.loncapa.org')."\n");
1885: system("wget http://install.loncapa.org/versions/$lctarball ".
1886: "2>/dev/null 1>/dev/null");
1887: if (! -e "./$lctarball") {
1888: print &mt('Unable to retrieve LON-CAPA source files from: [_1].',
1889: "http://install.loncapa.org/versions/$lctarball")."\n";
1890: } else {
1891: $have_tarball = 1;
1892: }
1893: print_and_log("\n");
1894: } else {
1895: $have_tarball = 1;
1896: print_and_log("
1897: ------------------------------------------------------------------------
1898:
1899: ".&mt('You seem to have a version of loncapa-current.tar.gz in [_1]',$instdir)."\n".
1900: &mt('This copy will be used and a new version will NOT be downloaded.')."\n".
1901: &mt('If you wish, you may download a new version by executing:')."
1902:
1.2 raeburn 1903: wget http://install.loncapa.org/versions/loncapa-current.tar.gz
1.1 raeburn 1904:
1905: ------------------------------------------------------------------------
1906: ");
1907: }
1908:
1909: ##
1910: ## untar loncapa.tar.gz
1911: ##
1912: if ($have_tarball) {
1913: print_and_log(&mt('Extracting LON-CAPA source files')."\n");
1914: writelog(`cd ~root; tar zxf $instdir/$lctarball`);
1915: print_and_log("\n");
1916: print &mt('LON-CAPA source files extracted.')."\n".
1917: &mt('It remains for you to execute the following commands:')."
1918:
1919: cd /root/loncapa-N.N (N.N should correspond to a version number like '0.4')
1920: ./UPDATE
1921:
1922: ".&mt('If you have any trouble, please see [_1] and [_2]',
1923: 'http://install.loncapa.org/','http://help.loncapa.org/')."\n";
1924: $updateshown = 1;
1925: }
1926: return ($have_tarball,$updateshown);
1927: }
1928:
1929: close LOG;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>