SOLVED: Asking a question during install
John G. Heim
jheim at math.wisc.edu
Thu Jul 14 19:49:51 CEST 2011
I've asked a lot of questions lately so I thought I'd share my perl
subroutine for asking a question during a FAI install. It validates the
answer versus a list of valid answers and it times out after 30 seconds
taking the default as the answer. It takes 3 parms:
1. The question.
2. A pointer to an associative array listing valid choices.
3. Default answer. So you might call it like this:
my $answer = &askQuestion ('Language?', {G => 'German', E => 'English'},
'E');
sub askQuestion
{
my $question = shift;
my $choices = shift;
my $default = shift;
my $answer = '';
if ( open CONSOLE, "</dev/console")
{
while (not defined ($choices->{$answer}))
{
eval
{
local $SIG{ALRM} = sub { die "alarm clock restart" };
alarm 30;
printf STDERR "$question\n" . join (", ", map ($_ . "=" . $choices->{$_},
keys %$choices)) . "[$default] ";
$answer = <CONSOLE>;
chomp($answer);
alarm 0;
};
$answer = $default unless ($answer);
} # elihw
close (CONSOLE);
} # fi
return $answer;
} # bus AskQuestion
More information about the linux-fai
mailing list