--gpg-auto-import-keys global option added (fate #307087)
authorJán Kupec <jkupec@suse.cz>
Tue, 10 Nov 2009 17:52:59 +0000 (18:52 +0100)
committerJán Kupec <jkupec@suse.cz>
Tue, 10 Nov 2009 17:52:59 +0000 (18:52 +0100)
src/Zypper.cc
src/Zypper.h
src/callbacks/keyring.h

index f32bc8a..9504025 100644 (file)
@@ -176,8 +176,14 @@ void print_main_help(Zypper & zypper)
     "\t--no-refresh\t\tDo not refresh the repositories.\n"
   )) + string(_(
     // translators: these belong to Repository Options main help text
+    // \todo merge into the main string for 11.3
     "\t--no-cd\t\t\tIgnore CD/DVD repositories.\n"
     "\t--no-remote\t\tIgnore remote repositories.\n"
+  )) + string(_(
+    // translators: these belong to Repository Options main help text
+    // \todo merge into the main string for 11.3
+    "\t--gpg-auto-import-keys\tAutomatically trust and import new repository\n"
+      "\t\t\t\tsigning keys.\n"
   ));
 
   static string help_global_target_options = _("     Target Options:\n"
@@ -324,6 +330,7 @@ void Zypper::processGlobalOptions()
     {"rug-compatible",             no_argument,       0, 'r'},
     {"non-interactive",            no_argument,       0, 'n'},
     {"no-gpg-checks",              no_argument,       0,  0 },
+    {"gpg-auto-import-keys",       no_argument,       0,  0 },
     {"root",                       required_argument, 0, 'R'},
     {"reposd-dir",                 required_argument, 0, 'D'},
     {"cache-dir",                  required_argument, 0, 'C'},
@@ -462,6 +469,15 @@ void Zypper::processGlobalOptions()
     MIL << "Entering no-gpg-checks mode" << endl;
   }
 
+  if (gopts.count("gpg-auto-import-keys")) {
+    _gopts.gpg_auto_import_keys = true;
+    string warn = str::form(
+      _("Turning on '%s'. New repository signing keys will be automatically imported!"),
+      "--gpg-auto-import-keys");
+    out().warning(warn, Out::HIGH);
+    MIL << "gpg-auto-import-keys is on" << endl;
+  }
+
   if ((it = gopts.find("root")) != gopts.end()) {
     _gopts.root_dir = it->second.front();
     _gopts.changedRoot = true;
index c6b7d36..39d361d 100644 (file)
@@ -45,6 +45,7 @@ struct GlobalOptions
   is_rug_compatible(false),
   non_interactive(false),
   no_gpg_checks(false),
+  gpg_auto_import_keys(false),
   machine_readable(false),
   no_refresh(false),
   no_cd(false),
@@ -73,6 +74,7 @@ struct GlobalOptions
   bool is_rug_compatible;
   bool non_interactive;
   bool no_gpg_checks;
+  bool gpg_auto_import_keys;
   bool machine_readable;
   /** Whether to disable autorefresh. */
   bool no_refresh;
index e67567c..fb2118d 100644 (file)
@@ -121,7 +121,9 @@ namespace zypp
        const std::string & keyid = key.id(), keyname = key.name(),
          fingerprint = key.fingerprint();
 
-        if (_gopts.no_gpg_checks)
+       if (_gopts.gpg_auto_import_keys)
+         s << _("Automatically importing the following key:") << std::endl;
+       else if (_gopts.no_gpg_checks)
           s << _("Automatically trusting the following key:") << std::endl;
         else
           s << _("New repository or package signing key received:") << std::endl;
@@ -135,13 +137,22 @@ namespace zypp
           s << str::form(_("Repository: %s"), context.repoInfo().name().c_str())
             << std::endl;
 
-        // print info and dont ask
+        // print info and don't ask
         if (_gopts.no_gpg_checks)
         {
-          MIL << boost::format("Automatically trusting key id '%s', '%s', fingerprint '%s'")
-              % keyid % keyname % fingerprint << std::endl;
           zypper.out().info(s.str());
-          return KeyRingReport::KEY_TRUST_TEMPORARILY;
+          if (_gopts.gpg_auto_import_keys)
+          {
+            MIL << boost::format("Automatically importing key id '%s', '%s', fingerprint '%s'")
+                % keyid % keyname % fingerprint << std::endl;
+            return KeyRingReport::KEY_TRUST_AND_IMPORT;
+          }
+          else
+          {
+            MIL << boost::format("Automatically trusting key id '%s', '%s', fingerprint '%s'")
+                % keyid % keyname % fingerprint << std::endl;
+            return KeyRingReport::KEY_TRUST_TEMPORARILY;
+          }
         }
 
         // ask the user
@@ -159,10 +170,10 @@ namespace zypp
           // The anserws must be separated by slash characters '/' and must
           // correspond to reject/trusttemporarily/trustalways in that order.
           // The answers should be lower case letters.
-          popts.setOptions(_("r/t/a/"), 0);
+          popts.setOptions(_("r/t/a/"), _gopts.gpg_auto_import_keys ? 2 : 0);
         else
           // translators: the same as r/t/a, but without 'a'
-          popts.setOptions(_("r/t"), 0);
+          popts.setOptions(_("r/t"), _gopts.gpg_auto_import_keys ? 1 : 0);
         // translators: help text for the 'r' option in the 'r/t/a' prompt
         popts.setOptionHelp(0, _("Don't trust the key."));
         // translators: help text for the 't' option in the 'r/t/a' prompt