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