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