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