Ability to control if fragments should always have a newline at the end.
This commit is contained in:
parent
0046fe45f8
commit
3defb6e1c1
2 changed files with 22 additions and 3 deletions
|
@ -44,6 +44,7 @@ TEST=""
|
|||
FORCE=""
|
||||
WARN=""
|
||||
SORTARG=""
|
||||
ENSURE_NEW_LINE=""
|
||||
|
||||
PATH=/sbin:/usr/sbin:/bin:/usr/bin
|
||||
|
||||
|
@ -59,6 +60,7 @@ while getopts "o:s:d:tnw:f" options; do
|
|||
w ) WARNMSG="$OPTARG";;
|
||||
f ) FORCE="true";;
|
||||
t ) TEST="true";;
|
||||
l ) ENSURE_NEW_LINE="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_NEW_LINE} != 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='
|
||||
|
|
|
@ -55,7 +55,8 @@ define concat(
|
|||
$backup = 'puppet',
|
||||
$replace = true,
|
||||
$gnu = undef,
|
||||
$order='alpha'
|
||||
$order='alpha',
|
||||
$ensure_new_line = false
|
||||
) {
|
||||
include concat::setup
|
||||
|
||||
|
@ -108,6 +109,18 @@ define concat(
|
|||
}
|
||||
}
|
||||
|
||||
case $ensure_new_line {
|
||||
'true', true, yes, on: {
|
||||
$newlineflag = '-l'
|
||||
}
|
||||
'false', false, no, off: {
|
||||
$newlineflag = ''
|
||||
}
|
||||
default: {
|
||||
fail("Improper 'ensure_new_line' value given to concat: ${ensure_new_line}")
|
||||
}
|
||||
}
|
||||
|
||||
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' {
|
||||
|
|
Loading…
Reference in a new issue