Parent Directory
|
Revision Log
fixed cgi url in webworkConfig.pm: uses cgi/cgi-scripts instead of cgi/
1 #!/usr/local/bin/perl 2 # change the above line to point to the perl program 3 4 ################################################################################ 5 # system_webwork_setup.pl 6 # 7 # This file changes the permissions to the correct ones in each of the 8 # subdirectories and the main course directory. It also modifies Global.pm and 9 # the various perl scripts. 10 # 11 # $Id$ 12 ################################################################################ 13 14 #################### initialization 15 16 require 5.000; 17 use strict; 18 19 use Cwd; 20 use File::Copy; 21 22 # define built-in defaults 23 my $DEFAULT_PERL_PATH = '/usr/bin/perl'; 24 my $DEFAULT_CGI_URL = '/cgi-bin/webwork/system/'; 25 my $DEFAULT_HTML_URL = '/webwork_system_html'; 26 27 # define code strings 28 my $CGI_DEBUG_TAG = 'WeBWorKCGIDebugURL'; 29 my $CGI_NODEBUG_TAG = 'WeBWorKCGINoDebugURL'; 30 my $LIB_INIT_LINE_TAG = 'WeBWorKInitLine'; 31 32 # scope and undefine setup variables 33 our $no_prompts = undef; 34 our $system_setup_mode = undef; 35 our $mainDir = undef; 36 our $perlPath = undef; 37 our $cgiURL = undef; 38 our $htmlURL = undef; 39 our $groupName = undef; 40 our $update_stuff_in_courses = undef; 41 our $chgrp_files_and_dirs = undef; 42 our $chmod_files_and_dirs = undef; 43 our $local_preprocessor = undef; 44 our $local_postprocessor = undef; 45 46 # read defaults in from defaults file 47 my $DEFAULTS_FILE; 48 if($ARGV[0]) { $DEFAULTS_FILE = $ARGV[0]; } 49 else { $DEFAULTS_FILE = ((getpwuid $<)[7]) . '/system_webwork_setup.defaults'; } 50 if(-e $DEFAULTS_FILE) { 51 print "Reading defaults file..."; 52 require $DEFAULTS_FILE; 53 print " done.\n"; 54 } 55 56 #################### text strings 57 58 my $INTRO_TEXT = q{ 59 +----------------------+ 60 | System Webwork Setup | 61 +----------------------+ 62 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, 65 and modify files. A "demo" or "working" version of the system can be setup. 66 67 You will need the following information: 68 69 1) The path to perl on your system. Usually this is something like 70 /usr/bin/perl or /usr/local/bin/perl 71 72 2) The group (e.g. wwadmin) containing the user names of anyone who has the 73 authority to modify the webwork system files. Who ever runs this script must 74 be a member of this group. This should be set up by your system 75 administrator before running this script. (Note: This is not required for a 76 demo version.) 77 78 3) The cgi WeBWorK URL. Usually this is something like 79 http://www.math.rochester.edu/cgi-bin/webwork/system or 80 http://webwork.math.rochester.edu/cgi-bin/webwork/system. In the above 81 cases, you can just enter /cgi-bin/webwork/system which is prefered but if 82 you do, don't forget the initial / . 83 84 4) The html WeBWorK URL. Usually this is something like 85 http://www.math.rochester.edu/webwork_system_html. Again in this case 86 /webwork_system_html is prefered. 87 88 See the html document 89 webwork/system/system_html/docs/techdescription/settingupsystem.html for 90 detailed explanations. The examples here are taken from those directions. 91 92 }; 93 94 my $MODE_TEXT = q{ 95 96 You can set up a "working" or a "demo" WeBWorK system. A "demo" system 97 should only be used as a sample system, never for a system that will be used 98 with actual courses with real students. The main difference between a 99 "working" version and a "demo" version is that in a "working" version you 100 will be promped to enter a group (e.g. wwadmin) where as in a "demo" 101 version, the group will be set yo your own default group (e.g. fac). Anyone 102 in the group will have permission to modify all webwork files. You can set 103 up "working" and "demo" courses under either a "working" or a "demo" system, 104 but normally you would not set up a "working" course under a "demo" system. 105 106 }; 107 108 my $MAIN_DIR_TEXT = q{ 109 110 The directory containing the WeBWorK system files (as well as this 111 script) is known as the main directory. In order to modify system files, 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. 115 116 }; 117 118 my $PERL_TEXT = q{ 119 120 WeBWorK needs to know the path of your perl binary, so that this information 121 can be used in the headers of cgi scripts. If you were able to run this 122 script by typing "./system_webwork_setup.pl", the path to a perl binary is 123 listed on the first line of this script. 124 125 }; 126 127 my $CGI_URL_TEXT = q{ 128 129 In order for generated HTML to be able to invoke CGI scripts, WeBWorK needs 130 to know the URL which points to the main WeBWorK system cgi subdirectory. 131 For example, http://www.math.rochester.edu.edu/cgi-bin/webwork/system might 132 be a valid CGI URL. If both static HTML and CGIs reside on the same host 133 (which is true in most cases), you can omit the 134 http://www.math.rochester.edu section of the URL. Make sure to include a 135 leading slash in this case. 136 137 }; 138 139 my $HTML_URL_TEXT = q{ 140 141 WeBWorK also needs to know the URL of the main HTML directory, the system 142 html subdirectory. For example, 143 http://www.math.rochester.edu/webwork_system_html or /webwork_system_html. 144 145 }; 146 147 my $GROUP_TEXT = q{ 148 149 WeBWorK needs to know what the admin group is. This group should have been 150 set up by your system administrator and must contain at least your user ID. 151 All files and directories created will have this as their group. 152 153 }; 154 155 my $COURSE_PERMS_TEXT = q{ 156 157 You have the option to set permissions for the courses directory. If this is 158 an inital setup, you should probably do so. If this is not an initial setup, 159 the courses directory is already set up, or the courses directory is shared 160 between WeBWorK installations, your probably shouldn't. 161 162 }; 163 164 my $CHGRP_TEXT = q{ 165 166 You have to option to set the group for all system files and directories. If 167 this is an initial setup, you should probably do this. If this is not an 168 initial setup, or you have customized the way system files should be 169 grouped, you probably shoudn't. 170 171 }; 172 173 my $CHMOD_TEXT = q{ 174 175 You have to option to set the permissions for all system files and 176 directories. If this is an initial setup, you should probably do this. If 177 this is not an initial setup, or you have customized the permissions for the 178 system files, you probably shoudn't. 179 180 }; 181 182 my $CONFIRM_TEXT = q{ 183 184 Now that I have the necessary information, I can begin modifying the WeBWorK 185 system files. 186 187 }; 188 189 my $DONE_TEXT = q{ 190 191 The system setup script is done. Your WeBWorK system directory is now set up 192 correctly. 193 194 }; 195 196 197 198 199 200 ################################################################################ 201 ########## Ask some questions, perform some logic. ############################# 202 ################################################################################ 203 204 205 206 207 208 #################### introduction 209 210 my $temp; 211 212 unless($no_prompts) { 213 page($INTRO_TEXT); 214 $temp = questionChar("Do you want to continue with setup?", 'y', 'y', 'n'); 215 exit unless $temp eq 'y'; 216 } 217 print "Okay, here we go...\n"; 218 219 #################### working or demo? 220 221 unless(defined $system_setup_mode) { 222 page($MODE_TEXT); 223 $temp = questionChar("Shall we set up a working version or a demo version?", 'w', 'w', 'd'); 224 $system_setup_mode = "working" if $temp eq 'w'; 225 $system_setup_mode = "demo" if $temp eq 'd'; 226 } 227 print "System setup mode is: $system_setup_mode\n"; 228 229 #################### main directory 230 231 unless(defined $mainDir) { 232 page($MAIN_DIR_TEXT); 233 $mainDir = questionString("Where is the main WeBWorK directory?", cwd()); 234 $mainDir .= '/' unless $mainDir =~ m|/$|; # ensure trailing slash 235 } 236 print "We'll use $mainDir as WeBWorK's home.\n"; 237 238 #################### perl path 239 240 unless(defined $perlPath) { 241 page($PERL_TEXT); 242 $perlPath = questionString("What is the full path to PERL?", $DEFAULT_PERL_PATH); 243 } 244 print "Path to PERL binary is: $perlPath\n"; 245 246 #################### CGI URL 247 248 unless(defined $cgiURL) { 249 page($CGI_URL_TEXT); 250 while (1) { 251 $cgiURL = questionString("What is the CGI URL?", $DEFAULT_CGI_URL); 252 if( ($cgiURL =~ m|^/|) or ($cgiURL =~ m|^http://|) ) { 253 last; 254 } else { 255 $temp = questionChar("That doesn't look like a valid URL. Would you like to use it anyway?", 'n', 'y', 'n'); 256 last if $temp eq 'y'; 257 } 258 } 259 $cgiURL .= "/" unless $cgiURL =~ m"/$"; # ensure trailing slash 260 } 261 print "CGI URL is: $cgiURL\n"; 262 263 #################### HTML URL 264 265 unless(defined $htmlURL) { 266 page($HTML_URL_TEXT); 267 while (1) { 268 $htmlURL = questionString("What is the HTML URL?", $DEFAULT_HTML_URL); 269 if( ($htmlURL =~ m|^/|) or ($htmlURL =~ m|^http://|) ) { 270 last; 271 } else { 272 $temp = questionChar("That doesn't look like a valid URL. Would you like to use it anyway?", 'n', 'y', 'n'); 273 last if $temp eq 'y'; 274 } 275 } 276 $htmlURL .= "/" unless $htmlURL =~ m"/$" ; 277 } 278 print "HTML URL is: $htmlURL\n"; 279 280 #################### admin group 281 282 unless(defined $groupName) { 283 my ($userName, $userGID) = (getpwuid $<)[0,3]; 284 my $userGroupName = (getgrgid $userGID)[0]; 285 286 if ($system_setup_mode eq 'demo') { 287 # in demo mode, the group is set to the user's primary group 288 $groupName = $userGroupName; 289 } else { 290 # in working mode, we get to chose 291 page($GROUP_TEXT); 292 my $validGroup = 0; 293 while(1) { 294 $groupName = questionString("What is the admin group name?", $userGroupName); 295 my @members = split / /, (getgrnam $groupName)[3]; 296 if($groupName eq $userGroupName) { 297 print "$groupName is $userName's primary group. Good.\n"; 298 } elsif(grep /$userName/, @members) { 299 print "$userName is a member of $groupName. Good.\n"; 300 last; 301 } elsif($< == 0) { # we're root! 302 print "$userName isn't a member of $groupName, but you're root, so who cares?\n"; 303 last; 304 } else { 305 print "That group is not valid. Please make sure the group exists and you are a member.\n"; 306 } 307 } 308 } 309 } 310 print "Admin group is: $groupName\n"; 311 312 #################### chmod courses directory 313 314 unless(defined $update_stuff_in_courses) { 315 page($COURSE_PERMS_TEXT); 316 $temp = questionChar("Do you want to set default $system_setup_mode permissions for the courses directory?", 'y', 'y', 'n'); 317 $update_stuff_in_courses = ($temp eq 'y'); 318 } 319 print "Permissions ", ($update_stuff_in_courses ? "will" : "will not"), " be set for the courses directory.\n"; 320 321 322 #################### chgrp files/directories 323 324 $system_setup_mode eq "demo" and $chgrp_files_and_dirs = 1; 325 unless(defined $chgrp_files_and_dirs) { 326 page($CHGRP_TEXT); 327 $temp = questionChar("Do you want to set the group for system files and directories?", 'y', 'y', 'n'); 328 $chgrp_files_and_dirs = ($temp eq 'y'); 329 } 330 print "Group ", ($chgrp_files_and_dirs ? "will" : "will not"), " be set for system files and directories.\n"; 331 332 #################### chmod files/directories 333 334 $system_setup_mode eq "demo" and $chmod_files_and_dirs = 1; 335 unless(defined $chmod_files_and_dirs) { 336 page($CHMOD_TEXT); 337 $temp = questionChar("Do you want to set the permissions for system files and directories?", 'y', 'y', 'n'); 338 $chmod_files_and_dirs = ($temp eq 'y'); 339 } 340 print "Permissions ", ($chmod_files_and_dirs ? "will" : "will not"), " be set for system files and directories.\n"; 341 342 #################### make sure we want to actually do this 343 344 unless($no_prompts) { 345 print $CONFIRM_TEXT; 346 $temp = questionChar("Do you want to continue with setup?", 'y', 'y', 'n'); 347 exit unless $temp eq 'y'; 348 } 349 print "\Going to make changes now...\n\n"; 350 351 352 353 354 355 ################################################################################ 356 ########## Now we start changing things... ##################################### 357 ################################################################################ 358 359 360 361 362 363 chdir $mainDir; 364 365 #################### run local preprocessor 366 367 if(defined $local_preprocessor) { 368 print "Executing local preprocessor...\n"; 369 &$local_preprocessor; 370 print "Done with local preprocessor.\n"; 371 } 372 373 #################### update Global.pm 374 #needs: $mainDir, $cgiURL, $htmlURL 375 376 #chdir "lib"; 377 # 378 #-e 'Global.pm' or die "Global.pm doesn't exist! There's no point in continuing.\n"; 379 #if(-e 'Global.pm.bak1') { 380 # print "Copying Global.pm.bak1 -> Global.pm.bak2\n"; 381 # copy('Global.pm.bak1', 'Global.pm.bak2'); 382 #} 383 #print "Copying Global.pm -> Global.pm.bak1\n"; 384 #copy('Global.pm', 'Global.pm.bak1'); 385 # 386 #open OLD_GLOBAL, "Global.pm.bak1"; 387 #open NEW_GLOBAL, ">Global.pm"; 388 # 389 #while (<OLD_GLOBAL>) { 390 # if (/^\$mainDirectory/) { 391 # print NEW_GLOBAL "\$mainDirectory = '$mainDir';\n"; 392 # print "\$mainDirectory = '$mainDir';\n"; 393 # } elsif (/\#$CGI_DEBUG_TAG$/) { 394 # print NEW_GLOBAL "\#\$cgiWebworkURL = '$cgiURL'; \#$CGI_DEBUG_TAG\n"; 395 # print "\#\$cgiWebworkURL = '$cgiURL'; \#$CGI_DEBUG_TAG\n"; 396 # } elsif (/\#$CGI_NODEBUG_TAG$/) { 397 # print NEW_GLOBAL "\$cgiWebworkURL = '${cgiURL}cgi-scripts/'; \#$CGI_NODEBUG_TAG\n"; 398 # print "\$cgiWebworkURL = '${cgiURL}cgi-scripts/'; \#$CGI_NODEBUG_TAG\n"; 399 # } elsif (/^\$htmlWebworkURL/) { 400 # print NEW_GLOBAL "\$htmlWebworkURL = '$htmlURL';\n"; 401 # print "\$htmlWebworkURL = '$htmlURL';\n"; 402 # } else { 403 # print NEW_GLOBAL $_; 404 # } 405 #} 406 # 407 #close NEW_GLOGAL; 408 #close OLD_GLOBAL; 409 # 410 #chmod(0644, "Global.pm"); 411 #chdir ".."; 412 #print "Done updating Global.pm\n\n"; 413 414 #################### update #! and use lines 415 # uses: $mainDir, $perlPath 416 417 print "Fixing #! lines...\n"; 418 419 # fix up the course setup script and the *.pl files 420 fixFile('../courses/demoCourse/course_webwork_setup.pl') if $update_stuff_in_courses; 421 foreach my $dir ('cgi/cgi-scripts', 'scripts', 'courseScripts') { 422 foreach my $file (<${dir}/*.pl>) { 423 fixFile($file); 424 } 425 } 426 427 sub fixFile 428 { 429 my ($file) = @_; 430 431 # read the file 432 open FILE, $file || die "Couldn't open $file for reading."; 433 my @lines = <FILE>; 434 close FILE || die "Couldn't close $file after reading."; 435 436 # fix perl path 437 $lines[0] =~ m/^#!(\S*)/; 438 if($1 ne $perlPath) { 439 $lines[0] =~ s/^#!\S*/#!$perlPath/; 440 open FILE, ">$file" || die "Couldn't open $file for writing."; 441 print FILE @lines; 442 close FILE || die "Couldn't close $file for writing."; 443 } 444 } 445 446 print "done fixing #! and \"use\" lines.\n\n"; 447 448 #################### write webworkConfig.pm file 449 # uses: $mainDir, $cgiURL, $htmlURL 450 451 print "Writing lib/webworkConfig.pm file...\n"; 452 open CONFIG_FILE, ">${mainDir}lib/webworkConfig.pm"; 453 print CONFIG_FILE 454 "package Global;\n\n", 455 "\$cgiWebworkURL = \"${cgiURL}cgi-scripts/\";\n", 456 "\$htmlWebworkURL = \"$htmlURL\";\n", 457 "\$mainDirectory = \"$mainDir\";\n\n", 458 "1;"; 459 close CONFIG_FILE; 460 print "Done writing lib/webworkConfig.pm file.\n\n"; 461 462 #################### write webworkInit.pm files 463 # uses: $mainDir 464 465 print "Writing webworkInit.pm files...\n"; 466 foreach my $dir ('cgi/', 'cgi/cgi-scripts/', 'scripts/', 'courseScripts/') { 467 open INIT_FILE, ">$mainDir${dir}webworkInit.pm"; 468 print INIT_FILE 469 "use lib '${mainDir}lib/';\n\n", 470 "1;"; 471 close INIT_FILE; 472 } 473 print "Done writing webworkInit.pm files.\n\n"; 474 475 #################### chgrp system stuff 476 # uses: $chgrp_files_and_dirs, $groupName 477 478 if($chgrp_files_and_dirs) { 479 print "Setting group on system files and directories...\n"; 480 # R=recursive, P=don't follow symlinks 481 system "chgrp -PR $groupName ."; 482 print "Done setting group.\n\n"; 483 } 484 485 #################### chmod system stuff 486 # uses: $chmod_files_and_dirs 487 488 if($chmod_files_and_dirs) { 489 print "Setting permissions on system files and directories for $system_setup_mode mode...\n"; 490 if ($system_setup_mode eq "demo") { 491 # get some general permissions for files and directories 492 system "find . -type d -print0 | xargs -0 chmod 0711"; 493 system "find . -type f -print0 | xargs -0 chmod 0644"; 494 # add executable privs to scripts 495 system "find cgi scripts -type f -print0 | xargs -0 chmod 0755"; 496 # give everyone write access to logs 497 # (we should probably just be chowning the log directory to the webserver) 498 system "chmod 0666 logs/*"; 499 # make this script executable and safe 500 system "chmod 0700 system_webwork_setup.pl" 501 } else { 502 # get some general permissions for files and directories 503 system "find . -type d -print0 | xargs -0 chmod 0771"; 504 system "find . -type f -print0 | xargs -0 chmod 0664"; 505 # add executable privs to scripts 506 system "find cgi scripts -type f -print0 | xargs -0 chmod 0775"; 507 # give everyone write access to logs 508 # (we should probably just be chowning the log directory to the webserver) 509 system "find logs -type f -print0 | xargs -0 chmod 0666"; 510 # make this script executable and safe 511 system "chmod 0770 system_webwork_setup.pl" 512 } 513 print "done setting permissions.\n\n"; 514 } 515 516 #################### fix up the documemtation html files 517 # uses: $htmlURL, $cgiURL 518 519 print "Fixing image, cgi-bin, and ref lines in documentation html files...\n"; 520 foreach my $dir ('system_html/helpFiles') { 521 foreach my $file (<${dir}/*.html>) { 522 open FILE, $file || die "CAN'T READ $file!\n Fix the problem and run the setup script again"; 523 my @lines = <FILE>; 524 close FILE || die "CAN'T CLOSE $file!\n Fix the problem and run the setup script again"; 525 526 foreach my $line (@lines) { 527 $line =~ s|<IMG SRC=".*?images/|<IMG SRC="${htmlURL}images/|g; # fix "images" line 528 $line =~ s|<A HREF=".*?feedback.pl">|<A HREF="${cgiURL}feedback.pl">|g; # fix "cgi-bin" line 529 $line =~ s|<A HREF=".*?docs/">|<A HREF="${htmlURL}docs/">|g; # fix "Ref" line 530 } 531 open FILE, ">$file" || die "CAN'T WRITE $file!\n Fix the problem and run the setup script again"; 532 print FILE @lines; 533 close FILE || die "CAN'T CLOSE (writing) $file!\n Fix the problem and run the setup script again"; 534 } 535 } 536 print "done fixing documentation files.\n\n"; 537 538 #################### update couses stuff 539 # uses: $update_stuff_in_courses 540 541 if($update_stuff_in_courses) { 542 print "Setting permissions for ../courses directory.\n\n"; 543 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"; 544 } 545 546 #################### run local postprocessor 547 548 if(defined $local_postprocessor) { 549 print "Executing local preprocessor...\n"; 550 &$local_postprocessor; 551 print "Done with local preprocessor.\n"; 552 } 553 554 #################### finish up 555 556 page($DONE_TEXT); 557 558 ################################################################################ 559 560 sub page 561 { 562 my @string_lines = split /^/, shift; #/ 563 # not really optimal, but we're going to assume a constant screen height. 564 my $SCREEN_HEIGHT = 20; 565 while(@string_lines) { 566 print join "", @string_lines[0..$SCREEN_HEIGHT-1]; 567 if(scalar @string_lines >= $SCREEN_HEIGHT) { 568 print "\n[Press ENTER to continues...]"; 569 <STDIN>; 570 print "\n"; 571 } 572 @string_lines = @string_lines[$SCREEN_HEIGHT..$#string_lines]; 573 } 574 } 575 576 sub questionChar 577 { 578 my ($question, $default, @valid) = @_; 579 my $answer; 580 do { 581 print $question, " "; 582 foreach (@valid) { 583 $_ eq $default and print "["; 584 print $_; 585 $_ eq $default and print "]"; 586 } 587 print " "; 588 $answer = <STDIN>; 589 $answer =~ s/^\s*//; 590 $answer = substr $answer, 0, 1; 591 $answer = lc $answer; 592 $answer or $answer = $default; 593 } while (not grep(/$answer/, @valid)); 594 return $answer; 595 } 596 597 sub questionString 598 { 599 my ($question, $default, $emptyOK) = @_; 600 my $answer; 601 print $question, " [", $default, "] "; 602 $answer = <STDIN>; 603 chomp $answer; 604 $answer =~ s/^\s*//; 605 $answer or $answer = $default; 606 return $answer; 607 }
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |