Annotation of doc/install/redhat7.3/install.pl, revision 1.2
1.1 matthew 1: #!/usr/bin/perl -w
2: # The LearningOnline Network
3: # Red Hat 7.3 installation script
4: #
1.2 ! matthew 5: # $Id: install.pl,v 1.1 2002/06/19 19:16:54 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:
! 51: # gnuplot-3.7.1-5.i386.rpm
! 52: # libgd-1.3-4.i386.rpm
! 53: # libungif-progs-4.1.0-9.i386.rpm
! 54: # ncurses4-5.0-5.i386.rpm
! 55: # readline-2.2.1-6.i386.rpm
! 56: # readline-4.2a-4.i386.rpm
! 57: # perl-DBD-MySQL-1.2216-4.i386.rpm
! 58: # perl-DBI-1.21-1.i386.rpm
! 59: # mod_perl-1.26-5.i386.rpm
! 60: # perl-suidperl-5.6.1-34.99.6.i386.rpm
! 61: # LON-CAPA-systemperl-3.4-rh72.i386.rpm
! 62: # mysql-3.23.49-3.i386.rpm
! 63: # mysqlclient9-3.23.22-6.i386.rpm
! 64: # mysql-server-3.23.49-3.i386.rpm
! 65: # hwcrypto-1.0-3.i386.rpm
! 66: # m2crypto-0.05_snap4-2.i386.rpm
! 67: # netatalk-1.5pre6-1rh7.i386.rpm
! 68: # Other files:
! 69: # httpd.conf
! 70: # mod_auth_external-2.1.13.tar.gz
! 71: #
! 72: # The contingency plan for a 7.2 install tells the user to install these
! 73: # from the current directory.
! 74: # perl-5.6.1-34.99.6.i386.rpm
! 75: # perl-CGI-2.752-34.99.6.i386.rpm
! 76: #
! 77:
1.1 matthew 78: use strict;
79: use File::Copy;
80:
81: my $result;
82: my $test;
83:
84: # note: The filehandle LOG is global.
85: open LOG,">/tmp/loncapa_install.log" || die "Unable to open log file.\n";
86:
87: # Some friendly subroutines
88: sub die_if_nonempty {
89: my ($string,$error)=@_;
90: return if (! defined($error));
91: chomp($string);chomp($error);
92: if ($string ne '') {
93: print_and_log("$error\nHalting.\n");
94: die;
95: }
96: }
97:
98: sub make_link_or_die {
99: my ($source,$dest)=@_;
100: &die_if_nonempty
101: (`ln -fs $source $dest`,"Unable to link $source to $dest.");
102: print LOG "Link from $source to $dest made successfully\n";
103: }
104:
105: sub writelog {
106: while ($_ = shift) {
107: chomp;
108: print LOG "$_\n";
109: }
110: }
111:
112: sub print_and_log {
113: while ($_=shift) {
114: chomp;
115: print "$_\n";
116: print LOG "$_\n";
117: }
118: }
119:
120: ##
121: ## First, make sure it's a red hat system.
122: ##
123: if (! -e "/etc/redhat-release") {
124: print_and_log(<<"END");
125: *********************************************************************
126:
127: This does not a appear to be a Red-Hat system. More than likely the
128: installation will not be successful! Press control-c to abort now,
129: otherwise press enter to forge ahead and damn the torpedos.
130:
131: *********************************************************************
132: END
133: undef = <STDIN>;
134: }
135:
136:
137:
138: #
139: # The installation work begins now...
140: #
141:
142: print <<"END";
143: ********************************************************************
144:
145: Welcome to LON-CAPA
146:
147: This script will install the base software that LON-CAPA needs to
148: run properly.
149:
150: ********************************************************************
151: END
152:
153: ##
154: ## Install needed RPMS
155: ##
156: my $instdir = `pwd`;
157: chomp($instdir);
158: #
159: # This list of rpms needs to be pared down to some extent.
160: #
161:
162: my @gnuplot_rpms = (
163: "$instdir/gnuplot-3.7.1-5.i386.rpm",
164: "$instdir/libgd-1.3-4.i386.rpm",
165: "$instdir/libungif-progs-4.1.0-9.i386.rpm",
166: "$instdir/ncurses4-5.0-5.i386.rpm",
167: "$instdir/readline-2.2.1-6.i386.rpm",
168: "$instdir/readline-4.2a-4.i386.rpm"
169: );
170: my @perl_rpms = (
171: "$instdir/perl-DBD-MySQL-1.2216-4.i386.rpm",
172: "$instdir/perl-DBI-1.21-1.i386.rpm",
173: "$instdir/mod_perl-1.26-5.i386.rpm",
174: "$instdir/perl-suidperl-5.6.1-34.99.6.i386.rpm",
175: );
176: my @loncapa_perl_rpms = (
177: "$instdir/LON-CAPA-systemperl-3.4-rh72.i386.rpm"
178: );
179: my @mysql_rpms = (
180: "$instdir/mysql-3.23.49-3.i386.rpm", # okay w/o f,nd
181: "$instdir/mysqlclient9-3.23.22-6.i386.rpm", # okay w/o f,nd
182: "$instdir/mysql-server-3.23.49-3.i386.rpm", # okay w/o f,nd
183: );
184: my @misc_rpms = (
185: "$instdir/hwcrypto-1.0-3.i386.rpm", # already installed
186: "$instdir/m2crypto-0.05_snap4-2.i386.rpm", # okay w/o f,nd
187: "$instdir/netatalk-1.5pre6-1rh7.i386.rpm" # hmmmm
188: );
189: ##
190: ## Okay, I have tried being nice about this and not doing '--force --nodeps',
191: ## but it is an exercise in frustration. It would be nice to be kind, but
192: ## frankly I do not want to spend the time to figure this out.
193: ##
194: print_and_log("Installing mysql packages.\n");
195: writelog (`rpm -ivh --force --nodeps @mysql_rpms`);
196: print_and_log("Installing gnuplot packages.\n");
197: writelog (`rpm -ivh --force --nodeps @gnuplot_rpms`);
198: print_and_log("Installing LON-CAPA Perl packages.\n");
199: writelog (`rpm -ivh --force --nodeps @loncapa_perl_rpms`);
200: print_and_log("Installing Perl packages.\n");
201: writelog (`rpm -ivh --force --nodeps @perl_rpms`);
202: print_and_log("Installing misc packages.\n");
203: writelog (`rpm -ivh --force --nodeps @misc_rpms`);
204: system("/etc/init.d/sshd start");
205: print_and_log("\n");
206:
207: ##
208: ## Fix that stupid little sendmail bug
209: ##
210: print_and_log("changing permissions on root directory.\n");
211: $result = `chmod g-w,u+w /`;
212: if ($result eq '') {
213: $result = "successful\n";
214: } else {
215: die "Unable to change permissions on root directory. Halting.\n";
216: }
217: writelog ($result);
218: print_and_log("\n");
219:
220: ##
221: ## Set up www and authentication
222: ##
223: print_and_log("Creating user 'www'\n");
224: $result = `/usr/sbin/useradd www`;
225: if (! (($result eq '') || ($result =~ /user www exists/))) {
226: die "Unable to add user www. Halting.\n";
227: }
228: writelog ($result);
229: my $num = `grep ^www /etc/passwd | cut -d':' -f3`;
230: chomp $num;
231: if (int($num) == $num) {
232: writelog ("uid of www = $num\n");
233: } else {
234: die "Unable to determine UID of user www\n Halting.\n";
235: }
236: print_and_log("\n");
237:
238: ##
239: ## Patch mod_auth_external
240: ##
241: print_and_log("Setting up authentication for 'www'\n");
242: my $patch = <<"ENDPATCH";
243: 148c148
244: < #define SERVER_UIDS 99 /* user "nobody" */
245: ---
246: > #define SERVER_UIDS $num /* user "www" */
247: ENDPATCH
248:
249: if (! -e "/usr/bin/patch") {
250: print_and_log("You must install the software development tools package ".
251: "when installing RedHat.\n");
252: die;
253: }
254: &die_if_nonempty(`cd /tmp; tar zxf $instdir/mod_auth_external-2.1.13.tar.gz`,
255: "Unable to extract mod_auth_external\n");
256: my $dir = "/tmp/mod_auth_external-2.1.13/pwauth";
257: open PATCH, "| patch $dir/config.h" ||
258: die "Unable to start patch for mod_auth_external. Halting\n";
259: print PATCH $patch;
260: close PATCH;
261: print_and_log("\n");
262:
263: ##
264: ## Compile patched pwauth
265: ##
266: print_and_log("Compiling pwauth\n");
267: $result = `cd $dir/; make`;
268: my $expected = <<"END";
269: gcc -g -c -o pwauth.o pwauth.c
270: gcc -o pwauth -g pwauth.o -lcrypt
271: END
272:
273: if ($result ne $expected) {
274: die "Unable to compile patched pwauth. Halting.\n";
275: }
276: print_and_log( $result );
277:
278: ##
279: ## Install patched pwauth
280: ##
281: print_and_log("Copying pwauth to /usr/local/sbin\n");
282: if (! copy "$dir/pwauth","/usr/local/sbin/pwauth") {
283: die "Unable to copy $dir/pwauth to /usr/local/sbin/pwauth.\n$!\nHalting\n";
284: }
285: if (! chmod (06755, "/usr/local/sbin/pwauth")) {
286: die "Unable to set permissions on /usr/local/sbin/pwauth.\n";
287: }
288: print_and_log("\n");
289:
290: ##
291: ## Set up mysql
292: ##
293: print_and_log("Setting mysqld to start on boot up.\n");
294:
295: make_link_or_die("/etc/rc.d/init.d/mysqld","/etc/rc.d/rc0.d/K90mysqld");
296: make_link_or_die("/etc/rc.d/init.d/mysqld","/etc/rc.d/rc1.d/K90mysqld");
297: make_link_or_die("/etc/rc.d/init.d/mysqld","/etc/rc.d/rc2.d/S90mysqld");
298: make_link_or_die("/etc/rc.d/init.d/mysqld","/etc/rc.d/rc3.d/S90mysqld");
299: make_link_or_die("/etc/rc.d/init.d/mysqld","/etc/rc.d/rc4.d/S90mysqld");
300: make_link_or_die("/etc/rc.d/init.d/mysqld","/etc/rc.d/rc5.d/S90mysqld");
301: make_link_or_die("/etc/rc.d/init.d/mysqld","/etc/rc.d/rc6.d/K90mysqld");
302:
303: writelog("mysql links created successfully\n");
304: writelog(`/etc/rc.d/init.d/mysqld start`);
305: print_and_log("Waiting for mysql daemon to start.\n");
306: sleep 5;
307: if (`/etc/rc.d/init.d/mysqld status` !~ / is running/) {
308: die "Unable to start mysql daemon\nHalting\n";
309: }
310: print_and_log("\n");
311:
312: ##
313: ## Get root password for mysql client
314: ##
315: print <<END;
316: Please enter a root password for the mysql database.
317: It does not have to match your root account password, but you will need
318: to remember it.
319: END
320: my $rootpass = <>;
321: chomp $rootpass;
322: print_and_log("\n");
323:
324: ##
325: ## Run the damn thing (mysql, not LON-CAPA)
326: ##
327: print_and_log("Starting mysql client.\n");
328: open MYSQL, "|mysql -u root mysql" || die "Unable to start mysql\n";
329: print MYSQL <<"ENDMYSQL";
330: CREATE DATABASE loncapa;
331: INSERT INTO user (Host, User, Password)
332: VALUES ('localhost','www',password('localhostkey'));
333: GRANT ALL PRIVILEGES ON *.* TO www\@localhost;
334: SET PASSWORD FOR root\@localhost=PASSWORD('$rootpass');
335: DELETE FROM user WHERE host<>'localhost';
336: FLUSH PRIVILEGES;
337: USE loncapa;
338: 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;
339: EXIT
340: ENDMYSQL
341:
342: close MYSQL;
343: print_and_log("\n");
344:
345: ##
346: ## Kill the firewall, if it exists
347: ##
348: #
349: # A better method would be to modify the firewall rules to make
350: # the lond port open. Someday.
351: #
352: if (-e "/etc/init.d/iptables" || -e "/etc/init.d/ipchans") {
353: print_and_log("Stopping and removing your firewall\n");
354: my @tokill = ("/etc/rc.d/rc2.d/S08ipchains",
355: "/etc/rc.d/rc2.d/S08iptables",
356: "/etc/rc.d/rc3.d/S08ipchains",
357: "/etc/rc.d/rc3.d/S08iptables",
358: "/etc/rc.d/rc4.d/S08ipchains",
359: "/etc/rc.d/rc4.d/S08iptables",
360: "/etc/rc.d/rc5.d/S08ipchains",
361: "/etc/rc.d/rc5.d/S08iptables" );
362: foreach (@tokill) {
363: unlink $_ if (-e $_ );
364: }
365: writelog(`/etc/init.d/ipchains stop`);
366: writelog(`/etc/init.d/ipchains stop`);
367: print_and_log("\n");
368: }
369:
370: ##
371: ## Set up httpd
372: ##
373: print_and_log("Setting httpd to start on boot up.\n");
374:
375: make_link_or_die("/etc/rc.d/init.d/httpd","/etc/rc.d/rc0.d/K15httpd");
376: make_link_or_die("/etc/rc.d/init.d/httpd","/etc/rc.d/rc1.d/K15httpd");
377: make_link_or_die("/etc/rc.d/init.d/httpd","/etc/rc.d/rc2.d/K15httpd");
378: make_link_or_die("/etc/rc.d/init.d/httpd","/etc/rc.d/rc3.d/S85httpd");
379: make_link_or_die("/etc/rc.d/init.d/httpd","/etc/rc.d/rc4.d/K15httpd");
380: make_link_or_die("/etc/rc.d/init.d/httpd","/etc/rc.d/rc5.d/K15httpd");
381: make_link_or_die("/etc/rc.d/init.d/httpd","/etc/rc.d/rc6.d/K15httpd");
382:
383: ##
384: ## Copy our (probably lousy) httpd.conf to its rightful place
385: ##
386: print_and_log("Copying our httpd.conf to /etc/httpd/conf/httpd.conf\n");
387: copy "$instdir/httpd.conf","/etc/httpd/conf/httpd.conf";
388: chmod 0444,"/etc/httpd/conf/httpd.conf";
389: print_and_log("\n");
390:
391: ##
392: ## Retrieve loncapa.tar.gz
393: ##
394: if (! -e "$instdir/loncapa.tar.gz") {
395: print_and_log("Retrieving LON-CAPA source files from install.loncapa.org\n");
396: system("wget http://install.loncapa.org/versions/current/loncapa.tar.gz 2>/dev/null 1>/dev/null");
397: if (! -e "./loncapa.tar.gz") {
398: die("Unable to retrieve LON-CAPA source files from\n".
399: "http://install.loncapa.org/versions/current/loncapa.tar.gz\n");
400: }
401: print_and_log("\n");
402: } else {
403: print_and_log(<<"END");
404: ------------------------------------------------------------------------
405:
406: You seem to have a version of loncapa.tar.gz in $instdir.
407: This copy will be used and a new version will NOT be downloaded.
408: If you wish, you may download a new version by executing:
409:
410: wget http://install.loncapa.org/versions/current/loncapa.tar.gz
411:
412: ------------------------------------------------------------------------
413: END
414: }
415:
416: ##
417: ## untar loncapa.tar.gz
418: ##
419: print_and_log("Extracting LON-CAPA source files\n");
420: writelog(`cd ~root; tar zxf $instdir/loncapa.tar.gz`);
421: print_and_log("\n");
422:
423: my $version = `cat /etc/redhat-release`;
424: if ($version =~ /7\.2/) {
425: print_and_log(<<"END");
426: This appears to be a Red Hat 7.2 system. You need to execute the following
427: commands now:
428: rpm -Uvh perl-5.6.1-34.99.6.i386.rpm
429: rpm -Uvh perl-CGI-2.752-34.99.6.i386.rpm
430:
431: cd /root/loncapa
432: ./UPDATE
433:
434: END
435: } else {
436: ##
437: ## Assure them that everything worked okay....
438: ##
439: print <<"ENDMSG";
440: All of the extra files seem to have been installed correctly. It remains for
441: you to execute the following commands:
442:
443: cd /root/loncapa;
444: ./UPDATE
445:
446: If you have any trouble, please see http://install.loncapa.org and
447: http://help.loncapa.org.
448: ENDMSG
449: }
450:
451: close LOG;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>