From: Arvin Schnell Date: Fri, 8 Apr 2011 08:54:15 +0000 (+0200) Subject: - allow to select template during create-config X-Git-Tag: v0.1.3~415 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3aaff7ce60c11f1f59dc26cd39574377efc8e8ad;p=thirdparty%2Fsnapper.git - allow to select template during create-config --- diff --git a/snapper/Snapper.cc b/snapper/Snapper.cc index f1387450..70882776 100644 --- a/snapper/Snapper.cc +++ b/snapper/Snapper.cc @@ -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); diff --git a/snapper/Snapper.h b/snapper/Snapper.h index b5fcce92..a152b6fb 100644 --- a/snapper/Snapper.h +++ b/snapper/Snapper.h @@ -90,7 +90,8 @@ namespace snapper const vector& getIgnorePatterns() const { return ignore_patterns; } static list 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: diff --git a/snapper/SnapperDefines.h b/snapper/SnapperDefines.h index d4e55651..2ffe6dae 100644 --- a/snapper/SnapperDefines.h +++ b/snapper/SnapperDefines.h @@ -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" diff --git a/tools/snapper.cc b/tools/snapper.cc index 859b1ac3..b8382835 100644 --- a/tools/snapper.cc +++ b/tools/snapper.cc @@ -76,6 +76,9 @@ help_create_config() { cout << _(" Create config:") << endl << _("\tsnapper create-config ") << endl + << endl + << _(" Options for 'create-config' command:") << endl + << _("\t--template, -t \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);