Subversion Repositories camp_sysinfo_client_3

Rev

Rev 227 | Rev 229 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 227 Rev 228
Line 28... Line 28...
28
   use File::Spec;
28
   use File::Spec;
29
   use lib File::Spec->catdir($FindBin::Bin);
29
   use lib File::Spec->catdir($FindBin::Bin);
30
}
30
}
31
 
31
 
32
use sysinfoconf; # a library of shared routines with install.pl
32
use sysinfoconf; # a library of shared routines with install.pl
-
 
33
our %displayOrder;
33
 
34
 
34
my $config;
35
my $config;
35
 
36
 
36
sub findSendEmail {
37
sub findSendEmail {
37
   my $currentLocation = shift;
38
   my $currentLocation = shift;
Line 129... Line 130...
129
}
130
}
130
 
131
 
131
sub showEntry {
132
sub showEntry {
132
   my ( $lineno, $prompt, $value ) = @_;
133
   my ( $lineno, $prompt, $value ) = @_;
133
   $value = '' unless $value;
134
   $value = '' unless $value;
-
 
135
   my $valueType = ref( $value );
-
 
136
   if ( $valueType eq 'ARRAY' ) {
-
 
137
      $value = join( ', ', @$value );
-
 
138
   } elsif ( $valueType eq  'HASH' ) {
-
 
139
      $value = ( scalar keys %$value ) . " Entries";
-
 
140
   }
134
   return "$lineno. $prompt: $value\n";
141
   return "$lineno. $prompt: $value\n";
135
}
142
}
136
 
143
 
137
sub displayEditScreen {
144
sub displayEditScreen {
138
   my $config = shift;
145
   my $config = shift;
139
   #print "\033[2J";    #clear the screen
146
#   print "\033[2J";    #clear the screen
140
   #print "\033[0;0H"; #jump to 0,0   
147
#   print "\033[0;0H"; #jump to 0,0  
141
   print &showEntry( 1, 'Client Name', $config->{'clientName'} );
-
 
142
   print &showEntry( 2, 'Host Name', $config->{'hostname'} );
148
   foreach my $entry ( sort keys %displayOrder ) {
143
   print &showEntry( 3, 'Serial Number', $config->{'serialNumber'} );
-
 
144
   print &showEntry( 4, 'UUID', $config->{'UUID'} );
149
      print &showEntry( 
145
   print &showEntry( 5, 'Module Dirs', join( ',', $config->{'moduleDirs'} ?  @{ $config->{'moduleDirs'} } : () ) );
-
 
146
   print &showEntry( 6, 'Script Dirs', join( ',', $config->{'scriptDirs'} ?  @{ $config->{'scriptDirs'} } : () ) );
-
 
147
   print &showEntry( 7, 'Transports', '' );
150
         $entry, 
148
   foreach my $key ( sort { $a <=> $b } keys %{ $config->{'transports'} } ) {
151
         $displayOrder{$entry}{'display'}, 
149
      print "\t$key\t" . $config->{'transports'}->{$key}->{'name'} . "\n";
152
         $config->{$displayOrder{$entry}{'fieldname'}} 
-
 
153
      );
150
   }
154
   }
151
   print "Select Option to Edit, or 'Done' if finished [Done]: ";
155
   print "\nSelect Option to Edit, or 'Done' if finished [Done]: ";
152
   my $selection = <>;
156
   my $selection = <>;
153
   chomp $selection;
157
   chomp $selection;
154
   $selection = 'd' unless $selection;
158
   $selection = 'd' unless $selection;
155
   return lc substr( $selection, 0, 1 );
159
   return lc substr( $selection, 0, 1 );
156
}
160
}
Line 163... Line 167...
163
   chomp $t;
167
   chomp $t;
164
   return $t ? $t : $value;
168
   return $t ? $t : $value;
165
}
169
}
166
 
170
 
167
sub editSelection {
171
sub editSelection {
168
   my $selection = shift;
172
   my $entry = shift;
169
   if ( $selection == 1 ) {
-
 
170
      $config->{'clientName'} = &getValue( 'Client Name', $config->{'clientName'} );
173
   my $type = ref( $config->{$displayOrder{$entry}{'fieldname'}} );
171
   } elsif ( $selection == 2 ) {
-
 
172
      $config->{'hostname'} = &getValue( 'Host Name', $config->{'hostname'} );
-
 
173
   } elsif ( $selection == 3 ) {
174
   print "Type is $type\n";
174
      $config->{'serialNumber'} = &getValue( 'Serial Number', $config->{'serialNumber'} );
-
 
175
   } elsif ( $selection == 4 ) {
175
   if ( $type eq 'ARRAY' ) {
176
      $config->{'UUID'} = &getValue( 'UUID', $config->{'UUID'} );
176
      print "Don't know how to edit arrays yet\n";
177
   } elsif ( $selection == 5 ) {
177
   } elsif ( $type eq 'HASH' ) {
178
      my $t = join( ',', $config->{'moduleDirs'} ?  @{ $config->{'moduleDirs'} } : () );
-
 
179
      $t = &getValue( "Comma separated list of Module Directories\n\t", $t );
178
      print "Don't know how to edit transports yet\n";
180
      my @t = split( ',', $t );
179
   } else { # it is a scalar
181
      $config->{'moduleDirs'} =  \@t;
180
      $config->{$displayOrder{$entry}{'fieldname'}} = &getValue( 
182
   } elsif ( $selection == 6 ) {
-
 
183
      my $t = join( ',', $config->{'scriptDirs'} ?  @{ $config->{'scriptDirs'} } : () );
-
 
184
      $t = &getValue( "Comma separated list of Script Directories\n\t", $t );
-
 
185
      my @t = split( ',', $t );
181
         $displayOrder{$entry}{'display'}, 
186
      $config->{'scriptDirs'} =  \@t;
182
         $config->{$displayOrder{$entry}{'fieldname'}}
187
   } elsif ( $selection == 7 ) {
-
 
188
      print "Can not automatically do this at this time\nManually edit the file (press enter to continue)";
-
 
189
      my $t = <>;
183
         );
190
   }
184
   }
191
}
185
}
192
 
186
 
193
 
187
 
194
# will validate the config, adding modules, scripts and transports if necessary
188
# will validate the config, adding modules, scripts and transports if necessary
Line 264... Line 258...
264
unless ( $confFileName ) {
258
unless ( $confFileName ) {
265
   ( $confDir, $sysinfo3 ) = &findConf( $sysinfo3 );
259
   ( $confDir, $sysinfo3 ) = &findConf( $sysinfo3 );
266
   $outputFile = $confDir . '/' . $sysinfo3 unless $outputFile;
260
   $outputFile = $confDir . '/' . $sysinfo3 unless $outputFile;
267
   $confFileName =  $confDir . "/" . $sysinfo3 if ( $confDir );
261
   $confFileName =  $confDir . "/" . $sysinfo3 if ( $confDir );
268
}
262
}
269
print "Loading defaults from existing configs\n";
263
print "Loading defaults from existing config\n";
270
$config = &makeConfig( $outputFile, $confFileName  );
264
$config = &makeConfig( $outputFile, $confFileName  );
271
 
265
 
272
die Dumper($config) . "\n";
-
 
-
 
266
 
273
 
267
 
274
my $selection;
268
my $selection;
275
while ( ! $quiet && ( $selection = &displayEditScreen( $config ) ) ne 'd' ) {
269
while ( ! $quiet && ( $selection = &displayEditScreen( $config ) ) ne 'd' ) {
276
   &editSelection( $selection );
270
   &editSelection( $selection );
277
}
271
}
278
 
272
 
-
 
273
die Dumper($config) . "\n";
-
 
274
 
279
my $testResults = &testConfig($config);
275
my $testResults = &testConfig($config);
280
print "Error found in configuration file, manually run\n$0\n" if ( $testResults ne 'Ok' );
276
print "Error found in configuration file, manually run\n$0\n" if ( $testResults ne 'Ok' );
281
print $testResults if $test || $testResults ne 'Ok';
277
print $testResults if $test || $testResults ne 'Ok';
282
 
278
 
283
if ( $quiet || &yesno( "Ready to write configuration to $outputFile, ok?" ) ) {
279
if ( $quiet || &yesno( "Ready to write configuration to $outputFile, ok?" ) ) {