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