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