Parent Directory
|
Revision Log
setup script now changes group and permission for pg directory and its contents. Arnie
1 #!/usr/local/bin/perl 2 3 ################################################################################ 4 # WeBWorK 5 # 6 # Copyright (c) 1995-2001 WeBWorK Team, University of Rochester 7 # All rights reserved 8 # 9 # $Id$ 10 ################################################################################ 11 12 #################### initialization 13 14 require 5.000; 15 use Cwd; 16 use File::Copy; 17 18 # define built-in defaults 19 my $DEFAULT_PERL_PATH = '/usr/local/bin/perl'; 20 my $DEFAULT_CGI_URL = '/cgi-bin/webwork/system/'; 21 my $DEFAULT_HTML_URL = '/webwork_system_html/'; 22 my $DEFAULT_ADMIN_GROUP = 'wwadmin'; 23 24 # define code strings 25 my $CGI_DEBUG_TAG = 'WeBWorKCGIDebugURL'; 26 my $CGI_NODEBUG_TAG = 'WeBWorKCGINoDebugURL'; 27 my $LIB_INIT_LINE_TAG = 'WeBWorKInitLine'; 28 29 # scope and undefine setup variables 30 $no_prompts = undef; 31 $system_setup_mode = undef; 32 $mainDir = undef; 33 $perlPath = undef; 34 $cgiURL = undef; 35 $htmlURL = undef; 36 $groupName = undef; 37 $update_stuff_in_courses = undef; 38 $chgrp_files_and_dirs = undef; 39 $chmod_files_and_dirs = undef; 40 $local_preprocessor = undef; 41 $local_postprocessor = undef; 42 43 # read defaults in from defaults file 44 my $DEFAULTS_FILE; 45 if($ARGV[0] and $ARGV[0] eq '-d') { 46 if($ARGV[1]) { $DEFAULTS_FILE = $ARGV[1]; } 47 else { $DEFAULTS_FILE = ((getpwuid $<)[7]) . '/system_webwork_setup.defaults'; } 48 if(-e $DEFAULTS_FILE) { 49 print "Reading defaults file..."; 50 require $DEFAULTS_FILE; 51 print " done.\n"; 52 } 53 } 54 55 #################### text strings 56 57 my $INTRO_TEXT = q{ 58 +----------------------+ 59 | System Webwork Setup | 60 +----------------------+ 61 62 This script is used to setup the main WeBWorK system. It will create 63 initialization files, set groups and permissions for files and directories, 64 and modify files. A "demo" or "working" version of the system can be setup. 65 66 You will need the following information: 67 68 1) The location of your WeBWorK system directory. 69 Example: /usr/local/webwork/system/ 70 Example: /var/www/webwork/system/ 71 72 2) The path to perl on your system. 73 Example: /usr/bin/perl 74 Example: /usr/local/bin/perl 75 76 3) The group containing the users who have the authority to modify the 77 webwork system files. Who ever runs this script must be a member of 78 this group. (Note: This is not required for the demo mode.) 79 Example: wwadmin 80 81 4) The URL to the WeBWorK CGI scripts. 82 Example: /cgi-bin/webwork/system/ (preferred) 83 84 5) The URL to the static system_html files. 85 Example: /webwork_system_html/ 86 87 }; 88 89 my $MODE_TEXT = q{ 90 91 You can set up a "working" or a "demo" WeBWorK system. A "demo" system 92 should only be used as a sample system, never for a system that will be used 93 with actual courses with real students. The main difference between a 94 "working" version and a "demo" version is that in a "working" version you 95 will be promped to enter a group (e.g. wwadmin) where as in a "demo" 96 version, the group will be set yo your own default group (e.g. fac). Anyone 97 in the group will have permission to modify all webwork files. You can set 98 up "working" and "demo" courses under either a "working" or a "demo" system, 99 but normally you would not set up a "working" course under a "demo" system. 100 101 }; 102 103 my $MAIN_DIR_TEXT = q{ 104 105 The directory containing the WeBWorK system files (as well as this 106 script) is known as the system directory. In order to modify system 107 files, I need to know the location of the system directory for this 108 installation. 109 110 }; 111 112 my $PERL_TEXT = q{ 113 114 WeBWorK needs to know the path of your perl binary, so that this 115 information can be used in the headers of cgi scripts. Please make sure 116 that the version of perl you specify is 5.004 or later. 117 118 }; 119 120 my $CGI_URL_TEXT = q{ 121 122 In order for generated HTML to be able to invoke CGI scripts, WeBWorK 123 needs to know the URL which points to the main WeBWorK system cgi 124 subdirectory. If both static HTML and CGIs reside on the same host 125 (which is true in most cases), you can omit the http://hostname section 126 of the URL, but make sure the leading slash is present. 127 128 }; 129 130 my $HTML_URL_TEXT = q{ 131 132 WeBWorK also needs to know the URL of the main HTML directory, the 133 system_html subdirectory. If both static HTML and CGIs reside on the 134 same host (which is true in most cases), you can omit the 135 http://hostname section of the URL, but make sure the leading slash is 136 present. 137 138 }; 139 140 my $GROUP_TEXT = q{ 141 142 WeBWorK needs to know what the admin group is. This group should have been 143 set up by your system administrator and must contain at least your user ID. 144 All files and directories created will have this as their group. 145 146 }; 147 148 my $COURSE_PERMS_TEXT = q{ 149 150 You have the option to set permissions for the courses directory. If this is 151 an inital setup, you should probably do so. If this is not an initial setup, 152 the courses directory is already set up, or the courses directory is shared 153 between WeBWorK installations, your probably shouldn't. 154 155 }; 156 157 my $CHGRP_TEXT = q{ 158 159 You have to option to set the group for all system files and directories. If 160 this is an initial setup, you should probably do this. If this is not an 161 initial setup, or you have customized the way system files should be 162 grouped, you probably shoudn't. 163 164 }; 165 166 my $CHMOD_TEXT = q{ 167 168 You have to option to set the permissions for all system files and 169 directories. If this is an initial setup, you should probably do this. If 170 this is not an initial setup, or you have customized the permissions for the 171 system files, you probably shoudn't. 172 173 }; 174 175 my $CONFIRM_TEXT = q{ 176 177 Now that I have the necessary information, I can begin modifying the WeBWorK 178 system files. 179 180 }; 181 182 my $DONE_TEXT = q{ 183 184 The system setup script is done. Please read the above messages 185 carefully to determine if there have been any errors. If so, correct the 186 problem (usually a permissions problem) and run this script again. 187 188 }; 189 190 191 192 193 194 ################################################################################ 195 ########## Ask some questions, perform some logic. ############################# 196 ################################################################################ 197 198 199 200 201 202 #################### introduction 203 204 my $temp; 205 206 unless($no_prompts) { 207 page($INTRO_TEXT); 208 $temp = questionChar("Do you want to continue with setup?", 'y', 'y', 'n'); 209 exit unless $temp eq 'y'; 210 } 211 print "Okay, here we go...\n"; 212 213 #################### working or demo? 214 215 unless(defined $system_setup_mode) { 216 page($MODE_TEXT); 217 $temp = questionChar("Shall we set up a working version or a demo version?", 'w', 'w', 'd'); 218 $system_setup_mode = "working" if $temp eq 'w'; 219 $system_setup_mode = "demo" if $temp eq 'd'; 220 } 221 print "System setup mode is: $system_setup_mode\n"; 222 223 #################### main directory 224 225 unless(defined $mainDir) { 226 page($MAIN_DIR_TEXT); 227 $mainDir = questionString("Where is the WeBWorK system directory?", cwd()); 228 $mainDir .= '/' unless $mainDir =~ m|/$|; # ensure trailing slash 229 } 230 print "We'll use $mainDir as WeBWorK's system directory.\n"; 231 232 #################### perl path 233 234 unless(defined $perlPath) { 235 page($PERL_TEXT); 236 $perlPath = questionString("What is the full path to PERL?", $DEFAULT_PERL_PATH); 237 } 238 print "Path to PERL binary is: $perlPath\n"; 239 240 #################### CGI URL 241 242 unless(defined $cgiURL) { 243 page($CGI_URL_TEXT); 244 while (1) { 245 $cgiURL = questionString("What is the CGI URL?", $DEFAULT_CGI_URL); 246 if( ($cgiURL =~ m|^/|) or ($cgiURL =~ m|^http://|) ) { 247 last; 248 } else { 249 $temp = questionChar("That doesn't look like a valid URL. Would you like to use it anyway?", 'n', 'y', 'n'); 250 last if $temp eq 'y'; 251 } 252 } 253 $cgiURL .= "/" unless $cgiURL =~ m"/$"; # ensure trailing slash 254 } 255 print "CGI URL is: $cgiURL\n"; 256 257 #################### HTML URL 258 259 unless(defined $htmlURL) { 260 page($HTML_URL_TEXT); 261 while (1) { 262 $htmlURL = questionString("What is the HTML URL?", $DEFAULT_HTML_URL); 263 if( ($htmlURL =~ m|^/|) or ($htmlURL =~ m|^http://|) ) { 264 last; 265 } else { 266 $temp = questionChar("That doesn't look like a valid URL. Would you like to use it anyway?", 'n', 'y', 'n'); 267 last if $temp eq 'y'; 268 } 269 } 270 $htmlURL .= "/" unless $htmlURL =~ m"/$" ; 271 } 272 print "HTML URL is: $htmlURL\n"; 273 274 #################### admin group 275 276 unless(defined $groupName) { 277 my ($userName, $userGID) = (getpwuid $<)[0,3]; 278 my $userGroupName = (getgrgid $userGID)[0]; 279 280 if ($system_setup_mode eq 'demo') { 281 # in demo mode, the group is set to the user's primary group 282 $groupName = $userGroupName; 283 } else { 284 # in working mode, we get to chose 285 page($GROUP_TEXT); 286 while(1) { 287 $groupName = questionString("What is the admin group name?", $DEFAULT_ADMIN_GROUP); 288 my @group = getgrnam $groupName; 289 unless(@group) { 290 print "$groupName does not exist.\n"; 291 next; 292 } 293 my @members = split / /, $group[3]; 294 if($groupName eq $userGroupName) { 295 print "$groupName is ${userName}'s primary group. Good.\n"; 296 last; 297 } elsif(grep { $_ eq $userName } @members) { 298 print "$userName is a member of $groupName. Good.\n"; 299 last; 300 } elsif($< == 0) { # we're root! 301 print "$userName isn't a member of $groupName, but you're root, so who cares?\n"; 302 last; 303 } else { 304 print "$groupName is not a valid group. Please make sure the group exists and $userName are a member.\n"; 305 } 306 } 307 } 308 } 309 print "Admin group is: $groupName\n"; 310 311 #################### chmod courses directory 312 313 unless(defined $update_stuff_in_courses) { 314 page($COURSE_PERMS_TEXT); 315 $temp = questionChar("Do you want to set default $system_setup_mode permissions for the courses directory?", 'y', 'y', 'n'); 316 $update_stuff_in_courses = ($temp eq 'y'); 317 } 318 print "Permissions ", ($update_stuff_in_courses ? "will" : "will not"), " be set for the courses directory.\n"; 319 320 321 #################### chgrp files/directories 322 323 $system_setup_mode eq "demo" and $chgrp_files_and_dirs = 1; 324 unless(defined $chgrp_files_and_dirs) { 325 page($CHGRP_TEXT); 326 $temp = questionChar("Do you want to set the group for system files and directories?", 'y', 'y', 'n'); 327 $chgrp_files_and_dirs = ($temp eq 'y'); 328 } 329 print "Group ", ($chgrp_files_and_dirs ? "will" : "will not"), " be set for system files and directories.\n"; 330 331 #################### chmod files/directories 332 333 $system_setup_mode eq "demo" and $chmod_files_and_dirs = 1; 334 unless(defined $chmod_files_and_dirs) { 335 page($CHMOD_TEXT); 336 $temp = questionChar("Do you want to set the permissions for system files and directories?", 'y', 'y', 'n'); 337 $chmod_files_and_dirs = ($temp eq 'y'); 338 } 339 print "Permissions ", ($chmod_files_and_dirs ? "will" : "will not"), " be set for system files and directories.\n"; 340 341 #################### make sure we want to actually do this 342 343 unless($no_prompts) { 344 print $CONFIRM_TEXT; 345 $temp = questionChar("Do you want to continue with setup?", 'y', 'y', 'n'); 346 exit unless $temp eq 'y'; 347 } 348 print "\Going to make changes now...\n\n"; 349 350 351 352 353 354 ################################################################################ 355 ########## Now we start changing things... ##################################### 356 ################################################################################ 357 358 359 360 361 362 #################### run local preprocessor 363 364 if(defined $local_preprocessor) { 365 print "Executing local preprocessor...\n"; 366 &$local_preprocessor; 367 print "Done with local preprocessor.\n"; 368 } 369 370 #################### update #! and use lines 371 # uses: $mainDir, $perlPath 372 373 print "Fixing #! lines...\n"; 374 375 foreach my $dir ("${mainDir}cgi/cgi-scripts", "${mainDir}scripts", "${mainDir}courseScripts") { 376 foreach my $file (<${dir}/*.pl>) { 377 fixFile($file); 378 } 379 } 380 381 sub fixFile 382 { 383 my ($file) = @_; 384 385 # read the file 386 open FILE, $file || die "Couldn't open $file for reading."; 387 my @lines = <FILE>; 388 close FILE || die "Couldn't close $file after reading."; 389 390 # fix perl path 391 $lines[0] =~ m/^#!(\S*)/; 392 if($1 ne $perlPath) { 393 $lines[0] =~ s/^#!\S*/#!$perlPath/; 394 open FILE, ">$file" || die "Couldn't open $file for writing."; 395 print FILE @lines; 396 close FILE || die "Couldn't close $file for writing."; 397 } 398 } 399 400 print "done fixing #! and \"use\" lines.\n\n"; 401 402 #################### write webworkConfig.pm file 403 # uses: $mainDir, $cgiURL, $htmlURL 404 405 print "Writing lib/webworkConfig.pm file...\n"; 406 open CONFIG_FILE, ">${mainDir}lib/webworkConfig.pm"; 407 print CONFIG_FILE<<END_OF_CONFIG_FILE; 408 package Global; 409 410 ################################################################################ 411 # WeBWorK 412 # 413 # Copyright (c) 1995-2001 WeBWorK Team, University of Rochester 414 # All rights reserved 415 ################################################################################ 416 417 # \$cgiDebugMode, if enabled, will call the debug wrapper scripts instead of the 418 # cgi scripts themselves, allowing for header output, etc. In addition to 419 # setting \$cgiDebugMode =1, you will also need to enable debugging in the 420 # wrapper scripts that you wish to debug, by setting \$debug = 1. Wrapper 421 # scripts are found in the directory referred to by \$cgiWebworkURL, which is 422 # usually webwork/system/cgi. 423 \$cgiDebugMode = 0; 424 425 \$mainDirectory = "$mainDir"; 426 \$htmlWebworkURL = "$htmlURL"; 427 \$cgiWebworkURL = "$cgiURL"; 428 \$cgiWebworkURL .= "cgi-scripts/" unless \$cgiDebugMode; 429 430 1; 431 END_OF_CONFIG_FILE 432 close CONFIG_FILE; 433 print "Done writing lib/webworkConfig.pm file.\n\n"; 434 435 #################### write webworkInit.pm files 436 # uses: $mainDir 437 438 print "Writing webworkInit.pm files...\n"; 439 foreach my $dir ('cgi/', 'cgi/cgi-scripts/', 'scripts/', 'courseScripts/') { 440 open INIT_FILE, ">$mainDir${dir}webworkInit.pm"; 441 print INIT_FILE<<END_OF_INIT_FILE; 442 ################################################################################ 443 # WeBWorK 444 # 445 # Copyright (c) 1995-2001 WeBWorK Team, University of Rochester 446 # All rights reserved 447 ################################################################################ 448 449 use lib '${mainDir}lib/'; 450 451 1; 452 END_OF_INIT_FILE 453 close INIT_FILE; 454 } 455 print "Done writing webworkInit.pm files.\n\n"; 456 457 #################### chgrp system stuff 458 # uses: $chgrp_files_and_dirs, $groupName 459 460 if($chgrp_files_and_dirs) { 461 print "Setting group on system files and directories...\n"; 462 system "chgrp -R $groupName $mainDir"; 463 system "chgrp -R $groupName $mainDir/../system_html"; 464 system "chgrp -R $groupName $mainDir/../pg"; 465 print "Done setting group.\n\n"; 466 } 467 468 #################### chmod system stuff 469 # uses: $chmod_files_and_dirs 470 471 if($chmod_files_and_dirs) { 472 print "Setting permissions on system files and directories for $system_setup_mode mode...\n"; 473 if ($system_setup_mode eq "demo") { 474 # get some general permissions for files and directories 475 system "find $mainDir $mainDir/../system_html -type d -print | xargs chmod 0755"; 476 system "find $mainDir $mainDir/../system_html -type f -print | xargs chmod 0644"; 477 system "find $mainDir $mainDir/../pg -type f -print | xargs chmod 0644"; 478 # add executable privs to scripts 479 system "find ${mainDir}cgi ${mainDir}scripts -type f -print | xargs chmod 0755"; 480 } else { 481 # get some general permissions for files and directories 482 system "find $mainDir $mainDir/../system_html -type d -print | xargs chmod 0775"; 483 system "find $mainDir $mainDir/../system_html -type f -print | xargs chmod 0664"; 484 system "find $mainDir $mainDir/../pg -type f -print | xargs chmod 0664"; 485 # add executable privs to scripts 486 system "find ${mainDir}cgi ${mainDir}scripts -type f -print | xargs chmod 0775"; 487 } 488 # make the log files group writable 489 system "find $mainDir/logs -type f -print | xargs chmod 0664"; 490 # make the error_log file world writable 491 system "find $mainDir/logs/error_log -print | xargs chmod 0666"; 492 493 print "done setting permissions.\n\n"; 494 } 495 496 #################### update couses stuff 497 # uses: $update_stuff_in_courses 498 499 if($update_stuff_in_courses) { 500 print "Setting permissions for ../courses directory...\n"; 501 if ($system_setup_mode eq "demo") { 502 chmod(0755, "$mainDir/../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"; 503 } else { 504 chmod(0775, "$mainDir/../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"; 505 } 506 print "done permissions.\n\n"; 507 } 508 509 #################### run local postprocessor 510 511 if(defined $local_postprocessor) { 512 print "Executing local postprocessor...\n"; 513 &$local_postprocessor; 514 print "Done with local postprocessor.\n"; 515 } 516 517 #################### finish up 518 519 page($DONE_TEXT); 520 521 ################################################################################ 522 523 sub page 524 { 525 my @string_lines = split /^/, shift; #/ 526 # not really optimal, but we're going to assume a constant screen height. 527 my $SCREEN_HEIGHT = 20; 528 while(@string_lines) { 529 print join "", @string_lines[0..($SCREEN_HEIGHT>scalar @string_lines ? (scalar @string_lines)-1 : $SCREEN_HEIGHT-1)]; 530 if(scalar @string_lines >= $SCREEN_HEIGHT) { 531 print "\n[Press ENTER to continues...]"; 532 <STDIN>; 533 print "\n"; 534 } 535 @string_lines = @string_lines[$SCREEN_HEIGHT..$#string_lines]; 536 } 537 } 538 539 sub questionChar 540 { 541 my ($question, $default, @valid) = @_; 542 my $answer; 543 do { 544 print $question, " "; 545 foreach (@valid) { 546 $_ eq $default and print "["; 547 print $_; 548 $_ eq $default and print "]"; 549 } 550 print " "; 551 $answer = <STDIN>; 552 $answer =~ s/^\s*//; 553 $answer = substr $answer, 0, 1; 554 $answer = lc $answer; 555 $answer or $answer = $default; 556 } while (not grep(/$answer/, @valid)); 557 return $answer; 558 } 559 560 sub questionString 561 { 562 my ($question, $default, $emptyOK) = @_; 563 my $answer; 564 print $question, " [", $default, "] "; 565 $answer = <STDIN>; 566 chomp $answer; 567 $answer =~ s/^\s*//; 568 $answer or $answer = $default; 569 return $answer; 570 } 571 572 __END__ 573 574 =head1 NAME 575 576 system_webwork_setup.pl - set up the WeBWorK system 577 578 =head1 SYNOPSIS 579 580 system_webwork_setup.pl [B<-d> [defaults-file]] 581 582 =head1 DESCRIPTION 583 584 B<system_webwork_setup.pl> gathers the information necessary for configuration of the WeBWorK system. It then edits several WeBWorK system files, and creates F<webworkInit.pm> modules and the F<webworkConfig.pm> module based on the information gathered. It can optionally read defaults from a file specified on the command line or from the file F<$HOME/system_webwork_setup.defaults>. 585 586 =head1 OPTIONS 587 588 =over 4 589 590 =item B<-d> 591 592 enables defaults-file processing. If no defaults-file is specified, the file F<$HOME/system_webwork_setup.defaults> will be used. 593 594 =head1 DEFAULTS 595 596 The F<system_webwork_setup.defaults> file is intended to be used in a situation where B<system_webwork_setup.pl> must be executed frequently, such as in the case of use with CVS, in which the it must be executed after a checkout and some updates. The defaults file is a perl script that will be require'd by B<system_webwork_setup.pl>. It can set any of the following variables in the usual way: 597 598 =over 4 599 600 =item $no_prompts 601 602 Refrain from prompting at the beginning of the script and before making changes. Also supresses the introductory text. 603 604 =item $system_setup_mode 605 606 Can be set to "working" or "demo". This affects how system file permissions and group ownership are set. In "working" mode, system files are group owned by a webwork admin group (see I<$groupName>) and group writeable while in "demo" mode files are group owned by the current user's default group and are not group writeable. 607 608 =item $mainDir 609 610 Specify WeBWorK's main directory, which should contain the directories cgi/ scripts/ courseScripts/ and lib/. 611 612 =item $perlPath 613 614 Specify the path to the perl interpreter which should be used. This is used to set the shebang line in cgi-scripts and scripts. 615 616 =item $cgiURL 617 618 Specify the externally visible URL to the CGI directory (typically cgi/cgi-scripts/). This will be used when scripts call other scripts. 619 620 =item $htmlURL 621 622 Specify the externally visible URL to the HTML directory (typically system_html/). This will be used when scripts refer to static graphics and text. 623 624 =item $groupName 625 626 When in "working" mode, I<$groupName> is the name of the WeBWorK admin group, members of which should have write access to the system files. (The web server should not be in this group!) 627 628 =item $update_stuff_in_courses 629 630 If true, B<system_webwork_setup.pl> will set permissions in the courses directory and prepare the B<course_webwork_setup.pl> script for execution. 631 632 =item $chgrp_files_and_dirs, $chmod_files_and_dirs 633 634 If true, the group and/or permissions on system files will be set according to I<$system_setup_mode>. 635 636 =item $local_preprocessor, $local_postprocessor 637 638 If set, these variables will be called as subroutine references. I<$local_preprocessor> is called before any changes take place, while I<$local_postprocessor> is called after all changes have taken place. 639 640 =back 641 642 =head1 FILES 643 644 $HOME/system_webwork_setup.defaults 645 646 =head1 AUTHOR 647 648 Samuel Hathaway <sh002i@math.rochester.edu>
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |