Skip to content

Commit b4a80d4

Browse files
committed
Merge pull request #17 from pdxcat/refactor_remove_gnuflag
Remove the gnu parameter from concat
2 parents 30c9628 + 81d5ee8 commit b4a80d4

File tree

2 files changed

+20
-31
lines changed

2 files changed

+20
-31
lines changed

files/concatfragments.sh

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
# is generated by puppet
2727
# -f Enables the creation of empty output files when no fragments are found
2828
# -n Sort the output numerically rather than the default alpha sort
29-
# -g Do NOT use the GNU entensions to find, xargs and sort; might cause problems on suitably funky filenames
3029
#
3130
# the command:
3231
#
@@ -44,33 +43,27 @@ WORKDIR=""
4443
TEST=""
4544
FORCE=""
4645
WARN=""
47-
SORT1="-z"
48-
SORT2=""
49-
FINDARG="-print0"
50-
XARGSARG="-0"
46+
SORTARG=""
5147

5248
PATH=/sbin:/usr/sbin:/bin:/usr/bin
5349

5450
## Well, if there's ever a bad way to do things, Nexenta has it.
5551
## http://nexenta.org/projects/site/wiki/Personalities
5652
unset SUN_PERSONALITY
5753

58-
while getopts "o:s:d:tnw:fg" options; do
54+
while getopts "o:s:d:tnw:f" options; do
5955
case $options in
6056
o ) OUTFILE=$OPTARG;;
6157
d ) WORKDIR=$OPTARG;;
62-
n ) SORT2="-n";;
58+
n ) SORTARG="-n";;
6359
w ) WARNMSG="$OPTARG";;
6460
f ) FORCE="true";;
6561
t ) TEST="true";;
66-
g ) FINDARG="" ; XARGSARG="" ; SORT1="" ;;
6762
* ) echo "Specify output file with -o and fragments directory with -d"
6863
exit 1;;
6964
esac
7065
done
7166

72-
SORTARG="$SORT1 $SORT2"
73-
7467
# do we have -o?
7568
if [ x${OUTFILE} = "x" ]; then
7669
echo "Please specify an output file with -o"
@@ -119,7 +112,9 @@ else
119112
fi
120113

121114
# find all the files in the fragments directory, sort them numerically and concat to fragments.concat in the working dir
122-
find fragments/ -type f -follow $FINDARG |sort ${SORTARG}|xargs $XARGSARG cat >>"fragments.concat"
115+
find fragments/ -type f -follow | sort ${SORTARG} | while read fragfile; do
116+
cat "$fragfile" >> "fragments.concat"
117+
done
123118

124119
if [ x${TEST} = "x" ]; then
125120
# This is a real run, copy the file to outfile

manifests/init.pp

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# A system to construct files using fragments from other files or templates.
22
#
3-
# This requires at least puppet 0.25 to work correctly as we use some
3+
# This requires at least puppet 0.25 to work correctly as we use some
44
# enhancements in recursive directory management and regular expressions
55
# to do the work here.
66
#
77
# USAGE:
88
# The basic use case is as below:
99
#
10-
# concat{"/etc/named.conf":
10+
# concat{"/etc/named.conf":
1111
# notify => Service["named"]
1212
# }
1313
#
@@ -17,15 +17,15 @@
1717
# content => template("named_conf_zone.erb")
1818
# }
1919
#
20-
# # add a fragment not managed by puppet so local users
20+
# # add a fragment not managed by puppet so local users
2121
# # can add content to managed file
2222
# concat::fragment{"foo.com_user_config":
2323
# target => "/etc/named.conf",
2424
# order => 12,
2525
# ensure => "/etc/named.conf.local"
2626
# }
2727
#
28-
# This will use the template named_conf_zone.erb to build a single
28+
# This will use the template named_conf_zone.erb to build a single
2929
# bit of config up and put it into the fragments dir. The file
3030
# will have an number prefix of 10, you can use the order option
3131
# to control that and thus control the order the final file gets built in.
@@ -39,7 +39,7 @@
3939
# There's some regular expression magic to figure out the puppet version but
4040
# if you're on an older 0.24 version just set $puppetversion = 24
4141
#
42-
# Before you can use any of the concat features you should include the
42+
# Before you can use any of the concat features you should include the
4343
# class concat::setup somewhere on your node first.
4444
#
4545
# DETAIL:
@@ -48,21 +48,21 @@
4848
# seem more complex than some of the one-liner alternatives you might find on
4949
# the net we do a lot of error checking and safety checks in the script to avoid
5050
# problems that might be caused by complex escaping errors etc.
51-
#
51+
#
5252
# LICENSE:
5353
# Apache Version 2
5454
#
5555
# LATEST:
5656
# http://github.com/ripienaar/puppet-concat/
5757
#
5858
# CONTACT:
59-
# R.I.Pienaar <rip@devco.net>
59+
# R.I.Pienaar <rip@devco.net>
6060
# Volcane on freenode
6161
# @ripienaar on twitter
6262
# www.devco.net
6363

6464

65-
# Sets up so that you can use fragments to build a final config file,
65+
# Sets up so that you can use fragments to build a final config file,
6666
#
6767
# OPTIONS:
6868
# - mode The mode of the final file
@@ -78,16 +78,16 @@
7878
# - Creates fragment directories if it didn't exist already
7979
# - Executes the concatfragments.sh script to build the final file, this script will create
8080
# directory/fragments.concat. Execution happens only when:
81-
# * The directory changes
82-
# * fragments.concat != final destination, this means rebuilds will happen whenever
81+
# * The directory changes
82+
# * fragments.concat != final destination, this means rebuilds will happen whenever
8383
# someone changes or deletes the final file. Checking is done using /usr/bin/cmp.
8484
# * The Exec gets notified by something else - like the concat::fragment define
8585
# - Copies the file over to the final destination using a file resource
8686
#
8787
# ALIASES:
8888
# - The exec can notified using Exec["concat_/path/to/file"] or Exec["concat_/path/to/directory"]
89-
# - The final file can be referened as File["/path/to/file"] or File["concat_/path/to/file"]
90-
define concat($mode = 0644, $owner = $::id, $group = $concat::setup::root_group, $warn = "false", $force = "false", $backup = "puppet", $gnu = "true", $order="alpha") {
89+
# - The final file can be referened as File["/path/to/file"] or File["concat_/path/to/file"]
90+
define concat($mode = 0644, $owner = $::id, $group = $concat::setup::root_group, $warn = "false", $force = "false", $backup = "puppet", $gnu = undef, $order="alpha") {
9191
$safe_name = regsubst($name, '/', '_', 'G')
9292
$concatdir = $concat::setup::concatdir
9393
$version = $concat::setup::majorversion
@@ -113,12 +113,6 @@
113113
default: { fail("Improper 'force' value given to concat: $force") }
114114
}
115115

116-
case $gnu {
117-
'true',true,yes,on: { $gnuflag = "" }
118-
'false',false,no,off: { $gnuflag = "-g" }
119-
default: { fail("Improper 'gnu' value given to concat: $gnu") }
120-
}
121-
122116
case $order {
123117
numeric: { $orderflag = "-n" }
124118
alpha: { $orderflag = "" }
@@ -168,8 +162,8 @@
168162
subscribe => File[$fragdir],
169163
alias => "concat_${fragdir}",
170164
require => [ File[$fragdir], File["${fragdir}/fragments"], File["${fragdir}/fragments.concat"] ],
171-
unless => "${concat::setup::concatdir}/bin/concatfragments.sh -o ${fragdir}/${concat_name} -d ${fragdir} -t ${warnflag} ${forceflag} ${orderflag} ${gnuflag}",
172-
command => "${concat::setup::concatdir}/bin/concatfragments.sh -o ${fragdir}/${concat_name} -d ${fragdir} ${warnflag} ${forceflag} ${orderflag} ${gnuflag}",
165+
unless => "${concat::setup::concatdir}/bin/concatfragments.sh -o ${fragdir}/${concat_name} -d ${fragdir} -t ${warnflag} ${forceflag} ${orderflag}",
166+
command => "${concat::setup::concatdir}/bin/concatfragments.sh -o ${fragdir}/${concat_name} -d ${fragdir} ${warnflag} ${forceflag} ${orderflag}",
173167
}
174168
if $::id == 'root' {
175169
Exec["concat_${name}"]{

0 commit comments

Comments
 (0)