diff --git a/files/concatfragments.sh b/files/concatfragments.sh index 771655c..570d553 100755 --- a/files/concatfragments.sh +++ b/files/concatfragments.sh @@ -44,6 +44,7 @@ TEST="" FORCE="" WARN="" SORTARG="" +ENSURE_NEWLINE="" PATH=/sbin:/usr/sbin:/bin:/usr/bin @@ -51,7 +52,7 @@ PATH=/sbin:/usr/sbin:/bin:/usr/bin ## http://nexenta.org/projects/site/wiki/Personalities unset SUN_PERSONALITY -while getopts "o:s:d:tnw:f" options; do +while getopts "o:s:d:tnw:fl" options; do case $options in o ) OUTFILE=$OPTARG;; d ) WORKDIR=$OPTARG;; @@ -59,6 +60,7 @@ while getopts "o:s:d:tnw:f" options; do w ) WARNMSG="$OPTARG";; f ) FORCE="true";; t ) TEST="true";; + l ) ENSURE_NEWLINE="true";; * ) echo "Specify output file with -o and fragments directory with -d" exit 1;; esac @@ -111,6 +113,10 @@ else printf '%s\n' "$WARNMSG" > "fragments.concat" fi +if [ x${ENSURE_NEWLINE} != x ]; then + find fragments/ -type f -follow -print0 | xargs -0 -I '{}' sh -c 'if [ -n "$(tail -c 1 < {} )" ]; then echo >> {} ; fi' +fi + # find all the files in the fragments directory, sort them numerically and concat to fragments.concat in the working dir IFS_BACKUP=$IFS IFS=' diff --git a/manifests/init.pp b/manifests/init.pp index cba8223..ed4068b 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -55,7 +55,8 @@ define concat( $backup = 'puppet', $replace = true, $gnu = undef, - $order='alpha' + $order='alpha', + $ensure_newline = false ) { include concat::setup @@ -108,6 +109,18 @@ define concat( } } + case $ensure_newline { + 'true', true, yes, on: { + $newlineflag = '-l' + } + 'false', false, no, off: { + $newlineflag = '' + } + default: { + fail("Improper 'ensure_newline' value given to concat: ${ensure_newline}") + } + } + File { owner => $::id, group => $group, @@ -155,7 +168,7 @@ define concat( exec { "concat_${name}": alias => "concat_${fragdir}", - command => "${concat::setup::concatdir}/bin/concatfragments.sh -o ${fragdir}/${concat_name} -d ${fragdir} ${warnflag} ${forceflag} ${orderflag}", + command => "${concat::setup::concatdir}/bin/concatfragments.sh -o ${fragdir}/${concat_name} -d ${fragdir} ${warnflag} ${forceflag} ${orderflag} ${newlineflag}", notify => File[$name], require => [ File[$fragdir], @@ -163,7 +176,7 @@ define concat( File["${fragdir}/fragments.concat"], ], subscribe => File[$fragdir], - unless => "${concat::setup::concatdir}/bin/concatfragments.sh -o ${fragdir}/${concat_name} -d ${fragdir} -t ${warnflag} ${forceflag} ${orderflag}", + unless => "${concat::setup::concatdir}/bin/concatfragments.sh -o ${fragdir}/${concat_name} -d ${fragdir} -t ${warnflag} ${forceflag} ${orderflag} ${newlineflag}", } if $::id == 'root' { diff --git a/spec/defines/init_spec.rb b/spec/defines/init_spec.rb index 172929a..ace50f0 100644 --- a/spec/defines/init_spec.rb +++ b/spec/defines/init_spec.rb @@ -49,7 +49,7 @@ describe 'concat' do should contain_exec("concat_/etc/foo.bar").with_command( "#{basedir}/bin/concatfragments.sh " + "-o #{basedir}/_etc_foo.bar/fragments.concat.out " + - "-d #{basedir}/_etc_foo.bar " + "-d #{basedir}/_etc_foo.bar " ) end end @@ -105,7 +105,7 @@ describe 'concat' do should contain_exec("concat_foobar").with_command( "#{basedir}/bin/concatfragments.sh " + "-o #{basedir}/foobar/fragments.concat.out " + - "-d #{basedir}/foobar " + "-d #{basedir}/foobar " ) end