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