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
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);
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:
#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"
{
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;
}
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;
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);