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