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