]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- allow to select template during create-config
authorArvin Schnell <aschnell@suse.de>
Fri, 8 Apr 2011 08:54:15 +0000 (10:54 +0200)
committerArvin Schnell <aschnell@suse.de>
Fri, 8 Apr 2011 08:54:15 +0000 (10:54 +0200)
snapper/Snapper.cc
snapper/Snapper.h
snapper/SnapperDefines.h
tools/snapper.cc

index f1387450632b1ee10aaa6e22d6ddda3606799a60..708827763d57dc670d2164556c140ae2e0d615f8 100644 (file)
@@ -514,11 +514,13 @@ namespace snapper
 
 
     bool
-    Snapper::addConfig(const string& config_name, const string& subvolume)
+    Snapper::addConfig(const string& config_name, const string& subvolume,
+                      const string& template_name)
     {
        y2mil("Snapper add-config");
        y2mil("libsnapper version " VERSION);
-       y2mil("config_name:" << config_name << " subvolume:" << subvolume);
+       y2mil("config_name:" << config_name << " subvolume:" << subvolume <<
+             " template_name:" << template_name);
 
        // TODO: error handling
 
@@ -530,7 +532,8 @@ namespace snapper
        config_names.push_back(config_name);
        sysconfig.setValue("SNAPPER_CONFIGS", config_names);
 
-       SystemCmd cmd1(CPBIN " " DEFAULTCONFIGTEMPLATEFILE " " CONFIGSDIR "/" + config_name);
+       SystemCmd cmd1(CPBIN " " CONFIGTEMPLATEDIR "/" + template_name + " " CONFIGSDIR "/" +
+                      config_name);
 
        SysconfigFile config(CONFIGSDIR "/" + config_name);
        config.setValue("SUBVOLUME", subvolume);
index b5fcce92731e41b4910e34db2e2b37f7177d71fd..a152b6fb28e8c9f3f23ab0dfae2df916bd709e2b 100644 (file)
@@ -90,7 +90,8 @@ namespace snapper
        const vector<string>& getIgnorePatterns() const { return ignore_patterns; }
 
        static list<ConfigInfo> getConfigs();
-       static bool addConfig(const string& config_name, const string& subvolume);
+       static bool addConfig(const string& config_name, const string& subvolume,
+                             const string& template_name);
 
     private:
 
index d4e55651ee3a027679b6f3d1be6b4f96e391c541..2ffe6dae39cd239ec1fe3dfe68e6e3b65f6c001f 100644 (file)
@@ -27,9 +27,9 @@
 #define SYSCONFIGFILE "/etc/sysconfig/snapper"
 
 #define CONFIGSDIR "/etc/snapper/configs"
-#define FILTERSDIR "/etc/snapper/filters"
+#define CONFIGTEMPLATEDIR "/etc/snapper/config-templates"
 
-#define DEFAULTCONFIGTEMPLATEFILE "/etc/snapper/config-templates/default"
+#define FILTERSDIR "/etc/snapper/filters"
 
 #define SNAPSHOTDIR "/snapshot"
 #define SNAPSHOTSDIR "/snapshots"
index 859b1ac3dcf8fa64dcecce8ae36657daf7d37910..b83828354384c6c4c2ba1bb83d4484909caf9290 100644 (file)
@@ -76,6 +76,9 @@ help_create_config()
 {
     cout << _("  Create config:") << endl
         << _("\tsnapper create-config <subvolume>") << endl
+        << endl
+        << _("    Options for 'create-config' command:") << endl
+        << _("\t--template, -t <name>\t\tName of config template to use.") << endl
         << endl;
 }
 
@@ -83,7 +86,12 @@ help_create_config()
 void
 command_create_config()
 {
-    getopts.parse("create-config", GetOpts::no_options);
+    const struct option options[] = {
+       { "template",           required_argument,      0,      't' },
+       { 0, 0, 0, 0 }
+    };
+
+    GetOpts::parsed_opts opts = getopts.parse("create-config", options);
     if (getopts.numArgs() != 1)
     {
        cerr << _("Command 'create-config' needs one argument.") << endl;
@@ -92,7 +100,14 @@ command_create_config()
 
     string subvolume = getopts.popArg();
 
-    if (!Snapper::addConfig(config_name, subvolume))
+    string template_name = "default";
+
+    GetOpts::parsed_opts::const_iterator opt;
+
+    if ((opt = opts.find("template")) != opts.end())
+       template_name = opt->second;
+
+    if (!Snapper::addConfig(config_name, subvolume, template_name))
     {
        cerr << _("Creating config failed.") << endl;
        exit(EXIT_FAILURE);