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