| … | |
… | |
| 18 | |
18 | |
| 19 | use Cwd; |
19 | use Cwd; |
| 20 | use File::Copy; |
20 | use File::Copy; |
| 21 | |
21 | |
| 22 | # define built-in defaults |
22 | # define built-in defaults |
| 23 | my $DEFAULT_CHROOT_DIR = '/www/webwork-root'; |
|
|
| 24 | my $DEFAULT_PERL_PATH = '/usr/bin/perl'; |
23 | my $DEFAULT_PERL_PATH = '/usr/bin/perl'; |
| 25 | my $DEFAULT_CGI_URL = '/cgi-bin/webwork/system/'; |
24 | my $DEFAULT_CGI_URL = '/cgi-bin/webwork/system/'; |
| 26 | my $DEFAULT_HTML_URL = '/webwork_system_html'; |
25 | my $DEFAULT_HTML_URL = '/webwork_system_html'; |
| 27 | |
26 | |
| 28 | # define code strings |
27 | # define code strings |
| … | |
… | |
| 31 | my $MAIN_DIR_TAG = 'mainWeBWorKDirectory'; |
30 | my $MAIN_DIR_TAG = 'mainWeBWorKDirectory'; |
| 32 | |
31 | |
| 33 | # scope and undefine setup variables |
32 | # scope and undefine setup variables |
| 34 | our $no_prompts = undef; |
33 | our $no_prompts = undef; |
| 35 | our $system_setup_mode = undef; |
34 | our $system_setup_mode = undef; |
| 36 | our $chrootDir = undef; |
|
|
| 37 | our $mainDir = undef; |
35 | our $mainDir = undef; |
| 38 | our $perlPath = undef; |
36 | our $perlPath = undef; |
| 39 | our $cgiURL = undef; |
37 | our $cgiURL = undef; |
| 40 | our $htmlURL = undef; |
38 | our $htmlURL = undef; |
| 41 | our $groupName = undef; |
39 | our $groupName = undef; |
| … | |
… | |
| 44 | our $chmod_files_and_dirs = undef; |
42 | our $chmod_files_and_dirs = undef; |
| 45 | our $local_preprocessor = undef; |
43 | our $local_preprocessor = undef; |
| 46 | our $local_postprocessor = undef; |
44 | our $local_postprocessor = undef; |
| 47 | |
45 | |
| 48 | # read defaults in from defaults file |
46 | # read defaults in from defaults file |
|
|
47 | my $DEFAULTS_FILE; |
|
|
48 | if($ARGV[0]) { $DEFAULTS_FILE = $ARGV[0]; } |
| 49 | my $DEFAULTS_FILE = ((getpwuid $<)[7]) . '/system_webwork_setup.defaults'; |
49 | else { $DEFAULTS_FILE = ((getpwuid $<)[7]) . '/system_webwork_setup.defaults'; } |
| 50 | if(-e $DEFAULTS_FILE) { |
50 | if(-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 | |
| 63 | This script is used to setup the main WeBWorK system. It will create |
63 | This script is used to setup the main WeBWorK system. It will create |
| 64 | initialization files, set groups and permissions for files and directories, |
64 | initialization files, set groups and permissions for files and directories, |
| 65 | and modify files. A "demo" or "working" version of the system can be setup. |
65 | and modify files. A "demo" or "working" version of the system can be setup. |
| 66 | |
66 | |
| 67 | This script must be run from the the main WeBWorK system directory, for |
|
|
| 68 | example from /www/webwork/system or /www/webwork-root/webwork/system |
|
|
| 69 | You will need the following information: |
67 | You will need the following information: |
| 70 | |
68 | |
| 71 | 1) If the web server is running in a chroot environment, you need to know |
|
|
| 72 | the directory the server will see as root, usually something like |
|
|
| 73 | /www/webwork-root |
|
|
| 74 | |
|
|
| 75 | 2) The path to perl on your system. Usually this is something like |
69 | 1) 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 | |
| 78 | 3) The group (e.g. wwadmin) containing the user names of anyone who has the |
72 | 2) The group (e.g. wwadmin) containing the user names of anyone who has the |
| 79 | authority to modify the webwork system files. Who ever runs this script must |
73 | authority to modify the webwork system files. Who ever runs this script must |
| 80 | be a member of this group. This should be set up by your system |
74 | be a member of this group. This should be set up by your system |
| 81 | administrator before running this script. (Note: This is not required for a |
75 | administrator before running this script. (Note: This is not required for a |
| 82 | demo version.) |
76 | demo version.) |
| 83 | |
77 | |
| 84 | 4) The cgi WeBWorK URL. Usually this is something like |
78 | 3) The cgi WeBWorK URL. Usually this is something like |
| 85 | http://www.math.rochester.edu/cgi-bin/webwork/system or |
79 | http://www.math.rochester.edu/cgi-bin/webwork/system or |
| 86 | http://webwork.math.rochester.edu/cgi-bin/webwork/system. In the above |
80 | http://webwork.math.rochester.edu/cgi-bin/webwork/system. In the above |
| 87 | cases, you can just enter /cgi-bin/webwork/system which is prefered but if |
81 | cases, you can just enter /cgi-bin/webwork/system which is prefered but if |
| 88 | you do, don't forget the initial / . |
82 | you do, don't forget the initial / . |
| 89 | |
83 | |
| 90 | 5) The html WeBWorK URL. Usually this is something like |
84 | 4) The html WeBWorK URL. Usually this is something like |
| 91 | http://www.math.rochester.edu/webwork_system_html. Again in this case |
85 | http://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 | |
| 94 | See the html document |
88 | See the html document |
| 95 | webwork/system/system_html/docs/techdescription/settingupsystem.html for |
89 | webwork/system/system_html/docs/techdescription/settingupsystem.html for |
| … | |
… | |
| 109 | up "working" and "demo" courses under either a "working" or a "demo" system, |
103 | up "working" and "demo" courses under either a "working" or a "demo" system, |
| 110 | but normally you would not set up a "working" course under a "demo" system. |
104 | but normally you would not set up a "working" course under a "demo" system. |
| 111 | |
105 | |
| 112 | }; |
106 | }; |
| 113 | |
107 | |
| 114 | my $CHROOT_TEXT = q{ |
108 | my $MAIN_DIR_TEXT = q{ |
| 115 | |
109 | |
| 116 | If your web server is set to run chrooted (that is, it sees some directory |
110 | The directory containing the WeBWorK system files (as well as this |
| 117 | other than "/" as the root directory), WeBWorK needs to know what that |
111 | script) is known as the main directory. In order to modify system files, |
| 118 | directory is so that it can set file paths accordingly. |
112 | I need to know where the main directory for this installation is. If you |
|
|
113 | invoked this script as ./system_webwork_setup.pl, then you are already |
|
|
114 | in the main directory and can accept the default. |
| 119 | |
115 | |
| 120 | }; |
116 | }; |
| 121 | |
117 | |
| 122 | my $PERL_TEXT = q{ |
118 | my $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 | } |
| 231 | print "System setup mode is: $system_setup_mode\n"; |
227 | print "System setup mode is: $system_setup_mode\n"; |
| 232 | |
228 | |
| 233 | #################### chroot directory |
|
|
| 234 | |
|
|
| 235 | unless(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 | } |
|
|
| 243 | print "Chroot directory is: $chrootDir\n" if $chrootDir; |
|
|
| 244 | print "The web server is not chrooted.\n" unless $chrootDir; |
|
|
| 245 | |
|
|
| 246 | #################### main directory |
229 | #################### main directory |
| 247 | |
230 | |
| 248 | if(defined $mainDir) { |
231 | unless(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 | } |
| 256 | if($chrootDir) { |
|
|
| 257 | # make mainDir relative to chrootDir |
|
|
| 258 | $mainDir =~ s/^$chrootDir//; |
|
|
| 259 | #$mainDir = "$mainDir"; |
|
|
| 260 | } |
|
|
| 261 | print "We'll use $mainDir as WeBWorK's home"; |
236 | print "We'll use $mainDir as WeBWorK's home.\n"; |
| 262 | print " for chrooted scripts\nand $chrootDir$mainDir for regular scripts" if $chrootDir; |
|
|
| 263 | print ".\n"; |
|
|
| 264 | |
237 | |
| 265 | #################### perl path |
238 | #################### perl path |
| 266 | |
239 | |
| 267 | unless(defined $perlPath) { |
240 | unless(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 |
|
|
| 402 | my $fullMainDir; |
|
|
| 403 | if ($chrootDir) { |
|
|
| 404 | $fullMainDir = qq(defined(\$ENV{HTTP_HOST}) ? '$mainDir': '$chrootDir$mainDir';); |
|
|
| 405 | } else { |
|
|
| 406 | $fullMainDir = qq('$mainDir';); |
|
|
| 407 | } |
|
|
| 408 | # okay. |
|
|
| 409 | |
373 | |
| 410 | chdir "lib"; |
374 | chdir "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"; |
| 413 | if(-e 'Global.pm.bak1') { |
377 | if(-e 'Global.pm.bak1') { |
| … | |
… | |
| 420 | open OLD_GLOBAL, "Global.pm.bak1"; |
384 | open OLD_GLOBAL, "Global.pm.bak1"; |
| 421 | open NEW_GLOBAL, ">Global.pm"; |
385 | open NEW_GLOBAL, ">Global.pm"; |
| 422 | |
386 | |
| 423 | while (<OLD_GLOBAL>) { |
387 | while (<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 | |
| 460 | print "Fixing #! and \"use\" lines...\n"; |
424 | print "Fixing #! and \"use\" lines...\n"; |
| 461 | |
425 | |
| 462 | my $TAG = "mainWeBWorKDirectory"; |
|
|
| 463 | my $USE_LINE; |
|
|
| 464 | if ($chrootDir) { $USE_LINE = "use lib ('${mainDir}lib/', '${chrootDir}${mainDir}lib/'); \# $TAG\n"; } |
|
|
| 465 | else { $USE_LINE = "use lib '${mainDir}lib/'; \# $TAG\n"; } |
426 | my $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 |
| 470 | foreach my $dir ('cgi/cgi-scripts', 'scripts', 'courseScripts') { |
429 | foreach 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); |
| … | |
… | |
| 484 | sub fixFile |
443 | sub 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 | |
| 516 | print "done fixing #! and \"use\" lines.\n\n"; |
475 | print "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 |