[system] / trunk / webwork / system / system_webwork_setup.pl Repository:
ViewVC logotype

Annotation of /trunk/webwork/system/system_webwork_setup.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6 - (view) (download) (as text)

1 : sam 2 #!/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 $MAIN_DIR_TAG = 'mainWeBWorKDirectory';
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 : gage 6 my $DEFAULTS_FILE;
48 :     if($ARGV[0]) { $DEFAULTS_FILE = $ARGV[0]; }
49 :     else { $DEFAULTS_FILE = ((getpwuid $<)[7]) . '/system_webwork_setup.defaults'; }
50 : sam 2 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 : gage 6 1) The path to perl on your system. Usually this is something like
70 : sam 2 /usr/bin/perl or /usr/local/bin/perl
71 :    
72 : gage 6 2) The group (e.g. wwadmin) containing the user names of anyone who has the
73 : sam 2 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 : gage 6 3) The cgi WeBWorK URL. Usually this is something like
79 : sam 2 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 : gage 6 4) The html WeBWorK URL. Usually this is something like
85 : sam 2 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 : gage 6 my $MAIN_DIR_TEXT = q{
109 : sam 2
110 : gage 6 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 : sam 2
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 : gage 6 unless(defined $mainDir) {
232 :     page($MAIN_DIR_TEXT);
233 :     $mainDir = questionString("Where is the main WeBWorK directory?", cwd());
234 : sam 2 $mainDir .= '/' unless $mainDir =~ m|/$|; # ensure trailing slash
235 :     }
236 : gage 6 print "We'll use $mainDir as WeBWorK's home.\n";
237 : sam 2
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 :     #################### run local preprocessor
364 :    
365 :     if(defined $local_preprocessor) {
366 :     print "Executing local preprocessor...\n";
367 :     &$local_preprocessor;
368 :     print "Done with local preprocessor.\n";
369 :     }
370 :    
371 :     #################### update Global.pm
372 : gage 6 #needs: $mainDir, $cgiURL, $htmlURL
373 : sam 2
374 :     chdir "lib";
375 :    
376 :     -e 'Global.pm' or die "Global.pm doesn't exist! There's no point in continuing.\n";
377 :     if(-e 'Global.pm.bak1') {
378 :     print "Copying Global.pm.bak1 -> Global.pm.bak2\n";
379 :     copy('Global.pm.bak1', 'Global.pm.bak2');
380 :     }
381 :     print "Copying Global.pm -> Global.pm.bak1\n";
382 :     copy('Global.pm', 'Global.pm.bak1');
383 :    
384 :     open OLD_GLOBAL, "Global.pm.bak1";
385 :     open NEW_GLOBAL, ">Global.pm";
386 :    
387 :     while (<OLD_GLOBAL>) {
388 :     if (/^\$mainDirectory/) {
389 : gage 6 print NEW_GLOBAL "\$mainDirectory = '$mainDir';\n";
390 :     print "\$mainDirectory = '$mainDir';\n";
391 : sam 2 } elsif (/\#$CGI_DEBUG_TAG$/) {
392 : gage 6 print NEW_GLOBAL "\#\$cgiWebworkURL = '$cgiURL'; \#$CGI_DEBUG_TAG\n";
393 :     print "\#\$cgiWebworkURL = '$cgiURL'; \#$CGI_DEBUG_TAG\n";
394 : sam 2 } elsif (/\#$CGI_NODEBUG_TAG$/) {
395 : gage 6 print NEW_GLOBAL "\$cgiWebworkURL = '${cgiURL}cgi-scripts/'; \#$CGI_NODEBUG_TAG\n";
396 :     print "\$cgiWebworkURL = '${cgiURL}cgi-scripts/'; \#$CGI_NODEBUG_TAG\n";
397 : sam 2 } elsif (/^\$htmlWebworkURL/) {
398 : gage 6 print NEW_GLOBAL "\$htmlWebworkURL = '$htmlURL';\n";
399 :     print "\$htmlWebworkURL = '$htmlURL';\n";
400 : sam 2 } else {
401 :     print NEW_GLOBAL $_;
402 :     }
403 :     }
404 :    
405 :     close NEW_GLOGAL;
406 :     close OLD_GLOBAL;
407 :    
408 :     chmod(0644, "Global.pm");
409 :     chdir "..";
410 :     print "Done updating Global.pm\n\n";
411 :    
412 :     #################### update couses stuff
413 :     # uses: $update_stuff_in_courses
414 :    
415 :     if($update_stuff_in_courses) {
416 :     print "Setting permissions for ../courses directory.\n\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";
418 :     }
419 :    
420 :     #################### update #! and use lines
421 : gage 6 # uses: $mainDir, $perlPath
422 : sam 2 # i must fix this some day
423 :    
424 :     print "Fixing #! and \"use\" lines...\n";
425 :    
426 : gage 6 my $USE_LINE = "use lib '${mainDir}lib/'; \# $MAIN_DIR_TAG\n";
427 : sam 2
428 :     # fix up the *.pl files
429 :     foreach my $dir ('cgi/cgi-scripts', 'scripts', 'courseScripts') {
430 :     foreach my $file (<${dir}/*.pl>) {
431 :     fixFile($file, $USE_LINE);
432 :     }
433 :     }
434 :    
435 :     # fix up the course_webwork_setup.pl file and some modules.
436 :     my @files = ('lib/PGtranslator.pm', 'lib/Auth.pm', 'lib/capa2PG.pm');
437 :     push @files,'../courses/demoCourse/course_webwork_setup.pl' if $update_stuff_in_courses;
438 :     foreach my $file (@files) {
439 :     if($file eq 'lib/PGtranslator.pm') { fixFile($file, $USE_LINE); }
440 :     else { fixFile($file); }
441 :     }
442 :    
443 :     sub fixFile
444 :     {
445 :     my ($file, $use_line) = @_;
446 :    
447 :     # read the file
448 : gage 6 open FILE, $file || die "CAN'T READ $file!\n Fix the problem and run the setup script again";
449 : sam 2 my @lines = <FILE>;
450 : gage 6 close FILE || die "CAN'T CLOSE $file!\n Fix the problem and run the setup script again";
451 : sam 2
452 :     # fix perl path
453 :     my $num = 0;
454 :     $num = $lines[0] =~ s/^#!.*/#!$perlPath/g; # fix #!... line
455 :     warn "couldn't fix #! line in $file\n" unless $num;
456 :    
457 :     # fix use lines
458 :     if($use_line) {
459 :     $num = 0;
460 :     foreach (@lines) {
461 : gage 6 if (/^.*\#\s*\Q$MAIN_DIR_TAG\E.*$/) {
462 : sam 2 $num++;
463 :     $_ = $use_line;
464 :     }
465 :     }
466 :     warn "fixed $num 'use lib' lines in $file\n" if $num > 1;
467 :     }
468 :    
469 :     # write the file
470 :     open FILE, ">$file" || die "CAN'T WRITE $file!\n Fix the problem and run the setup script again";
471 :     print FILE @lines;
472 : gage 6 close FILE || die "CAN'T CLOSE (writing) $file!\n Fix the problem and run the setup script again";
473 : sam 2 }
474 :    
475 :     print "done fixing #! and \"use\" lines.\n\n";
476 :    
477 :     #################### chgrp system stuff
478 :     # uses: $chgrp_files_and_dirs, $groupName
479 :    
480 :     if($chgrp_files_and_dirs) {
481 :     print "Setting group on system files and directories...\n";
482 :     # R=recursive, P=don't follow symlinks
483 :     system "chgrp -PR $groupName .";
484 :     print "Done setting group.\n\n";
485 :     }
486 :    
487 :     #################### chmod system stuff
488 :     # uses: $chmod_files_and_dirs
489 :    
490 :     if($chmod_files_and_dirs) {
491 :     print "Setting permissions on system files and directories for $system_setup_mode mode...\n";
492 :     if ($system_setup_mode eq "demo") {
493 :     # get some general permissions for files and directories
494 :     system "find . -type d -print0 | xargs -0 chmod 0711";
495 :     system "find . -type f -print0 | xargs -0 chmod 0644";
496 :     # add executable privs to scripts
497 : gage 6 system "find cgi scripts -type f -print0 | xargs -0 chmod 0755";
498 : sam 2 # give everyone write access to logs
499 :     # (we should probably just be chowning the log directory to the webserver)
500 : gage 6 system "chmod 0666 logs/*";
501 : sam 2 # make this script executable and safe
502 : gage 6 system "chmod 0700 system_webwork_setup.pl"
503 : sam 2 } else {
504 :     # get some general permissions for files and directories
505 :     system "find . -type d -print0 | xargs -0 chmod 0771";
506 :     system "find . -type f -print0 | xargs -0 chmod 0664";
507 :     # add executable privs to scripts
508 : gage 6 system "find cgi scripts -type f -print0 | xargs -0 chmod 0775";
509 : sam 2 # give everyone write access to logs
510 :     # (we should probably just be chowning the log directory to the webserver)
511 : gage 6 system "chmod 0666 logs/*";
512 : sam 2 # make this script executable and safe
513 : gage 6 system "chmod 0770 system_webwork_setup.pl"
514 : sam 2 }
515 :     print "done setting permissions.\n\n";
516 :     }
517 :    
518 :     #################### fix up the documemtation html files
519 :     # uses: $htmlURL, $cgiURL
520 :    
521 :     print "Fixing image, cgi-bin, and ref lines in documentation html files...\n";
522 :     foreach my $dir ('system_html/helpFiles') {
523 :     foreach my $file (<${dir}/*.html>) {
524 :     open FILE, $file || die "CAN'T READ $file!\n Fix the problem and run the setup script again";
525 :     my @lines = <FILE>;
526 :     close FILE || die "CAN'T CLOSE $file!\n Fix the problem and run the setup script again";
527 :    
528 :     foreach my $line (@lines) {
529 :     $line =~ s|<IMG SRC=".*?images/|<IMG SRC="${htmlURL}images/|g; # fix "images" line
530 :     $line =~ s|<A HREF=".*?feedback.pl">|<A HREF="${cgiURL}feedback.pl">|g; # fix "cgi-bin" line
531 :     $line =~ s|<A HREF=".*?docs/">|<A HREF="${htmlURL}docs/">|g; # fix "Ref" line
532 :     }
533 :     open FILE, ">$file" || die "CAN'T WRITE $file!\n Fix the problem and run the setup script again";
534 :     print FILE @lines;
535 :     close FILE || die "CAN'T CLOSE (writing) $file!\n Fix the problem and run the setup script again";
536 :     }
537 :     }
538 :     print "done fixing documentation files.\n\n";
539 :    
540 :     #################### run local postprocessor
541 :    
542 :     if(defined $local_postprocessor) {
543 :     print "Executing local preprocessor...\n";
544 :     &$local_postprocessor;
545 :     print "Done with local preprocessor.\n";
546 :     }
547 :    
548 :     #################### finish up
549 :    
550 :     page($DONE_TEXT);
551 :    
552 :     ################################################################################
553 :    
554 :     sub page
555 :     {
556 :     my @string_lines = split /^/, shift; #/
557 :     # not really optimal, but we're going to assume a constant screen height.
558 :     my $SCREEN_HEIGHT = 20;
559 :     while(@string_lines) {
560 :     print join "", @string_lines[0..$SCREEN_HEIGHT-1];
561 :     if(scalar @string_lines >= $SCREEN_HEIGHT) {
562 :     print "\n[Press ENTER to continues...]";
563 :     <STDIN>;
564 :     print "\n";
565 :     }
566 :     @string_lines = @string_lines[$SCREEN_HEIGHT..$#string_lines];
567 :     }
568 :     }
569 :    
570 :     sub questionChar
571 :     {
572 :     my ($question, $default, @valid) = @_;
573 :     my $answer;
574 :     do {
575 :     print $question, " ";
576 :     foreach (@valid) {
577 :     $_ eq $default and print "[";
578 :     print $_;
579 :     $_ eq $default and print "]";
580 :     }
581 :     print " ";
582 :     $answer = <STDIN>;
583 :     $answer =~ s/^\s*//;
584 :     $answer = substr $answer, 0, 1;
585 :     $answer = lc $answer;
586 :     $answer or $answer = $default;
587 :     } while (not grep(/$answer/, @valid));
588 :     return $answer;
589 :     }
590 :    
591 :     sub questionString
592 :     {
593 :     my ($question, $default, $emptyOK) = @_;
594 :     my $answer;
595 :     print $question, " [", $default, "] ";
596 :     $answer = <STDIN>;
597 :     chomp $answer;
598 :     $answer =~ s/^\s*//;
599 :     $answer or $answer = $default;
600 :     return $answer;
601 :     }

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9