file - The LCFG file component
The file component can be used to create arbitrary configuration files
and directories without the need to write a custom component. The
templates for the configuration files, and the resources to be
substituted in them, may be supplied directly as resources of the
file component, or may be specified in an independent .def file
(a ``managed component'').
A list of ``managed'' components for which configuration files should
be generated. For each component comp in the list, the resources
specified below (see MANAGED COMPONENT RESOURCES) must be
present. This list should normally include the file component
itself, so that configuration files can be generated from file
resources without any additional default files. The default value is
file.
See MANAGED COMPONENT RESOURCES
See MANAGED COMPONENT RESOURCES
See MANAGED COMPONENT RESOURCES
See MANAGED COMPONENT RESOURCES
See MANAGED COMPONENT RESOURCES
See MANAGED COMPONENT RESOURCES
See MANAGED COMPONENT RESOURCES
A list of variable tags for variables to be substituted in any templates
declared in the files resource.
The values of the variable given by the var tag.
Each managed component should define the following resources to
specify the configuration files or directories to be created on its
behalf by the file component. The managed components may include
code of their own but, typically, they do not - they consist of only a
.def file and the file component uses this to create their
configuration files.
Managed components should also set the resource comp.ng_cfdepend to >file so that the file component is called whenever the resources change.
A list of file/directory tags. Each tag corresponds to a configuration file or directory to be created on behalf of the component comp.
A space-separated list of pathnames for configuration files or directories corresponding to tag for component comp. Normally, these will be full pathnames, but several objects in the same directory can be specified by giving a common prefix; for example:
/home/users : fred jill
The group for the file or directory corresponding to tag. If this is null, then files are created with the same group as the template, and directories with the same group as the running component.
The file mode (in octal, starting with 0) for the file or directory corresponding to tag. If this is null, then files are created with the same mode as the template, and directories with the mode 0755.
The owner for the file or directory corresponding to tag. If this
is null, then files are created with the same owner as the template,
and directories with the same owner as the running component. Changing
ownership of links normally changes the ownership of the target and is
not recommended. If the owner is specified as *, then the name of
the file itself is used as the owner. This is useful for creating home
directories, for example.
If the file corresponding to tag has type template, then this
resource should give the full pathname of the template file. If the
type is literal, then this resource should specify the template
literally - newlines may be included by using the \n escape
sequence. Similarly if the type is base64, then this resource
should specify base64 encoded data, with \n escape sequences
joining any lines together. The component decodes this data before
treating it exactly the same as if it were of type literal. The
base64 type is useful for distributing literal file contents that
includes characters which are processed by the compiler, but it does
lead to obfuscated configurations.
The template is passed through the template processor with the resources of comp defined, to create the configuration file.
The type of the configuration file or directory corresponding to
tag for component comp. This may be delete, to delete any
existing configuration file, template to create a file from a
template file, literal to create a file from a literal template,
base64 a variation of literal where the text is supplied base64
encoded, link to create a symlink from the template to the file, or
dir to create a directory. The type may optionally be followed by a
colon and a space-separated list of options. The zap option will
delete any existing filesystem object with the same pathname as the
target file if it has a different type. Directories will be deleted
recursively and this should be used with care! The mkdir option
will create the parent directories for a file or link if they do not
already exist (parents are always created automatically for
directories). The noback option will prevent creation of backup
files. The perl option will use the Perl template processor instead
of the LCFG one.
You can use this Perl snippet to generate base64 encoded data ready for assigning to the resource.
perl -e 'use MIME::Base64;
while (<>) {
print encode_base64($_, "\\n");
}
print "\n";' < source_file
#include "mutate.h" #include "ngeneric-1.def"
!ng_cfdepend mSET(>file) !ng_statusdisplay mSET(false) !ng_reconfig mSET()
@files type_$ tmpl_$ file_$ type_$ tmpl_$ file_$ owner_$ group_$ mode_$ var1 var2
files A B homes
type_A template tmpl_A path to the template file_A path to the config file type_B literal tmpl_B the value of var1 is <%var1%> file_B path to the config file
var1 some value to substitute in a template var2 some value to substitute in a template
type_homes dir file_homes /home : fred jill owner_homes * group_homes users mode_homes 0700
Solaris9, Fedora3, Fedora5, Fedora6, Scientific5
Paul Anderson <dcspaul@inf.ed.ac.uk>