metaconf

Introduction

metaconf is a generic software for maintenance of multiple configurations in a single machine. One of its main uses is for notebook users which need mobility between several places, but unlike other similar softwares, metaconf is not designed to work specifically with network configurations. Indeed, it may be used to alternate between almost any kind of configuration, as far as the user knows how to configure the softwares properly.

How it works

First, metaconf doesn't know about any kind of archives nor commands. Instead, metaconf will provide the tools you need to store and manage confortably the necessary actions to put the system in a named state.

Two of the main building blocks of metaconf are commands and metafiles. Commands, as you expect, may be usual shell commands, or commands of any language which has an interpreter. On the other hand, metafiles introduce a new and exciting concept. A metafile is a single configuration file that contains sections which are uncommented or commented out depending on the configuration you are using. These files don't need any special format, being the only requisite that the file format has the idea of a comment character (may be more than one).

The other ideas introduced by metaconf allow one to mix and extract the best out of the basic building blocks. For example, it's possible to build base configurations and inherit from them, or use dynamic parameters inside commands and metafiles.

Random ideas

Here is a list of ideas where metaconf could be used.

Command usage

The basic usage of metaconf is like:

metaconf configname

or

metaconf configname parm1=value1 parm2=value2

Here is the output of metaconf --help:

Usage: metaconf [options] <confname> ... [<parm>=<value> ...]

Options:
  --version            show program's version number and exit
  -h, --help           show this help message and exit
  -fFILE, --file=FILE  configuration file (default is ~/.metaconf/config or
                       /etc/metaconf)
  -l, --list           list available configurations
  --dryrun             do not commit changes to the system
  --log=LEVEL          set logging level to LEVEL (debug, info, warning, error)

MetaFile format

Basics

One of the nice features of metaconf is the ability to control multiple configurations in a single file through the use of metafiles. As explained above, these files have no specific format, being the only requirement that their format accept the idea of a comment character. This comment character will be used to introduce special tags with expressions in some lines, and to comment and uncomment sections of the metafile on demand.

Here is an example of a metafile:

# These are comments preceding the first set.
# The option below is also before the first special tag.

option1 = value1

# Now, we have a special comment:
#:set: setname1

# This will be disabled, unless we are running setname1.
option2 = value2

# Another special comment, a little bit more complex.
#:set: setname2 setname3

# This will be disabled, unless we are running setname2
# or setname3.
option3 = value3

#:set:

# This will always be enabled.
option4 = value4

This file should give you the general idea. Now, suppose we have this configuration:

<MetaConf>
<Config name="confname2">
  <MetaFile set="setname2">mymetafile</MetaFile>
</Config>
</MetaConf>

If we execute metaconf confname2, we'll end up with the following configuration file:

# These are comments preceding the first set.
# The option below is also before the first special tag.

option1 = value1

# Now, we have a special comment:
#:set: setname1

# This will be disabled, unless we are running setname1.
#:disabled:option2 = value2

# Another special comment, a little bit more complex.
#:set: setname2 setname3

# This will be disabled, unless we are running setname2
# or setname3.
option3 = value3

#:set:

# This will always be enabled.
option4 = value4

Notice that option2 was commented out, while most of the file structure was left intact.

Parameters

In addition to the tags presented above, there's also a special tag for using parameters inside metafiles. Unfortunately, we can't use a single line because we loose track of the parameter itself.

For example, suppose we have the following /etc/hosts file:

#:parm:myhostname %(myip)s
myhostname 127.0.0.1

And the following configuration:

<MetaConf>
<Config name="confname">
  <Parm name="myip">127.0.0.1</Parm>
  <MetaFile parm="myip">myhosts</MetaFile>
</Config>
</MetaConf>

If we execute simply metaconf confname, the file won't be changed since we have a default parameter which is the same as in the current file, but if we execute metaconf confname myip=10.0.0.1, we'll end up with the following file:

#:parm:myhostname %(myip)s
myhostname 10.0.0.1

Includes

Another nice feature of metafile is the ability to inline other files. For example, pppd generates a file in /etc/ppp/resolv.conf if you enable the usepeerdns option. You may want to inline it in your /etc/resolv.conf, with something like:

# This is /etc/resolv.conf
nameserver 1.2.3.4

#:set: mydialup
#:include: /etc/ppp/resolv.conf
#:include:
#:set:

Next time you run metaconf in a configuration that enables the mydialup section, the given file will be inlined between the include markup.

Configuration

metaconf configuration is stored on an XML file, which is located either in ~/.metaconf/config or /etc/metaconf (or anywhere -f points to).

The basic format of the configuration file is:

<MetaConf>

<Config name="configname1">
...
</Config>

<Config name="configname2">
...
</Config>

...

</MetaConf>

Below there's a list of the allowed tags and their meanings.

<MetaConf>

This is the basic tag which groups configurations. MetaConf tags may be nested, so that included files may contain a top MetaConf tag as well.

This tag accepts no attributes.

There's an example of its usage above.

<Config>

The Config tag creates a group of actions with a name. That's how configurations are made.

Available attributes:

name
This attribute informs the name of the configuration to be used in the command line, or in inherits.
list

If set to false, this config will not be listed when -l is used in the command line.

There's an example of its usage above.

<Include>

This tag will include the given filename at the current point. If the filename doesn't start with a /, the same path of the including file will be used.

This tag accepts no attributes.

Examples:

<Include>metaconf.firewall</Include>

<Inherit>

The Inherit tag executes at the current point the given configurations. If more than one configuration is given, they must be separated with spaces, and will be executed in the given order.

This tag accepts no attributes.

Examples:

<Inherit>myconfig1 myconfig2</Inherit>

<Command>

The Command tag will execute the given commands, which may be a complex command including more than one line, with the given interpreter.

Available tags:

shell

Interpreter used to execute the commands. Defaults to /bin/sh.

show

If set to true, the command output will be shown if available.

error

If set to ignore, errors from the given commands will be ignored.

parm
List of parameters needed by this command, separated by spaces.

Examples:

<Command>echo "Hello world!"</Command>

<Command parm="parm1">echo "parm1 is %(parm1)s"</Command>

<Command>
  for word in multiline command; do
    echo $word
  done
</Command>

<MetaFileSet>

The given sets will be enabled in all further processed metafiles. If more than one set is given, they must be separated with spaces.

This tag accepts no attributes.

Examples:

<MetaFileSet>home adsl</MetaFileSet>

<MetaFile>

The MetaFile tag defines one or more files which will be processed as metafiles at the point of execution of this tag. Filenames may be prefixed by ~, with the usual meaning, or by the special prefix ~*/, meaning for every user home in the system. If using the special prefix, inexistent files will be ignored. In every other case a warning will be issued.

Available attributes:

set
The given sets will be enabled in this file, in addition to

the other sets queued by the MetaFileSet tag.

comment
Define the comment character used by this file format.

If not given, it defaults to #.

parm
List of parameters needed by this command, separated by spaces.

Examples:

<MetaFile set="home">
  /etc/hosts
  /etc/resolv.conf
</MetaFile>

<MetaFile comment="//">/etc/named.conf</MetaFile>

<Parm>

The Parm tag will define a default value for the given parameter. If the same parameter is given in the command line, or if a previous Parm tag is found with the same name as the one being processed, it will be ignored.

Available attributes:

name
Defines the name of the parameter.

Examples:

<Parm name="ip">127.0.0.1</Parm>

Download

The following files are available:

License

metaconf is licensed under the GPL.

Author

Gustavo Niemeyer <gustavo@niemeyer.net>


CategoryProject

metaconf (last edited 2008-03-03 03:16:21 by GustavoNiemeyer)