* Finished updating tools/anvil-prep-database to inject the new, local database entry into anvil.conf. This tool works again.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 7 years ago
parent a89fb24adf
commit 5f06752167
  1. 13
      Anvil/Tools/Database.pm
  2. 24
      Anvil/Tools/Storage.pm
  3. 1
      share/words.xml
  4. 16
      tools/anvil-prep-database

@ -1246,9 +1246,17 @@ sub get_local_uuid
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"network_details->hostname" => $network_details->{hostname},
"database::${uuid}::host" => $anvil->data->{database}{$uuid}{host},
"database::${uuid}::host" => $anvil->data->{database}{$uuid}{host},
}});
if ($network_details->{hostname} eq $anvil->data->{database}{$uuid}{host})
# If the uuid matches our host_uuid or if the hostname matches ours (or is localhost), return
# that UUID.
if ($uuid eq $anvil->Get->host_uuid)
{
$local_uuid = $uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { local_uuid => $local_uuid }});
last;
}
elsif (($network_details->{hostname} eq $anvil->data->{database}{$uuid}{host}) or ($anvil->data->{database}{$uuid}{host} eq "localhost"))
{
$local_uuid = $uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { local_uuid => $local_uuid }});
@ -1283,7 +1291,6 @@ sub get_local_uuid
}
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { local_uuid => $local_uuid }});
return($local_uuid);
}

@ -1051,7 +1051,7 @@ C<< 3 >> = File not readable
Parameters;
=head3 file (required)
=head3 file (optional, default file stored in 'path::configs::anvil.conf')
This is the configuration file to read.
@ -1078,7 +1078,7 @@ sub read_config
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
# Setup default values
my $file = defined $parameter->{file} ? $parameter->{file} : 0;
my $file = defined $parameter->{file} ? $parameter->{file} : $anvil->data->{path}{configs}{'anvil.conf'};
my $return_code = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { file => $file }});
@ -1124,21 +1124,26 @@ sub read_config
}
else
{
# Read it in!
# Read it in!
my $count = 0;
open (my $file_handle, "<$file") or die "Can't read: [$file], error was: $!\n";
while (<$file_handle>)
my $body = $anvil->Storage->read_file({file => $file});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { body => $body }});
foreach my $line (split/\n/, $body)
{
chomp;
my $line = $_;
$line =~ s/^\s+//;
$line =~ s/\s+$//;
$line = $anvil->Words->clean_spaces({ string => $line });
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { line => $line }});
$count++;
# Skip empty lines and lines that start with a '#', and lines without an '='.
next if ((not $line) or ($line =~ /^#/));
next if $line !~ /=/;
my ($variable, $value) = split/=/, $line, 2;
$variable =~ s/\s+$//;
$value =~ s/^\s+//;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"s1:variable" => $variable,
"s2:value" => $value,
}});
if (not $variable)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "alert", key => "log_0035", variables => {
@ -1150,7 +1155,6 @@ sub read_config
$anvil->_make_hash_reference($anvil->data, $variable, $value);
}
close $file_handle;
}
}

@ -349,6 +349,7 @@ Here we will inject 't_0006', which injects 't_0001' which has a variable: [#!st
<key name="error_0007">The passwords don't match, exiting.</key>
<key name="error_0008">Failed to read the file: [#!variable!file!#]. Please see the logs for details</key>
<key name="error_0009">Failed to add the target: [#!variable!target!#]:[#!variable!port!#]'s RSA fingerprint to: [#!variable!user!#]'s list of known hosts.</key>
<key name="error_0010">There was a problem adding the local machine to the: [#!data!path::configs::anvil.conf!#] file. Please see the log for details.</key>
<!-- These are works and strings used by javascript/jqery -->
<key name="js_0001">Up</key>

@ -36,7 +36,7 @@ $anvil->Get->switches;
# Paths
$anvil->Storage->read_config({file => $anvil->data->{path}{configs}{'anvil.conf'}});
my $local_uuid = $anvil->Database->get_local_uuid;
my $local_uuid = $anvil->Database->get_local_uuid();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { local_uuid => $local_uuid }});
# If we didn't get the $local_uuid, then there is no entry for this system in anvil.conf yet, so we'll add it.
@ -44,8 +44,14 @@ if (not $local_uuid)
{
$local_uuid = add_to_local_config($anvil);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { local_uuid => $local_uuid }});
# If we still don't have a local_uuid, something went wrong.
if (not $local_uuid)
{
print $anvil->Words->string({key => "error_0010"})."\n";
$anvil->nice_exit({code => 1});
}
}
exit;
# Now configure!
if ($local_uuid)
@ -404,7 +410,7 @@ else
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0143"});
}
exit(0);
$anvil->nice_exit({code => 0});
#############################################################################################################
@ -465,6 +471,7 @@ sub add_to_local_config
# Now update!
$anvil->Storage->write_file({
debug => 2,
file => $anvil->data->{path}{configs}{'anvil.conf'},
body => $new_body,
user => "admin",
@ -476,6 +483,9 @@ sub add_to_local_config
# Record the local UUID for returning to the caller.
$local_uuid = $host_uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { local_uuid => $local_uuid }});
# Re-read the new config.
$anvil->Storage->read_config({file => $anvil->data->{path}{configs}{'anvil.conf'}});
}
return($local_uuid);

Loading…
Cancel
Save