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