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