reworked gatherer to be more flexible, added sudo support
[scpubgit/System-Introspector.git] / bin / system-introspector
index 0c16443..1f09084 100644 (file)
@@ -11,6 +11,7 @@ GetOptions(
     'c|config=s'    => \my $config_file,
     's|storage=s'   => \my $storage_dir,
     'H|host=s'      => \my $hostname,
+    'U|user=s'      => \my $username,
     'allow-empty'   => \my $allow_empty,
     'a|all'         => \my $update_all,
     'g|group=s'     => \my @update_groups,
@@ -20,6 +21,9 @@ GetOptions(
 die "Requires --all or --group option\n"
     unless $update_all or @update_groups;
 
+die "The --user option also requires a --host to be set\n"
+    if defined($username) and not defined($hostname);
+
 my $config = System::Introspector::Config->new(
     config_file => (defined($config_file)
                     ? $config_file
@@ -31,6 +35,8 @@ $config->has_group($_) or die "Unknown group '$_'\n"
 
 @update_groups = $config->groups
     if $update_all;
+    
+my $sudo_user = $config->sudo_user;
 
 for my $group (@update_groups) {
     my $group_dir = "$storage_dir/$group";
@@ -42,12 +48,15 @@ for my $group (@update_groups) {
     $storage->create
         unless $storage->exists;
     my $state = System::Introspector::State->new(
-        defined($hostname) ? (host => $hostname) : (),
+        defined($hostname)  ? (host => $hostname) : (),
+        defined($username)  ? (user => $username) : (),
+        defined($sudo_user) ? (sudo_user => $sudo_user) : (),
         storage => $storage,
         config  => $config->config_for_group($group),
     );
     eval { $state->fetch_and_store };
     if (my $error = $@) {
+        warn "Error: $error\n";
         $storage->reset;
     }
     else {