Annotation of doc/install/redhat7.3/install.pl, revision 1.25
1.1 matthew 1: #!/usr/bin/perl -w
2: # The LearningOnline Network
3: # Red Hat 7.3 installation script
4: #
1.25 ! albertel 5: # $Id: install.pl,v 1.24 2003/09/02 19:10:52 matthew Exp $
1.1 matthew 6: #
7: # Copyright Michigan State University Board of Trustees
8: #
9: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
10: #
11: # LON-CAPA is free software; you can redistribute it and/or modify
12: # it under the terms of the GNU General Public License as published by
13: # the Free Software Foundation; either version 2 of the License, or
14: # (at your option) any later version.
15: #
16: # LON-CAPA is distributed in the hope that it will be useful,
17: # but WITHOUT ANY WARRANTY; without even the implied warranty of
18: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19: # GNU General Public License for more details.
20: #
21: # You should have received a copy of the GNU General Public License
22: # along with LON-CAPA; if not, write to the Free Software
23: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24: #
25: # http://www.lon-capa.org/
26: #
1.2 matthew 27:
1.1 matthew 28: ##
29: ## Obvious flaws of this program:
30: ## Dieing on every error may be a little extreme. On the other hand,
31: ## how the heck am I supposed to know what absurd things the user
32: ## has done with their system before inflicting LON-CAPA on it?
33: ## The links to /etc/init.d for httpd and mysqld do not seem to work :(
34: ## The user is never informed of the log file (/tmp/loncapa_install.log).
35: ## It does not test the system at the end. Again, there are limits to
36: ## what nonsense we can put up with. Of course, we will have to
37: ## explain that to people at some point...
38: ## There is probably an overuse of elipses (...) in the comments.
1.2 matthew 39: ## It might be nice to check that all the files we need are here.
40: ## Appletalk is installed but does not work and gives errors on
41: ## boot up. I have not been able to find a clean way to get the
42: ## appletalk support working but the powers that be insist on it.
1.1 matthew 43: ##
1.2 matthew 44:
45: #
46: # Needed files:
47: #
48: # The following files are assumed to be present in the current
49: # directory:
50: # RPMS:
1.3 matthew 51: # ImageMagick-5.4.3.11-1.i386.rpm
52: # ImageMagick-devel-5.4.3.11-1.i386.rpm
53: # ImageMagick-perl-5.4.3.11-1.i386.rpm
1.2 matthew 54: # gnuplot-3.7.1-5.i386.rpm
55: # libgd-1.3-4.i386.rpm
56: # libungif-progs-4.1.0-9.i386.rpm
57: # ncurses4-5.0-5.i386.rpm
58: # readline-2.2.1-6.i386.rpm
59: # readline-4.2a-4.i386.rpm
60: # perl-DBD-MySQL-1.2216-4.i386.rpm
61: # perl-DBI-1.21-1.i386.rpm
62: # mod_perl-1.26-5.i386.rpm
63: # perl-suidperl-5.6.1-34.99.6.i386.rpm
1.16 matthew 64: # LON-CAPA-systemperl-3.5-rh7.i386.rpm
1.2 matthew 65: # mysql-3.23.49-3.i386.rpm
66: # mysqlclient9-3.23.22-6.i386.rpm
67: # mysql-server-3.23.49-3.i386.rpm
68: # hwcrypto-1.0-3.i386.rpm
69: # m2crypto-0.05_snap4-2.i386.rpm
1.12 matthew 70: # netpbm-9.24-3.i386.rpm
71: # netpbm-progs-9.24-3.i386.rpm
72: # krb5-libs-1.2.4-3.i386.rpm
1.2 matthew 73: # Other files:
74: # httpd.conf
75: # mod_auth_external-2.1.13.tar.gz
76: #
77: # The contingency plan for a 7.2 install tells the user to install these
78: # from the current directory.
79: # perl-5.6.1-34.99.6.i386.rpm
80: # perl-CGI-2.752-34.99.6.i386.rpm
81: #
82:
1.1 matthew 83: use strict;
84: use File::Copy;
85:
86: my $result;
87: my $test;
88:
89: # note: The filehandle LOG is global.
1.14 matthew 90: open LOG,">loncapa_install.log" || die "Unable to open log file.\n";
1.21 matthew 91:
1.25 ! albertel 92: print LOG '$Id: install.pl,v 1.24 2003/09/02 19:10:52 matthew Exp $'."\n";
1.1 matthew 93:
94: # Some friendly subroutines
95: sub die_if_nonempty {
96: my ($string,$error)=@_;
97: return if (! defined($error));
98: chomp($string);chomp($error);
99: if ($string ne '') {
100: print_and_log("$error\nHalting.\n");
101: die;
102: }
103: }
104:
105: sub make_link_or_die {
106: my ($source,$dest)=@_;
107: &die_if_nonempty
108: (`ln -fs $source $dest`,"Unable to link $source to $dest.");
109: print LOG "Link from $source to $dest made successfully\n";
110: }
111:
112: sub writelog {
113: while ($_ = shift) {
114: chomp;
115: print LOG "$_\n";
116: }
117: }
118:
119: sub print_and_log {
120: while ($_=shift) {
121: chomp;
122: print "$_\n";
123: print LOG "$_\n";
124: }
125: }
126:
127: ##
128: ## First, make sure it's a red hat system.
129: ##
130: if (! -e "/etc/redhat-release") {
131: print_and_log(<<"END");
132: *********************************************************************
133:
134: This does not a appear to be a Red-Hat system. More than likely the
135: installation will not be successful! Press control-c to abort now,
136: otherwise press enter to forge ahead and damn the torpedos.
137:
138: *********************************************************************
139: END
140: undef = <STDIN>;
141: }
142:
143:
144:
145: #
146: # The installation work begins now...
147: #
148:
149: print <<"END";
150: ********************************************************************
151:
1.20 matthew 152: Welcome to LON-CAPA
1.1 matthew 153:
154: This script will install the base software that LON-CAPA needs to
155: run properly.
156:
157: ********************************************************************
158: END
159:
160: ##
161: ## Install needed RPMS
162: ##
163: my $instdir = `pwd`;
164: chomp($instdir);
165: #
166: # This list of rpms needs to be pared down to some extent.
167: #
168:
1.4 matthew 169: my @apache_rpms = (
1.16 matthew 170: "$instdir/apache-1.3.23-14.i386.rpm",
1.4 matthew 171: );
172:
173: my @openssh_rpms = (
174: "$instdir/openssh-3.1p1-6.i386.rpm",
175: "$instdir/openssh-askpass-3.1p1-6.i386.rpm",
176: "$instdir/openssh-clients-3.1p1-6.i386.rpm",
177: "$instdir/openssh-server-3.1p1-6.i386.rpm"
178: );
1.16 matthew 179:
1.4 matthew 180: # Check for gnome-askpass installation.
181: if (-e "/etc/profile.d/gnome-ssh-askpass.sh") {
182: push @openssh_rpms,"$instdir/openssh-askpass-gnome-3.1p1-6.i386.rpm";
183: }
184:
1.16 matthew 185: my @ImageMagick_rpms = (
1.3 matthew 186: "$instdir/ImageMagick-5.4.3.11-1.i386.rpm",
187: "$instdir/ImageMagick-devel-5.4.3.11-1.i386.rpm",
188: "$instdir/ImageMagick-perl-5.4.3.11-1.i386.rpm",
189: );
190:
1.16 matthew 191: my @mysql_rpms = (
192: "$instdir/mysql-3.23.49-3.i386.rpm",
193: "$instdir/mysqlclient9-3.23.22-6.i386.rpm",
194: "$instdir/mysql-server-3.23.49-3.i386.rpm",
195: );
196:
1.1 matthew 197: my @perl_rpms = (
198: "$instdir/perl-DBD-MySQL-1.2216-4.i386.rpm",
199: "$instdir/perl-DBI-1.21-1.i386.rpm",
200: "$instdir/perl-suidperl-5.6.1-34.99.6.i386.rpm",
201: );
1.16 matthew 202:
203: my @old_readline_rpms = (
204: "$instdir/readline-2.2.1-6.i386.rpm", # requires -i --oldpackage,
205: # not -Uvh
206: );
207: my @gnuplot_rpms = ( # must be done after readline-2.2.1-6
208: "$instdir/libgd-1.3-4.i386.rpm",
209: "$instdir/libungif-progs-4.1.0-9.i386.rpm",
210: "$instdir/ncurses4-5.0-5.i386.rpm",
211: "$instdir/gnuplot-3.7.1-5.i386.rpm",
212: );
213:
1.1 matthew 214: my @loncapa_perl_rpms = (
1.12 matthew 215: "$instdir/netpbm-9.24-3.i386.rpm",
216: "$instdir/netpbm-progs-9.24-3.i386.rpm",
217: "$instdir/krb5-libs-1.2.4-3.i386.rpm",
1.13 matthew 218: "$instdir/krb5-devel-1.2.4-3.i386.rpm",
1.12 matthew 219: "$instdir/LON-CAPA-krb4-3.1-1.i386.rpm",
1.1 matthew 220: );
221: my @misc_rpms = (
1.16 matthew 222: "$instdir/m2crypto-0.05_snap4-2.i386.rpm",
223: "$instdir/tetex-dvips-1.0.7-47.i386.rpm",
224: "$instdir/ntp-4.1.1-1.i386.rpm",
225: "$instdir/libcap-1.10-8.i386.rpm",
1.1 matthew 226: );
1.16 matthew 227:
1.22 matthew 228: my $systemperl = "$instdir/LON-CAPA-systemperl-3.7-rh7.i386.rpm";
1.16 matthew 229:
230: ##
231: ## Some of these rpm commands require being obnoxious (--force --nodeps)
232: ## this is not a nice thing to do and we should be careful about it.
1.1 matthew 233: ##
1.16 matthew 234:
1.24 matthew 235:
236:
1.16 matthew 237: &print_and_log("Installing Apache packages.\n");
1.24 matthew 238: &writelog (`rpm -Uvh --replacepkgs @apache_rpms`);
1.16 matthew 239: &print_and_log("Installing openssh packages.\n");
1.24 matthew 240: &writelog (`rpm -Uvh --replacepkgs @openssh_rpms`);
1.16 matthew 241: &writelog(`/etc/init.d/sshd start`);
242: &print_and_log("Installing ImageMagick packages.\n");
1.24 matthew 243: &writelog (`rpm -Uvh --replacepkgs @ImageMagick_rpms`);
1.16 matthew 244: &print_and_log("Installing mysql packages.\n");
1.24 matthew 245: &writelog (`rpm -Uvh --replacepkgs @mysql_rpms`);
1.16 matthew 246: &print_and_log("Installing Perl packages.\n");
1.25 ! albertel 247: &writelog (`rpm -Uvh --replacepkgs @perl_rpms`);
1.16 matthew 248: &print_and_log("Installing legacy readline package (required for gnuplot).");
249: &writelog(`rpm -i --oldpackage @old_readline_rpms`);
250: &print_and_log("Installing gnuplot packages.\n");
251: &writelog (`rpm -ivh --force --nodeps @gnuplot_rpms`);
252: &print_and_log("Installing LON-CAPA Perl packages.\n");
1.24 matthew 253: &writelog (`rpm -Uvh --replacepkgs @loncapa_perl_rpms`);
1.16 matthew 254: &print_and_log("Installing misc packages.\n");
1.24 matthew 255: &writelog (`rpm -Uvh --replacepkgs @misc_rpms`);
1.16 matthew 256: &print_and_log("Installing LON-CAPA systemperl rpm");
257: &writelog(`rpm -ivh --force --nodeps $systemperl`);
258: &print_and_log("\n");
259:
260:
261: ##
262: ## Remove conflicting packages
263: ##
264: my @php_rpms = ("php-imap-4.1.2-7",
265: "asp2php-0.76.2-1",
266: "php-ldap-4.1.2-7",
267: "php-devel-4.1.2-7",
1.19 matthew 268: "php-4.1.2-7",
269: "php-pgsql-4.1.2-7");
1.16 matthew 270:
271: &print_and_log("Removing php packages");
272: foreach my $php_rpm (@php_rpms) {
273: my $remove_error = system("rpm -e --nodeps ".$php_rpm);
274: if ($remove_error) {
275: &print_and_log("Unable to remove ".$php_rpm.". ".
276: "Assuming it is not present.\n");
277: } else {
278: &writelog("Successfully removed ".$php_rpm);
279: }
280: }
1.23 matthew 281:
282: &print_and_log("Removing mod_throttle");
283: system("rpm -e `rpm -q -a | grep mod_throttle`");
284: &print_and_log("Removing mod_bandwidth");
285: system("rpm -e `rpm -q -a | grep mod_bandwidth`");
1.1 matthew 286:
287: ##
288: ## Fix that stupid little sendmail bug
289: ##
290: print_and_log("changing permissions on root directory.\n");
291: $result = `chmod g-w,u+w /`;
292: if ($result eq '') {
293: $result = "successful\n";
294: } else {
295: die "Unable to change permissions on root directory. Halting.\n";
296: }
297: writelog ($result);
298: print_and_log("\n");
299:
300: ##
301: ## Set up www and authentication
302: ##
303: print_and_log("Creating user 'www'\n");
304: $result = `/usr/sbin/useradd www`;
305: if (! (($result eq '') || ($result =~ /user www exists/))) {
306: die "Unable to add user www. Halting.\n";
307: }
308: writelog ($result);
309: my $num = `grep ^www /etc/passwd | cut -d':' -f3`;
310: chomp $num;
311: if (int($num) == $num) {
312: writelog ("uid of www = $num\n");
313: } else {
314: die "Unable to determine UID of user www\n Halting.\n";
315: }
316: print_and_log("\n");
317:
318: ##
319: ## Patch mod_auth_external
320: ##
321: print_and_log("Setting up authentication for 'www'\n");
322: my $patch = <<"ENDPATCH";
323: 148c148
324: < #define SERVER_UIDS 99 /* user "nobody" */
325: ---
326: > #define SERVER_UIDS $num /* user "www" */
327: ENDPATCH
328:
329: if (! -e "/usr/bin/patch") {
330: print_and_log("You must install the software development tools package ".
331: "when installing RedHat.\n");
332: die;
333: }
334: &die_if_nonempty(`cd /tmp; tar zxf $instdir/mod_auth_external-2.1.13.tar.gz`,
335: "Unable to extract mod_auth_external\n");
336: my $dir = "/tmp/mod_auth_external-2.1.13/pwauth";
337: open PATCH, "| patch $dir/config.h" ||
338: die "Unable to start patch for mod_auth_external. Halting\n";
339: print PATCH $patch;
340: close PATCH;
341: print_and_log("\n");
342:
343: ##
344: ## Compile patched pwauth
345: ##
346: print_and_log("Compiling pwauth\n");
347: $result = `cd $dir/; make`;
348: my $expected = <<"END";
349: gcc -g -c -o pwauth.o pwauth.c
350: gcc -o pwauth -g pwauth.o -lcrypt
351: END
352:
353: if ($result ne $expected) {
354: die "Unable to compile patched pwauth. Halting.\n";
355: }
356: print_and_log( $result );
357:
358: ##
359: ## Install patched pwauth
360: ##
361: print_and_log("Copying pwauth to /usr/local/sbin\n");
362: if (! copy "$dir/pwauth","/usr/local/sbin/pwauth") {
363: die "Unable to copy $dir/pwauth to /usr/local/sbin/pwauth.\n$!\nHalting\n";
364: }
365: if (! chmod (06755, "/usr/local/sbin/pwauth")) {
366: die "Unable to set permissions on /usr/local/sbin/pwauth.\n";
367: }
368: print_and_log("\n");
369:
370: ##
371: ## Set up mysql
372: ##
373: print_and_log("Setting mysqld to start on boot up.\n");
1.18 harris41 374: system("/sbin/chkconfig --add mysqld");
375: system("/sbin/chkconfig mysqld on");
376: &writelog(`/sbin/chkconfig --list mysqld`);
1.1 matthew 377:
378: writelog("mysql links created successfully\n");
379: writelog(`/etc/rc.d/init.d/mysqld start`);
380: print_and_log("Waiting for mysql daemon to start.\n");
381: sleep 5;
1.4 matthew 382: my $status = system("/etc/rc.d/init.d/mysqld status");
383: if ($status != 0) {
1.1 matthew 384: die "Unable to start mysql daemon\nHalting\n";
1.4 matthew 385: } else {
386: print_and_log("Mysql daemon is running.\n");
1.1 matthew 387: }
388: print_and_log("\n");
389:
390: ##
391: ## Get root password for mysql client
392: ##
393: print <<END;
394: Please enter a root password for the mysql database.
395: It does not have to match your root account password, but you will need
396: to remember it.
397: END
398: my $rootpass = <>;
399: chomp $rootpass;
400: print_and_log("\n");
401:
402: ##
403: ## Run the damn thing (mysql, not LON-CAPA)
404: ##
405: print_and_log("Starting mysql client.\n");
406: open MYSQL, "|mysql -u root mysql" || die "Unable to start mysql\n";
407: print MYSQL <<"ENDMYSQL";
408: CREATE DATABASE loncapa;
409: INSERT INTO user (Host, User, Password)
410: VALUES ('localhost','www',password('localhostkey'));
1.11 harris41 411: INSERT INTO db VALUES ('localhost','loncapa','www',
412: 'Y','Y','Y','Y','Y','Y','N','Y','Y','Y');
1.1 matthew 413: SET PASSWORD FOR root\@localhost=PASSWORD('$rootpass');
414: DELETE FROM user WHERE host<>'localhost';
415: FLUSH PRIVILEGES;
416: USE loncapa;
417: 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, 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)) TYPE=MYISAM;
418: EXIT
419: ENDMYSQL
420:
421: close MYSQL;
422: print_and_log("\n");
423:
424: ##
1.17 matthew 425: ## Remove the firewall.
1.1 matthew 426: ##
1.18 harris41 427: system("/sbin/chkconfig ipchains off");
1.17 matthew 428: system("/etc/init.d/ipchains stop");
1.19 matthew 429: system("/sbin/chkconfig iptables off");
430: system("/etc/init.d/iptables stop");
1.17 matthew 431:
432: # Someday we will add these to /etc/sysconfig/ipchains.
433: # "-A input -s 0/0 -d 0/0 8080 -p tcp -y -j ACCEPT",
434: # "-A input -s 0/0 -d 0/0 5663 -p tcp -y -j ACCEPT"
435: # Someday we will deal with iptables, too. Soon.
1.1 matthew 436:
437: ##
438: ## Set up httpd
439: ##
440: print_and_log("Setting httpd to start on boot up.\n");
1.18 harris41 441: system("/sbin/chkconfig httpd on");
1.1 matthew 442:
443: ##
444: ## Copy our (probably lousy) httpd.conf to its rightful place
445: ##
446: print_and_log("Copying our httpd.conf to /etc/httpd/conf/httpd.conf\n");
447: copy "$instdir/httpd.conf","/etc/httpd/conf/httpd.conf";
448: chmod 0444,"/etc/httpd/conf/httpd.conf";
449: print_and_log("\n");
450:
451: ##
452: ## Retrieve loncapa.tar.gz
453: ##
1.15 matthew 454: my $lctarball = 'loncapa-current.tar.gz';
455: if (! -e "$instdir/$lctarball") {
456: print_and_log("Retrieving LON-CAPA source files from install.loncapa.org\n")
457: ;
1.16 matthew 458: system("wget http://install.loncapa.org/versions/$lctarball 2>/dev/null 1>/dev/null");
1.15 matthew 459: if (! -e "./$lctarball") {
1.1 matthew 460: die("Unable to retrieve LON-CAPA source files from\n".
1.15 matthew 461: "http://install.loncapa.org/versions/$lctarball\n");
1.1 matthew 462: }
463: print_and_log("\n");
464: } else {
465: print_and_log(<<"END");
466: ------------------------------------------------------------------------
467:
1.5 harris41 468: You seem to have a version of loncapa-current.tar.gz in $instdir.
1.1 matthew 469: This copy will be used and a new version will NOT be downloaded.
470: If you wish, you may download a new version by executing:
471:
1.5 harris41 472: wget http://install.loncapa.org/versions/loncapa-current.tar.gz
1.1 matthew 473:
474: ------------------------------------------------------------------------
475: END
476: }
477:
478: ##
479: ## untar loncapa.tar.gz
480: ##
481: print_and_log("Extracting LON-CAPA source files\n");
1.5 harris41 482: writelog(`cd ~root; tar zxf $instdir/loncapa-current.tar.gz`);
1.1 matthew 483: print_and_log("\n");
484:
485: my $version = `cat /etc/redhat-release`;
486: if ($version =~ /7\.2/) {
487: print_and_log(<<"END");
488: This appears to be a Red Hat 7.2 system. You need to execute the following
489: commands now:
490: rpm -Uvh perl-5.6.1-34.99.6.i386.rpm
491: rpm -Uvh perl-CGI-2.752-34.99.6.i386.rpm
492:
1.7 harris41 493: cd /root/loncapa-N.N (N.N should correspond to a version number like '0.4')
1.1 matthew 494: ./UPDATE
495:
496: END
497: } else {
498: ##
499: ## Assure them that everything worked okay....
500: ##
501: print <<"ENDMSG";
502: All of the extra files seem to have been installed correctly. It remains for
503: you to execute the following commands:
504:
1.7 harris41 505: cd /root/loncapa-N.N (N.N should correspond to a version number like '0.4')
1.1 matthew 506: ./UPDATE
507:
1.5 harris41 508: If you have any trouble, please see http://install.loncapa.org/ and
509: http://help.loncapa.org/.
1.1 matthew 510: ENDMSG
511: }
512:
513: close LOG;
1.4 matthew 514:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>