[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 8 Revision 12
26 26
27# define code strings 27# define code strings
28my $CGI_DEBUG_TAG = 'WeBWorKCGIDebugURL'; 28my $CGI_DEBUG_TAG = 'WeBWorKCGIDebugURL';
29my $CGI_NODEBUG_TAG = 'WeBWorKCGINoDebugURL'; 29my $CGI_NODEBUG_TAG = 'WeBWorKCGINoDebugURL';
30my $LIB_INIT_LINE_TAG = 'WeBWorKInitLine'; 30my $LIB_INIT_LINE_TAG = 'WeBWorKInitLine';
31my $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 $mainDir = undef; 35our $mainDir = undef;
358################################################################################ 357################################################################################
359 358
360 359
361 360
362 361
362
363chdir $mainDir;
363 364
364#################### run local preprocessor 365#################### run local preprocessor
365 366
366if(defined $local_preprocessor) { 367if(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
416if($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
425print "Fixing #! and \"use\" lines...\n"; 417print "Fixing #! lines...\n";
426 418
427my $USE_LINE = "use lib '.'; use webworkInit; \# $LIB_INIT_LINE_TAG\n"; 419# fix up the course setup script and the *.pl files
428 420fixFile('../courses/demoCourse/course_webwork_setup.pl') if $update_stuff_in_courses;
429# fix up the *.pl files
430foreach my $dir ('cgi/cgi-scripts', 'scripts', 'courseScripts') { 421foreach 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.
437my @files = ('lib/PGtranslator.pm', 'lib/Auth.pm', 'lib/capa2PG.pm');
438push @files,'../courses/demoCourse/course_webwork_setup.pl' if $update_stuff_in_courses;
439foreach 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
444sub fixFile 427sub 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
476print "done fixing #! and \"use\" lines.\n\n"; 446print "done fixing #! and \"use\" lines.\n\n";
477 447
448#################### write webworkConfig.pm file
449# uses: $mainDir, $cgiURL, $htmlURL
450
451print "Writing lib/webworkConfig.pm file...\n";
452open CONFIG_FILE, ">${mainDir}lib/webworkConfig.pm";
453print CONFIG_FILE
454 "package Global;\n\n",
455 "\$cgiWebworkURL = \"$cgiURL\";\n",
456 "\$htmlWebworkURL = \"$htmlURL\";\n",
457 "\$mainDirectory = \"$mainDir\";\n\n",
458 "1;";
459close CONFIG_FILE;
460print "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
465print "Writing webworkInit.pm files...\n";
481foreach my $dir ('cgi/cgi-scripts/', 'scripts/') { 466foreach 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}
473print "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
490if($chgrp_files_and_dirs) { 478if($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}
548print "done fixing documentation files.\n\n"; 536print "done fixing documentation files.\n\n";
549 537
538#################### update couses stuff
539# uses: $update_stuff_in_courses
540
541if($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
552if(defined $local_postprocessor) { 548if(defined $local_postprocessor) {
553 print "Executing local preprocessor...\n"; 549 print "Executing local preprocessor...\n";
554 &$local_postprocessor; 550 &$local_postprocessor;

Legend:
Removed from v.8  
changed lines
  Added in v.12

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9