.\" -*- 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 "AUGPRINT 1" .TH AUGPRINT 1 2023-07-14 "Augeas 1.14.1" Augeas .\" 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 augprint \- create an idempotent augtool script for a given file .SH SYNOPSIS .IX Header "SYNOPSIS" augprint [\-\-pretty|\-p] [\-\-regexp[=n]|\-r[n]] [\-\-noseq|\-s] [\-\-verbose|\-v] [\-\-lens name|\-l name] [\-\-target /target|\-t /target] FILE .SH DESCRIPTION .IX Header "DESCRIPTION" \&\fBaugprint\fR creates an augtool script for a given \fBFILE\fR consisting primarily of \f(CW\*(C`set\*(C'\fR commands. .PP The resulting augtool script is designed to be idempotent, and will not result in any changes when applied to the original file. .PP \&\fBaugprint\fR replaces each numbered location in the tree with a path-expression that uniquely identifies the position using the values \&\fIwithin\fR that position. .PP This makes the path-expression independant of the position-number, and thereby applicable to files which in which the same data may exist at an alternate position-number .PP See "Examples" for sample output .SS "Regexp output" .IX Subsection "Regexp output" By default \fBaugprint\fR produces path-expressions made up of simple equality \f(CW\*(C`=\*(C'\fR comparisions .PP .Vb 1 \& set /files/etc/hosts/seq::*[ipaddr=\*(Aq127.0.0.1\*(Aq]/ipaddr \*(Aq127.0.0.1\*(Aq .Ve .PP The option \fB\-\-regexp\fR changes the output to produce regular expression comparisions .PP .Vb 1 \& set /files/etc/hosts/seq::*[ipaddr=~regexp(\*(Aq127\e\e.0\e\e..*\*(Aq)]/ipaddr \*(Aq127.0.0.1\*(Aq .Ve .PP The minimum length \fIN\fR of the regular expression can be specified using \f(CW\*(C`\-\-regexp=N\*(C'\fR .PP \&\fBaugprint\fR will choose a longer regular expression than \fIN\fR if multiple values would match using the \fIN\fR character regular expression. .SS Limitations .IX Subsection "Limitations" \fIAppend-only\fR .IX Subsection "Append-only" .PP The output is based primarily on set operations. The set operation can only: .PP a) change an existing value in-situ .PP b) append a new value after the last position in the group .PP This means that when an entry is re-created, it may not be in the same position as originally intended. ie if the entry for \f(CW192.0.2.3\fR does not already exist, it will be created as the \fIlast\fR entry in \fI/etc/hosts\fR .PP Often, such out-of-sequence entries will not matter to the resulting configuration file. If it does matter, further manual editing of the \f(CW\*(C`augtool\*(C'\fR script will be required. .PP \fIRepeated Values\fR .IX Subsection "Repeated Values" .PP \&\fBaugprint\fR is not always successful in finding a path-expression which is unique to a position. In this case \fBaugprint\fR appends a position to an expression which is not unique .PP This occurs in particular if there are repeated values within the file. .PP For an \fI/etc/hosts\fR file of .PP .Vb 3 \& #\-\-\-\-\-\- \& 192.0.2.3 defaultdns \& #\-\-\-\-\-\- .Ve .PP \&\fBaugprint\fR would produce the output .PP .Vb 4 \& set /files/etc/hosts/#comment[.=\*(Aq\-\-\-\-\-\-\-\-\*(Aq][1] \*(Aq\-\-\-\-\-\-\-\-\*(Aq \& set /files/etc/hosts/seq::*[ipaddr=\*(Aq192.0.2.3\*(Aq]/ipaddr \*(Aq192.0.2.3\*(Aq \& set /files/etc/hosts/seq::*[ipaddr=\*(Aq192.0.2.3\*(Aq]/canonical \*(Aqdefaultdns\*(Aq \& set /files/etc/hosts/#comment[.=\*(Aq\-\-\-\-\-\-\-\-\*(Aq][2] \*(Aq\-\-\-\-\-\-\-\-\*(Aq .Ve .PP Notice how \f(CW\*(C`#comment\*(C'\fR paths have \f(CW\*(C`[1]\*(C'\fR and \f(CW\*(C`[2]\*(C'\fR appended respectively to the \f(CW\*(C`[expr]\*(C'\fR .PP Other paths which do have unique path-expressions are not directly affected .SH OPTIONS .IX Header "OPTIONS" .IP "\fB\-v\fR, \fB\-\-verbose\fR" 4 .IX Item "-v, --verbose" Include the original numbered paths as comments in the output .IP "\fB\-p\fR, \fB\-\-pretty\fR" 4 .IX Item "-p, --pretty" Create more readable output by adding spaces and empty lines .IP "\fB\-r\fR, \fB\-r\fR\fIN\fR, \fB\-\-regexp\fR, \fB\-\-regexp\fR=\fIN\fR" 4 .IX Item "-r, -rN, --regexp, --regexp=N" Generate regular expressions to match values, using a minumum length of \fIN\fR characters from the value .Sp \&\fIN\fR can be omitted and defaults to 8 .IP "\fB\-l\fR, \fB\-\-lens\fR=\fILENS\fR" 4 .IX Item "-l, --lens=LENS" Use \fILENS\fR for the given file; without this option, \fBaugprint\fR uses the default lens for the file .IP "\fB\-t\fR \fItargetfile\fR, \fB\-\-target\fR=\fItargetfile\fR" 4 .IX Item "-t targetfile, --target=targetfile" Generate the script for the \fIFILE\fR specified as if its path was really \fItargetfile\fR .Sp This will apply the lens corresponding to \fItargetfile\fR to \fIFILE\fR and modifying the resulting path-expressions of \fIFILE\fR to correspond to \fItargetfile\fR .Sp \&\fItargetfile\fR must be the full path name, starting with a '/' .Sp See "Examples" for how \fB\-\-target\fR can be used in practice .IP "\fB\-s\fR, \fB\-\-noseq\fR" 4 .IX Item "-s, --noseq" Do not use \f(CW\*(C`seq::*\*(C'\fR in the output, use \f(CW\*(C`*\*(C'\fR instead. For example .Sp .Vb 1 \& set /files/etc/hosts/*[ipaddr=\*(Aq127.0.0.1\*(Aq]/ipaddr \*(Aq127.0.0.1\*(Aq .Ve .Sp IMPORTANT: The resulting output will no longer \fIcreate\fR a new entry for \f(CW127.0.0.1\fR if none already exists. The \f(CW\*(C`\-\-noseq\*(C'\fR option exists so that the resulting paths can be used with augeas versions prior to 1.13.0 (subject to this limitation) .SH EXAMPLES .IX Header "EXAMPLES" These examples use the following \fI/etc/hosts\fR file as the \fIFILE\fR .PP .Vb 3 \& 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 \& 192.0.2.3 dns\-a \& 192.0.2.4 dns\-b .Ve .PP The output from \f(CW\*(C`augtool \*(Aqprint /files/etc/hosts\*(Aq\*(C'\fR would be .PP .Vb 10 \& /files/etc/hosts \& /files/etc/hosts/1 \& /files/etc/hosts/1/ipaddr = "127.0.0.1" \& /files/etc/hosts/1/canonical = "localhost" \& /files/etc/hosts/1/alias[1] = "localhost.localdomain" \& /files/etc/hosts/1/alias[2] = "localhost4" \& /files/etc/hosts/1/alias[3] = "localhost4.localdomain4" \& /files/etc/hosts/2 \& /files/etc/hosts/2/ipaddr = "192.0.2.3" \& /files/etc/hosts/2/canonical = "dns\-a" \& /files/etc/hosts/3 \& /files/etc/hosts/3/ipaddr = "192.0.2.4" \& /files/etc/hosts/3/canonical = "dns\-b" .Ve .SS "Default output" .IX Subsection "Default output" \&\f(CW\*(C`augprint /etc/hosts\*(C'\fR .PP .Vb 9 \& set /files/etc/hosts/seq::*[ipaddr=\*(Aq127.0.0.1\*(Aq]/ipaddr \*(Aq127.0.0.1\*(Aq \& set /files/etc/hosts/seq::*[ipaddr=\*(Aq127.0.0.1\*(Aq]/canonical \*(Aqlocalhost\*(Aq \& set /files/etc/hosts/seq::*[ipaddr=\*(Aq127.0.0.1\*(Aq]/alias[.=\*(Aqlocalhost.localdomain\*(Aq] \*(Aqlocalhost.localdomain\*(Aq \& set /files/etc/hosts/seq::*[ipaddr=\*(Aq127.0.0.1\*(Aq]/alias[.=\*(Aqlocalhost4\*(Aq] \*(Aqlocalhost4\*(Aq \& set /files/etc/hosts/seq::*[ipaddr=\*(Aq127.0.0.1\*(Aq]/alias[.=\*(Aqlocalhost4.localdomain4\*(Aq] \*(Aqlocalhost4.localdomain4\*(Aq \& set /files/etc/hosts/seq::*[ipaddr=\*(Aq192.0.2.3\*(Aq]/ipaddr \*(Aq192.0.2.3\*(Aq \& set /files/etc/hosts/seq::*[ipaddr=\*(Aq192.0.2.3\*(Aq]/canonical \*(Aqdns\-a\*(Aq \& set /files/etc/hosts/seq::*[ipaddr=\*(Aq192.0.2.4\*(Aq]/ipaddr \*(Aq192.0.2.4\*(Aq \& set /files/etc/hosts/seq::*[ipaddr=\*(Aq192.0.2.4\*(Aq]/canonical \*(Aqdns\-b\*(Aq .Ve .SS "Verbose output" .IX Subsection "Verbose output" \&\f(CW\*(C`augprint \-\-verbose /etc/hosts\*(C'\fR .PP .Vb 9 \& # /files/etc/hosts \& # /files/etc/hosts/1 \& # /files/etc/hosts/1/ipaddr \*(Aq127.0.0.1\*(Aq \& set /files/etc/hosts/seq::*[ipaddr=\*(Aq127.0.0.1\*(Aq]/ipaddr \*(Aq127.0.0.1\*(Aq \& # /files/etc/hosts/1/canonical \*(Aqlocalhost\*(Aq \& set /files/etc/hosts/seq::*[ipaddr=\*(Aq127.0.0.1\*(Aq]/canonical \*(Aqlocalhost\*(Aq \& # /files/etc/hosts/1/alias[1] \*(Aqlocalhost.localdomain\*(Aq \& set /files/etc/hosts/seq::*[ipaddr=\*(Aq127.0.0.1\*(Aq]/alias[.=\*(Aqlocalhost.localdomain\*(Aq] \*(Aqlocalhost.localdomain\*(Aq \& ... .Ve .SS "Rexexp output" .IX Subsection "Rexexp output" \&\f(CW\*(C`augprint \-\-regexp=4 /etc/hosts\*(C'\fR .PP .Vb 9 \& set /files/etc/hosts/seq::*[ipaddr=~regexp(\*(Aq127\e\e..*\*(Aq)]/ipaddr \*(Aq127.0.0.1\*(Aq \& set /files/etc/hosts/seq::*[ipaddr=~regexp(\*(Aq127\e\e..*\*(Aq)]/canonical \*(Aqlocalhost\*(Aq \& set /files/etc/hosts/seq::*[ipaddr=~regexp(\*(Aq127\e\e..*\*(Aq)]/alias[.=~regexp(\*(Aqlocalhost\e\e..*\*(Aq)] \*(Aqlocalhost.localdomain\*(Aq \& set /files/etc/hosts/seq::*[ipaddr=~regexp(\*(Aq127\e\e..*\*(Aq)]/alias[.=~regexp(\*(Aqlocalhost4\*(Aq)] \*(Aqlocalhost4\*(Aq \& set /files/etc/hosts/seq::*[ipaddr=~regexp(\*(Aq127\e\e..*\*(Aq)]/alias[.=~regexp(\*(Aqlocalhost4\e\e..*\*(Aq)] \*(Aqlocalhost4.localdomain4\*(Aq \& set /files/etc/hosts/seq::*[ipaddr=~regexp(\*(Aq192\e\e.0\e\e.2\e\e.3\*(Aq)]/ipaddr \*(Aq192.0.2.3\*(Aq \& set /files/etc/hosts/seq::*[ipaddr=~regexp(\*(Aq192\e\e.0\e\e.2\e\e.3\*(Aq)]/canonical \*(Aqdns\-a\*(Aq \& set /files/etc/hosts/seq::*[ipaddr=~regexp(\*(Aq192\e\e.0\e\e.2\e\e.4\*(Aq)]/ipaddr \*(Aq192.0.2.4\*(Aq \& set /files/etc/hosts/seq::*[ipaddr=~regexp(\*(Aq192\e\e.0\e\e.2\e\e.4\*(Aq)]/canonical \*(Aqdns\-b\*(Aq .Ve .PP Note that although a \fIminimum\fR length of 4 has been specified, \fBaugprint\fR will choose longer regular expressions as needed to ensure a unique match. .SS "Using \-\-lens" .IX Subsection "Using --lens" If a file is not assocatiated with a lens by default, \fI\-\-lens lensname\fR can be used to specify a lens. .PP When \fI\-\-lens\fR is specified, the output is prefixed with suitable \f(CW\*(C`transform\*(C'\fR and \f(CW\*(C`load\-file\*(C'\fR statements, as required to complete the augtool script, and a \fIsetm\fR statement to exclude other autoloaded lenses. .PP \&\f(CW\*(C`augprint \-\-lens shellvars /etc/skel/.bashrc\*(C'\fR .PP .Vb 9 \& setm /augeas/load/*[incl=\*(Aq/etc/skel/.bashrc\*(Aq and label() != \*(Aqshellvars\*(Aq]/excl \*(Aq/etc/skel/.bashrc\*(Aq \& transform shellvars incl /etc/skel/.bashrc \& load\-file /etc/skel/.bashrc \& set /files/etc/skel/.bashrc/#comment[.=\*(Aq.bashrc\*(Aq] \*(Aq.bashrc\*(Aq \& set /files/etc/skel/.bashrc/#comment[.=\*(AqSource global definitions\*(Aq] \*(AqSource global definitions\*(Aq \& set /files/etc/skel/.bashrc/@if[.=\*(Aq[ \-f /etc/bashrc ]\*(Aq] \*(Aq[ \-f /etc/bashrc ]\*(Aq \& set /files/etc/skel/.bashrc/@if[.=\*(Aq[ \-f /etc/bashrc ]\*(Aq]/.source \*(Aq/etc/bashrc\*(Aq \& set /files/etc/skel/.bashrc/#comment[.=\*(AqUser specific environment\*(Aq] \*(AqUser specific environment\*(Aq \& ... .Ve .PP The lenses \f(CW\*(C`simplelines\*(C'\fR \f(CW\*(C`shellvars\*(C'\fR are most commonly useful as lenses for files that do not have a specific lens .SS "Using \-\-target" .IX Subsection "Using --target" In order to prepare an augtool script intended for a given file, it may be desired to copy the file to another location, rather than editting the original file. .PP The option \fI\-\-target\fR simplifies this process. .PP a) copy \fI/etc/hosts\fR to a new location .PP .Vb 1 \& cp /etc/hosts ~ .Ve .PP b) edit \fI~/hosts\fR to suit .PP .Vb 1 \& echo \*(Aq192.0.2.7 defaultdns\*(Aq >> ~/hosts .Ve .PP c) Run \f(CW\*(C`augprint\*(C'\fR as follows .PP .Vb 1 \& augprint \-\-target /etc/hosts ~/hosts .Ve .PP d) Copy the relevant part of the output to an augtool script or other Augeas client .PP .Vb 2 \& set /files/etc/hosts/seq::*[ipaddr=\*(Aq192.0.2.7\*(Aq]/ipaddr \*(Aq192.0.2.7\*(Aq \& set /files/etc/hosts/seq::*[ipaddr=\*(Aq192.0.2.7\*(Aq]/canonical \*(Aqdefaultdns\*(Aq .Ve .PP Notice that \f(CW\*(C`augprint\*(C'\fR has generated paths corresponding to \fI\-\-target\fR (/etc/hosts) instead of the \fIFILE\fR argument (~/hosts) .SH "ENVIRONMENT VARIABLES" .IX Header "ENVIRONMENT VARIABLES" .IP \fBAUGEAS_ROOT\fR 4 .IX Item "AUGEAS_ROOT" The effective file system root, defaults to '/'. .IP \fBAUGEAS_LENS_LIB\fR 4 .IX Item "AUGEAS_LENS_LIB" Colon separated list of directories with lenses. Directories specified here are searched before the default directories \fI/usr/share/augeas/lenses\fR and \&\fI/usr/share/augeas/lenses/dist\fR .SH "EXIT STATUS" .IX Header "EXIT STATUS" The exit status is 0 when the command was successful and 1 if any error occurred. .SH FILES .IX Header "FILES" Lenses and schema definitions in \fI/usr/share/augeas/lenses\fR and \&\fI/usr/share/augeas/lenses/dist\fR .SH AUTHOR .IX Header "AUTHOR" George Hansper .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright 2022 George Hansper .PP Augeas (and augprint) are distributed under the GNU Lesser General Public License (LGPL), version 2.1 .SH "SEE ALSO" .IX Header "SEE ALSO" \&\fBaugtool\fR\|(1) .PP \&\fBAugeas\fR project homepage .PP \&\fBAugeas\fR path expressions