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