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