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