Subversion Repositories camp_sysinfo_client_3

Rev

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

Rev 211 Rev 218
Line 186... Line 186...
186
   return $yaml->[0];
186
   return $yaml->[0];
187
}
187
}
188
 
188
 
189
sub makeConfig {
189
sub makeConfig {
190
   my @configFileNames = @_;
190
   my @configFileNames = @_;
191
   my %config;
191
   my $config;
192
 
192
 
-
 
193
   use Hash::Merge;
-
 
194
   my $merge = Hash::Merge->new('RIGHT_PRECEDENT');
193
   foreach my $config ( @configFileNames ) {
195
   foreach my $configFile ( @configFileNames ) {
-
 
196
      next unless $configFile && -e $configFile;
-
 
197
      print "Processing config file $configFile\n";
194
      my $thisConfig = &readConfig( $config ) if $config && -e $config;
198
      my $thisConfig = &readConfig( $configFile );
195
      # add the new config to %config, overwriting any existing keys which are duplicated
199
      # add the new config to %config, overwriting any existing keys which are duplicated
-
 
200
      $config = $merge->merge( $config, $thisConfig );
196
      @config{keys %$thisConfig} = values %$thisConfig;
201
      #@config{keys %$thisConfig} = values %$thisConfig;
197
   }
202
   }
-
 
203
   use Data::Dumper;
-
 
204
 
-
 
205
   die Dumper( $config );
198
   # now, ensure the correct values are loaded in some areas
206
   # now, ensure the correct values are loaded in some areas
199
   unless ( $config{'hostname'} ) {
207
   unless ( $config->{'hostname'} ) {
200
      $hostname = `hostname -f`;
208
      $hostname = `hostname -f`;
201
      chomp $hostname;
209
      chomp $hostname;
202
      $config{'hostname'} = $hostname;
210
      $config->{'hostname'} = $hostname;
203
   }
211
   }
204
   unless ( $config{'serialNumber'} ) {
212
   unless ( $config->{'serialNumber'} ) {
205
      $serialNumber = `dmidecode -t 1 | grep 'Serial Number' | cut -d':' -f2` if `which dmidecode`;
213
      $serialNumber = `dmidecode -t 1 | grep 'Serial Number' | cut -d':' -f2` if `which dmidecode`;
206
      chomp $serialNumber;
214
      chomp $serialNumber;
207
      $serialNumber =~ s/\s//gi;
215
      $serialNumber =~ s/\s//gi;
208
      $config{'serialNumber'} = $serialNumber;
216
      $config->{'serialNumber'} = $serialNumber;
209
   }
217
   }
210
   unless ( $config{'UUID'} ) {
218
   unless ( $config->{'UUID'} ) {
211
      my $UUID = `which dmidecode` ?  `dmidecode -t 1 | grep -i uuid | cut -d':' -f2` : '';
219
      my $UUID = `which dmidecode` ?  `dmidecode -t 1 | grep -i uuid | cut -d':' -f2` : '';
212
      $UUID =~ s/\s//gi;
220
      $UUID =~ s/\s//gi;
213
      $config{'UUID'} = $UUID;
221
      $config->{'UUID'} = $UUID;
214
   }
222
   }
215
 
223
 
216
   # ensure we have the default SaveLocal transport defined
224
   # ensure we have the default SaveLocal transport defined
217
   unless ( defined $config{'transports'}{'99'} ) {
225
   unless ( defined $config->{'transports'}{'99'} ) {
218
      $config{'transports'}{'99'} = {
226
      $config->{'transports'}{'99'} = {
219
                         'name'=> 'SaveLocal',
227
                         'name'=> 'SaveLocal',
220
                         'output directory' => '/tmp',
228
                         'output directory' => '/tmp',
221
                         'sendScript' => 'save_local'
229
                         'sendScript' => 'save_local'
222
                        };
230
                        };
223
   }
231
   }
224
 
232
 
225
   return \%config;
233
   return $config;
226
}
234
}
227
 
235
 
228
# prompt the user for a response, then allow them to enter it
236
# prompt the user for a response, then allow them to enter it
229
# the first response is considered the default and is printed
237
# the first response is considered the default and is printed
230
# in all caps if more than one exists
238
# in all caps if more than one exists