.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Config::Augeas 3pm" .TH Config::Augeas 3pm 2024-03-07 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Config::Augeas \- Edit configuration files through Augeas C library .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& use Config::Augeas; \& \& my $aug = Config::Augeas\->new( root => $aug_root ) ; \& \& my $ret = $aug\->get("/files/etc/hosts/1/ipaddr") ; \& $aug\->set("/files/etc/hosts/2/ipaddr","192.168.0.1") ; \& \& my @a = $aug\->match("/files/etc/hosts/") ; \& \& my $nb = $aug\->count_match("/files/etc/hosts/") ; \& \& $aug\->save ; .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" Augeas is a library and command line tool that focuses on the most basic problem in handling Linux configurations programmatically: editing actual configuration files in a controlled manner. .PP To that end, Augeas exposes a tree of all configuration settings (well, all the ones it knows about) and a simple local API for manipulating the tree. Augeas then modifies underlying configuration files according to the changes that have been made to the tree; it does as little modeling of configurations as possible, and focuses exclusively on transforming the tree-oriented syntax of its public API to the myriad syntaxes of individual configuration files. .PP This module provides an object oriented Perl interface for Augeas configuration edition library with a more "perlish" API than Augeas C counterpart. .SH Constructor .IX Header "Constructor" .SH "new ( ... )" .IX Header "new ( ... )" Creates a new Config::Augeas object. Optional parameters are: .IP loadpath 4 .IX Item "loadpath" a colon-spearated list of directories that lenses should be searched in. This is in addition to the standard load path and the directories in specified \f(CW\*(C`AUGEAS_LENS_LIB\*(C'\fR environment variable. .IP root 4 .IX Item "root" Use \f(CW\*(C`root\*(C'\fR as the filesystem root. If not specified, use the value of the environment variable \f(CW\*(C`AUGEAS_ROOT\*(C'\fR. If that doesn't exist either, use "\f(CW\*(C`/\*(C'\fR". .IP "save => backup | newfile | noop" 4 .IX Item "save => backup | newfile | noop" Specify how to save the configuration file. Either create a newfile (with extension \f(CW\*(C`.augnew\*(C'\fR, and do not overwrite the original file) or move the original file into a backup file (\f(CW\*(C`.augsave\*(C'\fR extension). \&\f(CW\*(C`noop\*(C'\fR make saves a no-op process, just record what would have changed .IP "type_check => 1" 4 .IX Item "type_check => 1" Typecheck lenses; since it can be very expensive it is not done by default. .IP no_std_inc 4 .IX Item "no_std_inc" Do not use the builtin load path for modules .IP no_load 4 .IX Item "no_load" Do not load the tree from AUG_INIT .SH Methods .IX Header "Methods" .SS "defvar( name, [ expr ])" .IX Subsection "defvar( name, [ expr ])" Define a variable \f(CW\*(C`name\*(C'\fR whose value is the result of evaluating \&\f(CW\*(C`expr\*(C'\fR. If a variable \f(CW\*(C`name\*(C'\fR already exists, its name will be replaced with the result of evaluating \f(CW\*(C`expr\*(C'\fR. .PP If \f(CW\*(C`expr\*(C'\fR is omitted, the variable \f(CW\*(C`name\*(C'\fR will be removed if it is defined. .PP Path variables can be used in path expressions later on by prefixing them with '$'. .PP Returns \-1 on error; on success, returns 0 if \f(CW\*(C`expr\*(C'\fR evaluates to anything other than a nodeset, and the number of nodes if \f(CW\*(C`expr\*(C'\fR evaluates to a nodeset .SS "defnode ( name, expr, value )" .IX Subsection "defnode ( name, expr, value )" Define a variable \f(CW\*(C`name\*(C'\fR whose value is the result of evaluating \&\f(CW\*(C`expr\*(C'\fR, which must evaluate to a nodeset. If a variable \f(CW\*(C`name\*(C'\fR already exists, its name will be replaced with the result of evaluating \f(CW\*(C`expr\*(C'\fR. .PP If \f(CW\*(C`expr\*(C'\fR evaluates to an empty nodeset, a node is created, equivalent to calling \f(CW\*(C`set( expr, value)\*(C'\fR and \f(CW\*(C`name\*(C'\fR will be the nodeset containing that single node. .PP Returns undef on error .PP Returns an array containing: .IP \(bu 4 the number of nodes in the nodeset .IP \(bu 4 1 if a node was created, and 0 if it already existed. .SS "get( path )" .IX Subsection "get( path )" Lookup the value associated with \f(CW\*(C`path\*(C'\fR. Returns the value associated with \f(CW\*(C`path\*(C'\fR if \f(CW\*(C`path\*(C'\fR matches exactly one node. If PATH matches no nodes or more than one node, returns undef. .SS "set ( path, value )" .IX Subsection "set ( path, value )" Set the value associated with \f(CW\*(C`path\*(C'\fR to \f(CW\*(C`value\*(C'\fR. \f(CW\*(C`value\*(C'\fR is copied into Augeas internal data structure. Intermediate entries are created if they don't exist. Return 1 on success, 0 on error. It is an error if more than one node matches \f(CW\*(C`path\*(C'\fR. .SS "text_store ( lens, node, path )" .IX Subsection "text_store ( lens, node, path )" Use the value of node \f(CW\*(C`node\*(C'\fR as a string and transform it into a tree using the lens \f(CW\*(C`lens\*(C'\fR and store it in the tree at \f(CW\*(C`path\*(C'\fR, which will be overwritten. \f(CW\*(C`path\*(C'\fR and \f(CW\*(C`node\*(C'\fR are path expressions. .SS "text_retrieve ( lens, node_in, path, node_out )" .IX Subsection "text_retrieve ( lens, node_in, path, node_out )" Transform the tree at \f(CW\*(C`path\*(C'\fR into a string using lens \f(CW\*(C`lens\*(C'\fR and store it in the node \f(CW\*(C`node_out\*(C'\fR, assuming the tree was initially generated using the value of node \f(CW\*(C`node_in\*(C'\fR. \f(CW\*(C`path\*(C'\fR, \f(CW\*(C`node_in\*(C'\fR, and \f(CW\*(C`node_out\*(C'\fR are path expressions. .SS "insert ( label, before | after , path )" .IX Subsection "insert ( label, before | after , path )" Create a new sibling \f(CW\*(C`label\*(C'\fR for \f(CW\*(C`path\*(C'\fR by inserting into the tree just before or just after \f(CW\*(C`path\*(C'\fR. .PP \&\f(CW\*(C`path\*(C'\fR must match exactly one existing node in the tree, and \f(CW\*(C`label\*(C'\fR must be a label, i.e. not contain a '/', '*' or end with a bracketed index '[N]'. .PP Return 1 on success, and 0 if the insertion fails. .SS "remove ( path )" .IX Subsection "remove ( path )" Remove path and all its children. Returns the number of entries removed. All nodes that match \f(CW\*(C`path\*(C'\fR, and their descendants, are removed. (\f(CW\*(C`remove\*(C'\fR can also be called with \f(CW\*(C`rm\*(C'\fR) .SS "move ( src, dest )" .IX Subsection "move ( src, dest )" Move the node SRC to DST. SRC must match exactly one node in the tree. DST must either match exactly one node in the tree, or may not exist yet. If DST exists already, it and all its descendants are deleted. If DST does not exist yet, it and all its missing ancestors are created. .PP Note that the node SRC always becomes the node DST: when you move \&\f(CW\*(C`/a/b\*(C'\fR to \f(CW\*(C`/x\*(C'\fR, the node \f(CW\*(C`/a/b\*(C'\fR is now called \f(CW\*(C`/x\*(C'\fR, no matter whether \f(CW\*(C`/x\*(C'\fR existed initially or not. (\f(CW\*(C`move\*(C'\fR can also be called with \f(CW\*(C`mv\*(C'\fR) .PP Returns 1 in case of success, 0 otherwise. .SS "rename ( src, dest )" .IX Subsection "rename ( src, dest )" Rename the label of all nodes matching \f(CW\*(C`src\*(C'\fR to \f(CW\*(C`lbl\*(C'\fR. .PP Returns the number of nodes renamed on success and \-1 on failure. .SS "span ( path )" .IX Subsection "span ( path )" Returns a hash containing the \f(CW\*(C`filename\*(C'\fR, \f(CW\*(C`label_start\*(C'\fR, \f(CW\*(C`label_end\*(C'\fR, \&\f(CW\*(C`value_start\*(C'\fR, \f(CW\*(C`value_end\*(C'\fR, \f(CW\*(C`span_start\*(C'\fR and \f(CW\*(C`span_end\*(C'\fR of the given \f(CW\*(C`path\*(C'\fR. .PP Example: .PP .Vb 5 \& my $span = $aug\->span(\*(Aq/files/etc/passwd/root\*(Aq) ; \& # If filename is undefined, there are no valid span information for this node \& if ($span\->{filename}) { \& print "Found root in passwd at character $span\->{span_start}\en" ; \& } .Ve .PP WARNING: You must check that \f(CW$span\fR\->{filename} is defined. If it isn't, the node has no span information and all other values in the hash are wrong. .SS "match ( pattern )" .IX Subsection "match ( pattern )" Returns an array of the elements that match of the path expression \&\f(CW\*(C`pattern\*(C'\fR. The returned paths are sufficiently qualified to make sure that they match exactly one node in the current tree. .SS "count_match ( pattern )" .IX Subsection "count_match ( pattern )" Same as match but return the number of matching element in manner more efficient than using \f(CW\*(C`scalar match( pattern )\*(C'\fR .SS save .IX Subsection "save" Write all pending changes to disk. Return 0 if an error is encountered, 1 on success. Only files that had any changes made to them are written. \f(CW\*(C`save\*(C'\fR will follow backup files as specified with Config::Augeas::new \f(CW\*(C`backup\*(C'\fR parameter. .SS load .IX Subsection "load" Load files into the tree. Which files to load and what lenses to use on them is specified under \f(CW\*(C`/augeas/load\*(C'\fR in the tree; each entry \&\f(CW\*(C`/augeas/load/NAME\*(C'\fR specifies a 'transform', by having itself exactly one child 'lens' and any number of children labelled 'incl' and 'excl'. The value of NAME has no meaning. .PP The 'lens' grandchild of \f(CW\*(C`/augeas/load\*(C'\fR specifies which lens to use, and can either be the fully qualified name of a lens 'Module.lens' or \&'\f(CW@Module\fR'. The latter form means that the lens from the transform marked for autoloading in \f(CW\*(C`MODULE\*(C'\fR should be used. .PP The 'incl' and 'excl' grandchildren of \f(CW\*(C`/augeas/load\*(C'\fR indicate which files to transform. Their value are used as glob patterns. Any file that matches at least one 'incl' pattern and no 'excl' pattern is transformed. The order of 'incl' and 'excl' entries is irrelevant. .PP When init is first called, it populates \f(CW\*(C`/augeas/load\*(C'\fR with the transforms marked for autoloading in all the modules it finds. .PP Before loading any files, \f(CW\*(C`load\*(C'\fR will remove everything underneath \&\f(CW\*(C`/augeas/files\*(C'\fR and \f(CW\*(C`/files\*(C'\fR, regardless of whether any entries have been modified or not. .PP Returns 0 on error, 1 on success. Note that success includes the case where some files could not be loaded. Details of such files can be found as '\f(CW\*(C`/augeas//error\*(C'\fR'. .SS "print ( [ path , [ file ] ] )" .IX Subsection "print ( [ path , [ file ] ] )" Print each node matching \f(CW\*(C`path\*(C'\fR and its descendants on STDOUT or in a file .PP The second parameter can be : .IP \(bu 4 A file name. .IP \(bu 4 Omitted. In this case, print to STDOUT .PP If path is omitted, all Augeas nodes will be printed. .PP Example: .PP .Vb 3 \& $aug\->print ; # print all nodes to STDOUT \& $aug\->print(\*(Aq/files\*(Aq) ; # print all file nodes to STDOUT \& $aug\->print(\*(Aq/augeas/\*(Aq,\*(Aqbar.txt\*(Aq); # print Augeas meta data in bar.txt .Ve .PP WARNING: The parameter order is reversed compared to Augeas C API. .SS "srun ( [ text , [ file ] ] )" .IX Subsection "srun ( [ text , [ file ] ] )" Run one or more newline-separated commands listed in \f(CW\*(C`text\*(C'\fR. Running just \f(CW\*(C`help\*(C'\fR will print what commands are available. Commands accepted by this are identical to what augtool accepts. .PP The second parameter can be : .IP \(bu 4 A file name. .IP \(bu 4 Omitted. In this case, print to STDOUT .PP The function returns the number of executed commands on success, and 0 otherwise. .SH "Error reporting" .IX Header "Error reporting" .SS error .IX Subsection "error" Returns the error code from the last API call as a short string: noerror, nomem, internal, pathx, nomatch, manymatch, syntax, nolens, multiple_transforms .SS error_message .IX Subsection "error_message" Return a human-readable message for the error code. .SS error_minor_message .IX Subsection "error_minor_message" Return a human-readable message elaborating the error code; might be undef. For example, when the error code is \f(CW\*(C`pathx\*(C'\fR, this will explain how the path expression is invalid. .SS error_details .IX Subsection "error_details" Return details about the error, which might be undef. For example, for \&\f(CW\*(C`pathx\*(C'\fR, indicates where in the path expression the error occurred. The returned value can only be used until the next API call .SH CAVEATS .IX Header "CAVEATS" Object oriented design would suggest to use a new class to represent Augeas errors, but this would stray too far from current Augeas design and API. .SH "SEE ALSO" .IX Header "SEE ALSO" .IP \(bu 4 http://augeas.net/ : Augeas project page .IP \(bu 4 Config::Model : Another kind of configuration editor (with optional GUI and advanced validation). .IP \(bu 4 Config::Augeas::Validator : A unit test framework for configuration files. .IP \(bu 4 Config::Augeas::Exporter : A module to export the Augeas tree to various formats. .IP \(bu 4 Augeas mailing list: http://augeas.net/developers.html .IP \(bu 4 Source repository: https://github.com/raphink/config\-augeas .SH AUTHORS .IX Header "AUTHORS" .IP \(bu 4 Dominique Dumont, .IP \(bu 4 Raphael Pinson, .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" .IP \(bu 4 Copyright (C) 2008\-2010 by Dominique Dumont .IP \(bu 4 Copyright (C) 2011\-2012 by Raphael Pinson .PP This library is free software; you can redistribute it and/or modify it under the LGPL terms.