| … | |
… | |
| 26 | |
26 | |
| 27 | # define code strings |
27 | # define code strings |
| 28 | my $CGI_DEBUG_TAG = 'WeBWorKCGIDebugURL'; |
28 | my $CGI_DEBUG_TAG = 'WeBWorKCGIDebugURL'; |
| 29 | my $CGI_NODEBUG_TAG = 'WeBWorKCGINoDebugURL'; |
29 | my $CGI_NODEBUG_TAG = 'WeBWorKCGINoDebugURL'; |
| 30 | my $LIB_INIT_LINE_TAG = 'WeBWorKInitLine'; |
30 | my $LIB_INIT_LINE_TAG = 'WeBWorKInitLine'; |
| 31 | 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 $mainDir = undef; |
35 | our $mainDir = undef; |
| … | |
… | |
| 358 | ################################################################################ |
357 | ################################################################################ |
| 359 | |
358 | |
| 360 | |
359 | |
| 361 | |
360 | |
| 362 | |
361 | |
|
|
362 | |
|
|
363 | chdir $mainDir; |
| 363 | |
364 | |
| 364 | #################### run local preprocessor |
365 | #################### run local preprocessor |
| 365 | |
366 | |
| 366 | if(defined $local_preprocessor) { |
367 | if(defined $local_preprocessor) { |
| 367 | print "Executing local preprocessor...\n"; |
368 | print "Executing local preprocessor...\n"; |
| … | |
… | |
| 408 | # |
409 | # |
| 409 | #chmod(0644, "Global.pm"); |
410 | #chmod(0644, "Global.pm"); |
| 410 | #chdir ".."; |
411 | #chdir ".."; |
| 411 | #print "Done updating Global.pm\n\n"; |
412 | #print "Done updating Global.pm\n\n"; |
| 412 | |
413 | |
| 413 | #################### update couses stuff |
|
|
| 414 | # uses: $update_stuff_in_courses |
|
|
| 415 | |
|
|
| 416 | if($update_stuff_in_courses) { |
|
|
| 417 | print "Setting permissions for ../courses directory.\n\n"; |
|
|
| 418 | 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"; |
|
|
| 419 | } |
|
|
| 420 | |
|
|
| 421 | #################### update #! and use lines |
414 | #################### update #! and use lines |
| 422 | # uses: $mainDir, $perlPath |
415 | # uses: $mainDir, $perlPath |
| 423 | # i must fix this some day |
|
|
| 424 | |
416 | |
| 425 | print "Fixing #! and \"use\" lines...\n"; |
417 | print "Fixing #! lines...\n"; |
| 426 | |
418 | |
| 427 | my $USE_LINE = "use lib '.'; use webworkInit; \# $LIB_INIT_LINE_TAG\n"; |
419 | # fix up the course setup script and the *.pl files |
| 428 | |
420 | fixFile('../courses/demoCourse/course_webwork_setup.pl') if $update_stuff_in_courses; |
| 429 | # fix up the *.pl files |
|
|
| 430 | foreach my $dir ('cgi/cgi-scripts', 'scripts', 'courseScripts') { |
421 | foreach my $dir ('cgi/cgi-scripts', 'scripts', 'courseScripts') { |
| 431 | foreach my $file (<${dir}/*.pl>) { |
422 | foreach my $file (<${dir}/*.pl>) { |
| 432 | fixFile($file, $USE_LINE); |
|
|
| 433 | } |
|
|
| 434 | } |
|
|
| 435 | |
|
|
| 436 | # fix up the course_webwork_setup.pl file and some modules. |
|
|
| 437 | my @files = ('lib/PGtranslator.pm', 'lib/Auth.pm', 'lib/capa2PG.pm'); |
|
|
| 438 | push @files,'../courses/demoCourse/course_webwork_setup.pl' if $update_stuff_in_courses; |
|
|
| 439 | foreach my $file (@files) { |
|
|
| 440 | if($file eq 'lib/PGtranslator.pm') { fixFile($file, $USE_LINE); } |
|
|
| 441 | else { fixFile($file); } |
423 | fixFile($file); |
|
|
424 | } |
| 442 | } |
425 | } |
| 443 | |
426 | |
| 444 | sub fixFile |
427 | sub fixFile |
| 445 | { |
428 | { |
| 446 | my ($file, $use_line) = @_; |
429 | my ($file) = @_; |
| 447 | |
430 | |
| 448 | # read the file |
431 | # read the file |
| 449 | open FILE, $file || die "CAN'T READ $file!\n Fix the problem and run the setup script again"; |
432 | open FILE, $file || die "Couldn't open $file for reading."; |
| 450 | my @lines = <FILE>; |
433 | my @lines = <FILE>; |
| 451 | close FILE || die "CAN'T CLOSE $file!\n Fix the problem and run the setup script again"; |
434 | close FILE || die "Couldn't close $file after reading."; |
| 452 | |
435 | |
| 453 | # fix perl path |
436 | # fix perl path |
| 454 | my $num = 0; |
437 | $lines[0] =~ m/^#!(\S*)/; |
| 455 | $num = $lines[0] =~ s/^#!.*/#!$perlPath/g; # fix #!... line |
438 | if($1 ne $perlPath) { |
| 456 | warn "couldn't fix #! line in $file\n" unless $num; |
439 | $lines[0] =~ s/^#!\S*/#!$perlPath/; |
| 457 | |
440 | open FILE, ">$file" || die "Couldn't open $file for writing."; |
| 458 | # # fix use lines |
|
|
| 459 | # if($use_line) { |
|
|
| 460 | # $num = 0; |
|
|
| 461 | # foreach (@lines) { |
|
|
| 462 | # if (/^.*\#\s*\Q$MAIN_DIR_TAG\E.*$/) { |
|
|
| 463 | # $num++; |
|
|
| 464 | # $_ = $use_line; |
|
|
| 465 | # } |
|
|
| 466 | # } |
|
|
| 467 | # warn "fixed $num 'use lib' lines in $file\n" if $num > 1; |
|
|
| 468 | # } |
|
|
| 469 | |
|
|
| 470 | # write the file |
|
|
| 471 | open FILE, ">$file" || die "CAN'T WRITE $file!\n Fix the problem and run the setup script again"; |
|
|
| 472 | print FILE @lines; |
441 | print FILE @lines; |
| 473 | close FILE || die "CAN'T CLOSE (writing) $file!\n Fix the problem and run the setup script again"; |
442 | close FILE || die "Couldn't close $file for writing."; |
|
|
443 | } |
| 474 | } |
444 | } |
| 475 | |
445 | |
| 476 | print "done fixing #! and \"use\" lines.\n\n"; |
446 | print "done fixing #! and \"use\" lines.\n\n"; |
| 477 | |
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\";\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 | |
| 478 | #################### create webworkInit.pm files |
462 | #################### write webworkInit.pm files |
| 479 | # uses: $mainDir |
463 | # uses: $mainDir |
| 480 | |
464 | |
|
|
465 | print "Writing webworkInit.pm files...\n"; |
| 481 | foreach my $dir ('cgi/cgi-scripts/', 'scripts/') { |
466 | foreach my $dir ('cgi/', 'cgi/cgi-scripts/', 'scripts/', 'courseScripts/') { |
| 482 | open INIT_FILE, ">$mainDir${dir}webworkInit.pm"; |
467 | open INIT_FILE, ">$mainDir${dir}webworkInit.pm"; |
|
|
468 | print INIT_FILE |
| 483 | print INIT_FILE "use lib '${mainDir}lib/';\n1;\n"; |
469 | "use lib '${mainDir}lib/';\n\n", |
|
|
470 | "1;"; |
| 484 | close INIT_FILE; |
471 | close INIT_FILE; |
| 485 | } |
472 | } |
|
|
473 | print "Done writing webworkInit.pm files.\n\n"; |
| 486 | |
474 | |
| 487 | #################### chgrp system stuff |
475 | #################### chgrp system stuff |
| 488 | # uses: $chgrp_files_and_dirs, $groupName |
476 | # uses: $chgrp_files_and_dirs, $groupName |
| 489 | |
477 | |
| 490 | if($chgrp_files_and_dirs) { |
478 | if($chgrp_files_and_dirs) { |
| … | |
… | |
| 545 | close FILE || die "CAN'T CLOSE (writing) $file!\n Fix the problem and run the setup script again"; |
533 | close FILE || die "CAN'T CLOSE (writing) $file!\n Fix the problem and run the setup script again"; |
| 546 | } |
534 | } |
| 547 | } |
535 | } |
| 548 | print "done fixing documentation files.\n\n"; |
536 | print "done fixing documentation files.\n\n"; |
| 549 | |
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 | |
| 550 | #################### run local postprocessor |
546 | #################### run local postprocessor |
| 551 | |
547 | |
| 552 | if(defined $local_postprocessor) { |
548 | if(defined $local_postprocessor) { |
| 553 | print "Executing local preprocessor...\n"; |
549 | print "Executing local preprocessor...\n"; |
| 554 | &$local_postprocessor; |
550 | &$local_postprocessor; |