diff options
-rwxr-xr-x | files/concatfragments.sh | 17 | ||||
-rw-r--r-- | manifests/init.pp | 34 |
2 files changed, 20 insertions, 31 deletions
diff --git a/files/concatfragments.sh b/files/concatfragments.sh index a761b7e..c939797 100755 --- a/files/concatfragments.sh +++ b/files/concatfragments.sh @@ -26,7 +26,6 @@ # is generated by puppet # -f Enables the creation of empty output files when no fragments are found # -n Sort the output numerically rather than the default alpha sort -# -g Do NOT use the GNU entensions to find, xargs and sort; might cause problems on suitably funky filenames # # the command: # @@ -44,10 +43,7 @@ WORKDIR="" TEST="" FORCE="" WARN="" -SORT1="-z" -SORT2="" -FINDARG="-print0" -XARGSARG="-0" +SORTARG="" PATH=/sbin:/usr/sbin:/bin:/usr/bin @@ -55,22 +51,19 @@ PATH=/sbin:/usr/sbin:/bin:/usr/bin ## http://nexenta.org/projects/site/wiki/Personalities unset SUN_PERSONALITY -while getopts "o:s:d:tnw:fg" options; do +while getopts "o:s:d:tnw:f" options; do case $options in o ) OUTFILE=$OPTARG;; d ) WORKDIR=$OPTARG;; - n ) SORT2="-n";; + n ) SORTARG="-n";; w ) WARNMSG="$OPTARG";; f ) FORCE="true";; t ) TEST="true";; - g ) FINDARG="" ; XARGSARG="" ; SORT1="" ;; * ) echo "Specify output file with -o and fragments directory with -d" exit 1;; esac done -SORTARG="$SORT1 $SORT2" - # do we have -o? if [ x${OUTFILE} = "x" ]; then echo "Please specify an output file with -o" @@ -119,7 +112,9 @@ else fi # find all the files in the fragments directory, sort them numerically and concat to fragments.concat in the working dir -find fragments/ -type f -follow $FINDARG |sort ${SORTARG}|xargs $XARGSARG cat >>"fragments.concat" +find fragments/ -type f -follow | sort ${SORTARG} | while read fragfile; do + cat "$fragfile" >> "fragments.concat" +done if [ x${TEST} = "x" ]; then # This is a real run, copy the file to outfile diff --git a/manifests/init.pp b/manifests/init.pp index f1fbc9f..1e6aee0 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,13 +1,13 @@ # A system to construct files using fragments from other files or templates. # -# This requires at least puppet 0.25 to work correctly as we use some +# This requires at least puppet 0.25 to work correctly as we use some # enhancements in recursive directory management and regular expressions # to do the work here. # # USAGE: # The basic use case is as below: # -# concat{"/etc/named.conf": +# concat{"/etc/named.conf": # notify => Service["named"] # } # @@ -17,7 +17,7 @@ # content => template("named_conf_zone.erb") # } # -# # add a fragment not managed by puppet so local users +# # add a fragment not managed by puppet so local users # # can add content to managed file # concat::fragment{"foo.com_user_config": # target => "/etc/named.conf", @@ -25,7 +25,7 @@ # ensure => "/etc/named.conf.local" # } # -# This will use the template named_conf_zone.erb to build a single +# This will use the template named_conf_zone.erb to build a single # bit of config up and put it into the fragments dir. The file # will have an number prefix of 10, you can use the order option # to control that and thus control the order the final file gets built in. @@ -39,7 +39,7 @@ # There's some regular expression magic to figure out the puppet version but # if you're on an older 0.24 version just set $puppetversion = 24 # -# Before you can use any of the concat features you should include the +# Before you can use any of the concat features you should include the # class concat::setup somewhere on your node first. # # DETAIL: @@ -48,7 +48,7 @@ # seem more complex than some of the one-liner alternatives you might find on # the net we do a lot of error checking and safety checks in the script to avoid # problems that might be caused by complex escaping errors etc. -# +# # LICENSE: # Apache Version 2 # @@ -56,13 +56,13 @@ # http://github.com/ripienaar/puppet-concat/ # # CONTACT: -# R.I.Pienaar <rip@devco.net> +# R.I.Pienaar <rip@devco.net> # Volcane on freenode # @ripienaar on twitter # www.devco.net -# Sets up so that you can use fragments to build a final config file, +# Sets up so that you can use fragments to build a final config file, # # OPTIONS: # - mode The mode of the final file @@ -78,16 +78,16 @@ # - Creates fragment directories if it didn't exist already # - Executes the concatfragments.sh script to build the final file, this script will create # directory/fragments.concat. Execution happens only when: -# * The directory changes -# * fragments.concat != final destination, this means rebuilds will happen whenever +# * The directory changes +# * fragments.concat != final destination, this means rebuilds will happen whenever # someone changes or deletes the final file. Checking is done using /usr/bin/cmp. # * The Exec gets notified by something else - like the concat::fragment define # - Copies the file over to the final destination using a file resource # # ALIASES: # - The exec can notified using Exec["concat_/path/to/file"] or Exec["concat_/path/to/directory"] -# - The final file can be referened as File["/path/to/file"] or File["concat_/path/to/file"] -define concat($mode = 0644, $owner = $::id, $group = $concat::setup::root_group, $warn = "false", $force = "false", $backup = "puppet", $gnu = "true", $order="alpha") { +# - The final file can be referened as File["/path/to/file"] or File["concat_/path/to/file"] +define concat($mode = 0644, $owner = $::id, $group = $concat::setup::root_group, $warn = "false", $force = "false", $backup = "puppet", $gnu = undef, $order="alpha") { $safe_name = regsubst($name, '/', '_', 'G') $concatdir = $concat::setup::concatdir $version = $concat::setup::majorversion @@ -113,12 +113,6 @@ define concat($mode = 0644, $owner = $::id, $group = $concat::setup::root_group, default: { fail("Improper 'force' value given to concat: $force") } } - case $gnu { - 'true',true,yes,on: { $gnuflag = "" } - 'false',false,no,off: { $gnuflag = "-g" } - default: { fail("Improper 'gnu' value given to concat: $gnu") } - } - case $order { numeric: { $orderflag = "-n" } alpha: { $orderflag = "" } @@ -168,8 +162,8 @@ define concat($mode = 0644, $owner = $::id, $group = $concat::setup::root_group, subscribe => File[$fragdir], alias => "concat_${fragdir}", require => [ File[$fragdir], File["${fragdir}/fragments"], File["${fragdir}/fragments.concat"] ], - unless => "${concat::setup::concatdir}/bin/concatfragments.sh -o ${fragdir}/${concat_name} -d ${fragdir} -t ${warnflag} ${forceflag} ${orderflag} ${gnuflag}", - command => "${concat::setup::concatdir}/bin/concatfragments.sh -o ${fragdir}/${concat_name} -d ${fragdir} ${warnflag} ${forceflag} ${orderflag} ${gnuflag}", + unless => "${concat::setup::concatdir}/bin/concatfragments.sh -o ${fragdir}/${concat_name} -d ${fragdir} -t ${warnflag} ${forceflag} ${orderflag}", + command => "${concat::setup::concatdir}/bin/concatfragments.sh -o ${fragdir}/${concat_name} -d ${fragdir} ${warnflag} ${forceflag} ${orderflag}", } if $::id == 'root' { Exec["concat_${name}"]{ |