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