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