Subversion Repositories camp_sysinfo_client_3

Rev

Rev 112 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 112 Rev 129
Line 6... Line 6...
6
# v1.1.0 20161022 RWR
6
# v1.1.0 20161022 RWR
7
# use library sysinfoconf.pm for loading, editing and displaying config
7
# use library sysinfoconf.pm for loading, editing and displaying config
8
#
8
#
9
# v1.2.0 20190108 RWR
9
# v1.2.0 20190108 RWR
10
# added UUID
10
# added UUID
-
 
11
#
-
 
12
# v1.3.0 20191107 RWR
-
 
13
# changed the screen to allow the user to see most of the values and decide what to edit
-
 
14
# then write the results.
-
 
15
# also, parameters are passed that allow the import of a file in old conf format
-
 
16
 
-
 
17
use Getopt::Long;
-
 
18
 
11
 
19
 
12
our $VERSION = '1.2.0';
20
our $VERSION = '1.3.0';
13
 
21
 
14
# find our location and use it for searching for libraries
22
# find our location and use it for searching for libraries
15
BEGIN {
23
BEGIN {
16
   use FindBin;
24
   use FindBin;
17
   use File::Spec;
25
   use File::Spec;
Line 129... Line 137...
129
      &showTransports( $priority, $$transports{ $priority } );
137
      &showTransports( $priority, $$transports{ $priority } );
130
      print '='x40 . "\n";
138
      print '='x40 . "\n";
131
   }
139
   }
132
}
140
}
133
 
141
 
-
 
142
sub showEntry {
-
 
143
   my ( $lineno, $prompt, $value ) = @_;
-
 
144
   $value = '' unless $value;
-
 
145
   return "$lineno. $prompt: $value\n";
-
 
146
}
134
 
147
 
-
 
148
sub displayEditScreen {
-
 
149
   my $config = shift;
-
 
150
   #print "\033[2J";    #clear the screen
-
 
151
   #print "\033[0;0H"; #jump to 0,0   
-
 
152
   print &showEntry( 1, 'Client Name', $config->{'clientName'} );
-
 
153
   print &showEntry( 2, 'Host Name', $config->{'hostname'} );
-
 
154
   print &showEntry( 3, 'Serial Number', $config->{'serialNumber'} );
-
 
155
   print &showEntry( 4, 'UUID', $config->{'UUID'} );
-
 
156
   print &showEntry( 5, 'Module Dirs', join( ',', $config->{'moduleDirs'} ?  @{ $config->{'moduleDirs'} } : () ) );
-
 
157
   print &showEntry( 6, 'Script Dirs', join( ',', $config->{'scriptDirs'} ?  @{ $config->{'scriptDirs'} } : () ) );
-
 
158
   print &showEntry( 7, 'Transports', '' );
-
 
159
   foreach my $key ( sort { $a <=> $b } keys %{ $config->{'transports'} } ) {
-
 
160
      print "\t$key\t" . $config->{'transports'}->{$key}->{'name'} . "\n";
-
 
161
   }
-
 
162
   print "Select Option to Edit, or 'Done' if finished [Done]: ";
-
 
163
   my $selection = <>;
-
 
164
   chomp $selection;
-
 
165
   $selection = 'd' unless $selection;
-
 
166
   return lc substr( $selection, 0, 1 );
-
 
167
}
-
 
168
 
-
 
169
sub getValue {
-
 
170
   my ( $prompt, $value ) = @_;
135
&processParameters( @ARGV );
171
   print "$prompt [$value]: ";
-
 
172
   my $t = <>;
-
 
173
   chomp $t;
-
 
174
   return $t ? $t : $value;
-
 
175
}
-
 
176
 
-
 
177
sub editSelection {
-
 
178
   my $selection = shift;
-
 
179
   if ( $selection == 1 ) {
-
 
180
      $config->{'clientName'} = &getValue( 'Client Name', $config->{'clientName'} );
-
 
181
   } elsif ( $selection == 2 ) {
-
 
182
      $config->{'hostname'} = &getValue( 'Host Name', $config->{'hostname'} );
-
 
183
   } elsif ( $selection == 3 ) {
-
 
184
      $config->{'serialNumber'} = &getValue( 'Serial Number', $config->{'serialNumber'} );
-
 
185
   } elsif ( $selection == 4 ) {
-
 
186
      $config->{'UUID'} = &getValue( 'UUID', $config->{'UUID'} );
-
 
187
   } elsif ( $selection == 5 ) {
-
 
188
      my $t = join( ',', $config->{'moduleDirs'} ?  @{ $config->{'moduleDirs'} } : () );
-
 
189
      $t = &getValue( "Comma separated list of Module Directories\n\t", $t );
-
 
190
      my @t = split( ',', $t );
-
 
191
      $config->{'moduleDirs'} =  \@t;
-
 
192
   } elsif ( $selection == 6 ) {
-
 
193
      my $t = join( ',', $config->{'scriptDirs'} ?  @{ $config->{'scriptDirs'} } : () );
-
 
194
      $t = &getValue( "Comma separated list of Script Directories\n\t", $t );
-
 
195
      my @t = split( ',', $t );
-
 
196
      $config->{'scriptDirs'} =  \@t;
-
 
197
   } elsif ( $selection == 7 ) {
-
 
198
      print "Can not automatically do this at this time\nManually edit the file (press enter to continue)";
-
 
199
      my $t = <>;
-
 
200
   }
-
 
201
}
-
 
202
 
-
 
203
my @confFileName;
-
 
204
my $verbose;
-
 
205
my $help;
-
 
206
my $version;
-
 
207
 
-
 
208
# handle any command line parameters that may have been passed in
-
 
209
# verbose is incremental, so for example, -vv would give more info than -v
-
 
210
# there can be multiple files passed, and an entry can have a comma
-
 
211
# separated list. The files will be processed in order, with the last
-
 
212
# one passed in being the one that overrides everything.
-
 
213
GetOptions (
-
 
214
            "verbose|v+" => \$verbose, # verbosity level, 0-9
-
 
215
            'file|f=s'      => \@confFileName,
-
 
216
            'help|h'      => \$help
-
 
217
            ) or die "Error parsing command line\n";
-
 
218
                  
-
 
219
if ( $help ) { &help() ; exit; }
-
 
220
if ( $version ) { print "$0 version $VERSION\n"; exit; }
136
 
221
 
-
 
222
# if they passed something like -f file1,file2,file3, parse it out
-
 
223
@confFileName = split(/,/,join(',',@confFileName));
137
 
224
 
-
 
225
# look for the standard configuration file in the standard place
138
( $confDir, $sysinfo3 ) = &findConf( $sysinfo3 );
226
( $confDir, $sysinfo3 ) = &findConf( $sysinfo3 );
-
 
227
# add it at the tail end of the list
-
 
228
push @confFileName, $confDir . "/" . $sysinfo3 if ( $confDir );
139
 
229
 
-
 
230
print "Loading defaults from existing configs\n";
140
$sysinfo3 = $confDir . "/" . $sysinfo3 if ( $confDir );
231
$config = &makeConfig( @confFileName  );
141
 
232
 
142
if ( -f $sysinfo3 && &yesno( "I found an existing configuration at $sysinfo3, modify it " ) ) {
-
 
143
   print "Loading defaults from existing config $sysinfo3\n";
233
my $selection;
144
   $config = &makeConfig( ( $sysinfo3 )  );
234
while ( ( $selection = &displayEditScreen( $config ) ) ne 'd' ) {
145
   my $content = &showConf( $config );
235
   &editSelection( $selection );
146
}
236
}
147
 
237
 
-
 
238
die;
148
&userConfirmation( $config );
239
#&userConfirmation( $config );
149
 
240
 
150
#use Data::Dumper;
241
#use Data::Dumper;
151
#print Dumper( $config ); die;
242
#print Dumper( $config ); die;
152
 
243
 
153
&doTransports( $$config{'transports'} );
244
&doTransports( $$config{'transports'} );