[system] / trunk / webwork / system / system_webwork_setup.pl Repository:
ViewVC logotype

Diff of /trunk/webwork/system/system_webwork_setup.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 2 Revision 6
18 18
19use Cwd; 19use Cwd;
20use File::Copy; 20use File::Copy;
21 21
22# define built-in defaults 22# define built-in defaults
23my $DEFAULT_CHROOT_DIR = '/www/webwork-root';
24my $DEFAULT_PERL_PATH = '/usr/bin/perl'; 23my $DEFAULT_PERL_PATH = '/usr/bin/perl';
25my $DEFAULT_CGI_URL = '/cgi-bin/webwork/system/'; 24my $DEFAULT_CGI_URL = '/cgi-bin/webwork/system/';
26my $DEFAULT_HTML_URL = '/webwork_system_html'; 25my $DEFAULT_HTML_URL = '/webwork_system_html';
27 26
28# define code strings 27# define code strings
31my $MAIN_DIR_TAG = 'mainWeBWorKDirectory'; 30my $MAIN_DIR_TAG = 'mainWeBWorKDirectory';
32 31
33# scope and undefine setup variables 32# scope and undefine setup variables
34our $no_prompts = undef; 33our $no_prompts = undef;
35our $system_setup_mode = undef; 34our $system_setup_mode = undef;
36our $chrootDir = undef;
37our $mainDir = undef; 35our $mainDir = undef;
38our $perlPath = undef; 36our $perlPath = undef;
39our $cgiURL = undef; 37our $cgiURL = undef;
40our $htmlURL = undef; 38our $htmlURL = undef;
41our $groupName = undef; 39our $groupName = undef;
44our $chmod_files_and_dirs = undef; 42our $chmod_files_and_dirs = undef;
45our $local_preprocessor = undef; 43our $local_preprocessor = undef;
46our $local_postprocessor = undef; 44our $local_postprocessor = undef;
47 45
48# read defaults in from defaults file 46# read defaults in from defaults file
47my $DEFAULTS_FILE;
48if($ARGV[0]) { $DEFAULTS_FILE = $ARGV[0]; }
49my $DEFAULTS_FILE = ((getpwuid $<)[7]) . '/system_webwork_setup.defaults'; 49else { $DEFAULTS_FILE = ((getpwuid $<)[7]) . '/system_webwork_setup.defaults'; }
50if(-e $DEFAULTS_FILE) { 50if(-e $DEFAULTS_FILE) {
51 print "Reading defaults file..."; 51 print "Reading defaults file...";
52 require $DEFAULTS_FILE; 52 require $DEFAULTS_FILE;
53 print " done.\n"; 53 print " done.\n";
54} 54}
62 62
63This script is used to setup the main WeBWorK system. It will create 63This script is used to setup the main WeBWorK system. It will create
64initialization files, set groups and permissions for files and directories, 64initialization files, set groups and permissions for files and directories,
65and modify files. A "demo" or "working" version of the system can be setup. 65and modify files. A "demo" or "working" version of the system can be setup.
66 66
67This script must be run from the the main WeBWorK system directory, for
68example from /www/webwork/system or /www/webwork-root/webwork/system
69You will need the following information: 67You will need the following information:
70 68
711) If the web server is running in a chroot environment, you need to know
72the directory the server will see as root, usually something like
73/www/webwork-root
74
752) The path to perl on your system. Usually this is something like 691) The path to perl on your system. Usually this is something like
76/usr/bin/perl or /usr/local/bin/perl 70/usr/bin/perl or /usr/local/bin/perl
77 71
783) The group (e.g. wwadmin) containing the user names of anyone who has the 722) The group (e.g. wwadmin) containing the user names of anyone who has the
79authority to modify the webwork system files. Who ever runs this script must 73authority to modify the webwork system files. Who ever runs this script must
80be a member of this group. This should be set up by your system 74be a member of this group. This should be set up by your system
81administrator before running this script. (Note: This is not required for a 75administrator before running this script. (Note: This is not required for a
82demo version.) 76demo version.)
83 77
844) The cgi WeBWorK URL. Usually this is something like 783) The cgi WeBWorK URL. Usually this is something like
85http://www.math.rochester.edu/cgi-bin/webwork/system or 79http://www.math.rochester.edu/cgi-bin/webwork/system or
86http://webwork.math.rochester.edu/cgi-bin/webwork/system. In the above 80http://webwork.math.rochester.edu/cgi-bin/webwork/system. In the above
87cases, you can just enter /cgi-bin/webwork/system which is prefered but if 81cases, you can just enter /cgi-bin/webwork/system which is prefered but if
88you do, don't forget the initial / . 82you do, don't forget the initial / .
89 83
905) The html WeBWorK URL. Usually this is something like 844) The html WeBWorK URL. Usually this is something like
91http://www.math.rochester.edu/webwork_system_html. Again in this case 85http://www.math.rochester.edu/webwork_system_html. Again in this case
92/webwork_system_html is prefered. 86/webwork_system_html is prefered.
93 87
94See the html document 88See the html document
95webwork/system/system_html/docs/techdescription/settingupsystem.html for 89webwork/system/system_html/docs/techdescription/settingupsystem.html for
109up "working" and "demo" courses under either a "working" or a "demo" system, 103up "working" and "demo" courses under either a "working" or a "demo" system,
110but normally you would not set up a "working" course under a "demo" system. 104but normally you would not set up a "working" course under a "demo" system.
111 105
112}; 106};
113 107
114my $CHROOT_TEXT = q{ 108my $MAIN_DIR_TEXT = q{
115 109
116If your web server is set to run chrooted (that is, it sees some directory 110The directory containing the WeBWorK system files (as well as this
117other than "/" as the root directory), WeBWorK needs to know what that 111script) is known as the main directory. In order to modify system files,
118directory is so that it can set file paths accordingly. 112I need to know where the main directory for this installation is. If you
113invoked this script as ./system_webwork_setup.pl, then you are already
114in the main directory and can accept the default.
119 115
120}; 116};
121 117
122my $PERL_TEXT = q{ 118my $PERL_TEXT = q{
123 119
228 $system_setup_mode = "working" if $temp eq 'w'; 224 $system_setup_mode = "working" if $temp eq 'w';
229 $system_setup_mode = "demo" if $temp eq 'd'; 225 $system_setup_mode = "demo" if $temp eq 'd';
230} 226}
231print "System setup mode is: $system_setup_mode\n"; 227print "System setup mode is: $system_setup_mode\n";
232 228
233#################### chroot directory
234
235unless(defined $chrootDir) {
236 page($CHROOT_TEXT);
237 $temp = questionChar("Is the web server running in a chroot environment?", 'n', 'y', 'n');
238 if ($temp eq 'y') {
239 $chrootDir = questionString("What directory does the web server see as root?", $DEFAULT_CHROOT_DIR);
240 $chrootDir =~ s|/$||; # remove trailing slash
241 }
242}
243print "Chroot directory is: $chrootDir\n" if $chrootDir;
244print "The web server is not chrooted.\n" unless $chrootDir;
245
246#################### main directory 229#################### main directory
247 230
248if(defined $mainDir) { 231unless(defined $mainDir) {
249 chdir $mainDir; 232 page($MAIN_DIR_TEXT);
250} else { 233 $mainDir = questionString("Where is the main WeBWorK directory?", cwd());
251 use Cwd;
252 $mainDir = cwd();
253 $mainDir or die "Sorry, I couldn't get the working directory. Make sure this script is run from an interactive shell.\n";
254 $mainDir .= '/' unless $mainDir =~ m|/$|; # ensure trailing slash 234 $mainDir .= '/' unless $mainDir =~ m|/$|; # ensure trailing slash
255} 235}
256if($chrootDir) {
257 # make mainDir relative to chrootDir
258 $mainDir =~ s/^$chrootDir//;
259 #$mainDir = "$mainDir";
260}
261print "We'll use $mainDir as WeBWorK's home"; 236print "We'll use $mainDir as WeBWorK's home.\n";
262print " for chrooted scripts\nand $chrootDir$mainDir for regular scripts" if $chrootDir;
263print ".\n";
264 237
265#################### perl path 238#################### perl path
266 239
267unless(defined $perlPath) { 240unless(defined $perlPath) {
268 page($PERL_TEXT); 241 page($PERL_TEXT);
394 &$local_preprocessor; 367 &$local_preprocessor;
395 print "Done with local preprocessor.\n"; 368 print "Done with local preprocessor.\n";
396} 369}
397 370
398#################### update Global.pm 371#################### update Global.pm
399#needs: $chrootDir, $mainDir, $cgiURL, $htmlURL 372#needs: $mainDir, $cgiURL, $htmlURL
400
401# fix all this chrootDir/mainDir crap
402my $fullMainDir;
403if ($chrootDir) {
404 $fullMainDir = qq(defined(\$ENV{HTTP_HOST}) ? '$mainDir': '$chrootDir$mainDir';);
405} else {
406 $fullMainDir = qq('$mainDir';);
407}
408# okay.
409 373
410chdir "lib"; 374chdir "lib";
411 375
412-e 'Global.pm' or die "Global.pm doesn't exist! There's no point in continuing.\n"; 376-e 'Global.pm' or die "Global.pm doesn't exist! There's no point in continuing.\n";
413if(-e 'Global.pm.bak1') { 377if(-e 'Global.pm.bak1') {
420open OLD_GLOBAL, "Global.pm.bak1"; 384open OLD_GLOBAL, "Global.pm.bak1";
421open NEW_GLOBAL, ">Global.pm"; 385open NEW_GLOBAL, ">Global.pm";
422 386
423while (<OLD_GLOBAL>) { 387while (<OLD_GLOBAL>) {
424 if (/^\$mainDirectory/) { 388 if (/^\$mainDirectory/) {
425 print NEW_GLOBAL "\$mainDirectory = $fullMainDir\n"; 389 print NEW_GLOBAL "\$mainDirectory = '$mainDir';\n";
426 print "\t\$mainDirectory = $fullMainDir\n"; 390 print "\$mainDirectory = '$mainDir';\n";
427 } elsif (/\#$CGI_DEBUG_TAG$/) { 391 } elsif (/\#$CGI_DEBUG_TAG$/) {
428 print NEW_GLOBAL "\#\$cgiWebworkURL = \"$cgiURL\"\; \#$CGI_DEBUG_TAG\n"; 392 print NEW_GLOBAL "\#\$cgiWebworkURL = '$cgiURL'; \#$CGI_DEBUG_TAG\n";
429 print "\t\#\$cgiWebworkURL = \"$cgiURL\"\; \#$CGI_DEBUG_TAG\n"; 393 print "\#\$cgiWebworkURL = '$cgiURL'; \#$CGI_DEBUG_TAG\n";
430 } elsif (/\#$CGI_NODEBUG_TAG$/) { 394 } elsif (/\#$CGI_NODEBUG_TAG$/) {
431 print NEW_GLOBAL "\$cgiWebworkURL = \"${cgiURL}cgi-scripts/\"\; \#$CGI_NODEBUG_TAG\n"; 395 print NEW_GLOBAL "\$cgiWebworkURL = '${cgiURL}cgi-scripts/'; \#$CGI_NODEBUG_TAG\n";
432 print "\t\$cgiWebworkURL = \"${cgiURL}cgi-scripts/\"\; \#$CGI_NODEBUG_TAG\n"; 396 print "\$cgiWebworkURL = '${cgiURL}cgi-scripts/'; \#$CGI_NODEBUG_TAG\n";
433 } elsif (/^\$htmlWebworkURL/) { 397 } elsif (/^\$htmlWebworkURL/) {
434 print NEW_GLOBAL "\$htmlWebworkURL = \"$htmlURL\"\;\n"; 398 print NEW_GLOBAL "\$htmlWebworkURL = '$htmlURL';\n";
435 print "\t\$htmlWebworkURL = \"$htmlURL\"\;\n"; 399 print "\$htmlWebworkURL = '$htmlURL';\n";
436 } else { 400 } else {
437 print NEW_GLOBAL $_; 401 print NEW_GLOBAL $_;
438 } 402 }
439} 403}
440 404
452 print "Setting permissions for ../courses directory.\n\n"; 416 print "Setting permissions for ../courses directory.\n\n";
453 chmod(0755, '../courses') or warn "Warning: I can't set permissions for ../courses directory. It's possible that the directory doesn't exist or you don't have permission to change it.\n"; 417 chmod(0755, '../courses') or warn "Warning: I can't set permissions for ../courses directory. It's possible that the directory doesn't exist or you don't have permission to change it.\n";
454} 418}
455 419
456#################### update #! and use lines 420#################### update #! and use lines
457# uses: $chrootDir, $mainDir, $perlPath 421# uses: $mainDir, $perlPath
458# i must fix this some day 422# i must fix this some day
459 423
460print "Fixing #! and \"use\" lines...\n"; 424print "Fixing #! and \"use\" lines...\n";
461 425
462my $TAG = "mainWeBWorKDirectory";
463my $USE_LINE;
464if ($chrootDir) { $USE_LINE = "use lib ('${mainDir}lib/', '${chrootDir}${mainDir}lib/'); \# $TAG\n"; }
465else { $USE_LINE = "use lib '${mainDir}lib/'; \# $TAG\n"; } 426my $USE_LINE = "use lib '${mainDir}lib/'; \# $MAIN_DIR_TAG\n";
466 # if we want to use absolute use lib paths, we have to include both the
467 # chrooted mainDir and non-chrooted mainDir for chrooted httpds
468 427
469# fix up the *.pl files 428# fix up the *.pl files
470foreach my $dir ('cgi/cgi-scripts', 'scripts', 'courseScripts') { 429foreach my $dir ('cgi/cgi-scripts', 'scripts', 'courseScripts') {
471 foreach my $file (<${dir}/*.pl>) { 430 foreach my $file (<${dir}/*.pl>) {
472 fixFile($file, $USE_LINE); 431 fixFile($file, $USE_LINE);
484sub fixFile 443sub fixFile
485{ 444{
486 my ($file, $use_line) = @_; 445 my ($file, $use_line) = @_;
487 446
488 # read the file 447 # read the file
489 open FILE, $file || die "CAN'T READ $file!\n Fix the problem and run the setup script again"; 448 open FILE, $file || die "CAN'T READ $file!\n Fix the problem and run the setup script again";
490 my @lines = <FILE>; 449 my @lines = <FILE>;
491 close FILE || die "CAN'T CLOSE $file!\n Fix the problem and run the setup script again"; 450 close FILE || die "CAN'T CLOSE $file!\n Fix the problem and run the setup script again";
492 451
493 # fix perl path 452 # fix perl path
494 my $num = 0; 453 my $num = 0;
495 $num = $lines[0] =~ s/^#!.*/#!$perlPath/g; # fix #!... line 454 $num = $lines[0] =~ s/^#!.*/#!$perlPath/g; # fix #!... line
496 warn "couldn't fix #! line in $file\n" unless $num; 455 warn "couldn't fix #! line in $file\n" unless $num;
497 456
498 # fix use lines 457 # fix use lines
499 if($use_line) { 458 if($use_line) {
500 $num = 0; 459 $num = 0;
501 foreach (@lines) { 460 foreach (@lines) {
502 if (/^.*\#\s*\Q$TAG\E.*$/) { 461 if (/^.*\#\s*\Q$MAIN_DIR_TAG\E.*$/) {
503 $num++; 462 $num++;
504 $_ = $use_line; 463 $_ = $use_line;
505 } 464 }
506 } 465 }
507 warn "fixed $num 'use lib' lines in $file\n" if $num > 1; 466 warn "fixed $num 'use lib' lines in $file\n" if $num > 1;
508 } 467 }
509 468
510 # write the file 469 # write the file
511 open FILE, ">$file" || die "CAN'T WRITE $file!\n Fix the problem and run the setup script again"; 470 open FILE, ">$file" || die "CAN'T WRITE $file!\n Fix the problem and run the setup script again";
512 print FILE @lines; 471 print FILE @lines;
513 close FILE || die "CAN'T CLOSE (writing) $file!\n Fix the problem and run the setup script again"; 472 close FILE || die "CAN'T CLOSE (writing) $file!\n Fix the problem and run the setup script again";
514} 473}
515 474
516print "done fixing #! and \"use\" lines.\n\n"; 475print "done fixing #! and \"use\" lines.\n\n";
517 476
518#################### chgrp system stuff 477#################### chgrp system stuff
533 if ($system_setup_mode eq "demo") { 492 if ($system_setup_mode eq "demo") {
534 # get some general permissions for files and directories 493 # get some general permissions for files and directories
535 system "find . -type d -print0 | xargs -0 chmod 0711"; 494 system "find . -type d -print0 | xargs -0 chmod 0711";
536 system "find . -type f -print0 | xargs -0 chmod 0644"; 495 system "find . -type f -print0 | xargs -0 chmod 0644";
537 # add executable privs to scripts 496 # add executable privs to scripts
538 system "find cgi scripts -type f -print0 | xargs -0 chmod +x"; 497 system "find cgi scripts -type f -print0 | xargs -0 chmod 0755";
539 # give everyone write access to logs 498 # give everyone write access to logs
540 # (we should probably just be chowning the log directory to the webserver) 499 # (we should probably just be chowning the log directory to the webserver)
541 system "chmod o+w logs/*"; 500 system "chmod 0666 logs/*";
542 # make this script executable and safe 501 # make this script executable and safe
543 system "chmod u+x,o- system_webwork_setup.pl" 502 system "chmod 0700 system_webwork_setup.pl"
544 } else { 503 } else {
545 # get some general permissions for files and directories 504 # get some general permissions for files and directories
546 system "find . -type d -print0 | xargs -0 chmod 0771"; 505 system "find . -type d -print0 | xargs -0 chmod 0771";
547 system "find . -type f -print0 | xargs -0 chmod 0664"; 506 system "find . -type f -print0 | xargs -0 chmod 0664";
548 # add executable privs to scripts 507 # add executable privs to scripts
549 system "find cgi scripts -type f -print0 | xargs -0 chmod +x"; 508 system "find cgi scripts -type f -print0 | xargs -0 chmod 0775";
550 # give everyone write access to logs 509 # give everyone write access to logs
551 # (we should probably just be chowning the log directory to the webserver) 510 # (we should probably just be chowning the log directory to the webserver)
552 system "chmod o+w logs/*"; 511 system "chmod 0666 logs/*";
553 # make this script executable and safe 512 # make this script executable and safe
554 system "chmod ug+x,o- system_webwork_setup.pl" 513 system "chmod 0770 system_webwork_setup.pl"
555 } 514 }
556 print "done setting permissions.\n\n"; 515 print "done setting permissions.\n\n";
557} 516}
558 517
559#################### fix up the documemtation html files 518#################### fix up the documemtation html files

Legend:
Removed from v.2  
changed lines
  Added in v.6

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9