Merge pull request #61 from hubspotdevops/newline_upstream

add ensure_newline
This commit is contained in:
Ashley Penney 2013-08-09 08:44:18 -07:00
commit 7313d26007
3 changed files with 25 additions and 6 deletions

View file

@ -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='

View file

@ -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' {

View file

@ -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