simp-rake-helpers 2.5.7 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +3 -1
- data/lib/simp/rake/build/iso.rb +11 -2
- data/lib/simp/rake/build/pkg.rb +60 -65
- data/lib/simp/rake/build/tar.rb +3 -0
- data/lib/simp/rake/build/vermap.yaml +1 -0
- data/lib/simp/rake/helpers/rpm_spec.rb +8 -370
- data/lib/simp/rake/helpers/rpm_spec/assets/simp4.spec +387 -0
- data/lib/simp/rake/helpers/rpm_spec/assets/simp5.spec +387 -0
- data/lib/simp/rake/helpers/rpm_spec/assets/simpdefault.spec +356 -0
- data/lib/simp/rake/helpers/version.rb +1 -1
- data/lib/simp/rake/pkg.rb +63 -60
- data/lib/simp/rpm.rb +52 -25
- data/spec/acceptance/files/simplib/CHANGELOG +2 -0
- data/spec/acceptance/files/simplib/Rakefile +3 -0
- data/spec/acceptance/files/simplib/build/rpm_metadata/requires +1 -0
- data/spec/acceptance/files/simplib/metadata.json +33 -0
- data/spec/acceptance/files/testpackage_missing_license/CHANGELOG +2 -0
- data/spec/acceptance/files/testpackage_missing_license/Rakefile +3 -0
- data/spec/acceptance/files/testpackage_missing_license/build/rpm_metadata/requires +1 -0
- data/spec/acceptance/files/testpackage_missing_license/metadata.json +32 -0
- data/spec/acceptance/files/testpackage_missing_metadata_file/CHANGELOG +2 -0
- data/spec/acceptance/files/testpackage_missing_metadata_file/Rakefile +3 -0
- data/spec/acceptance/files/testpackage_missing_metadata_file/build/rpm_metadata/requires +1 -0
- data/spec/acceptance/files/testpackage_missing_name/CHANGELOG +2 -0
- data/spec/acceptance/files/testpackage_missing_name/Rakefile +3 -0
- data/spec/acceptance/files/testpackage_missing_name/build/rpm_metadata/requires +1 -0
- data/spec/acceptance/files/testpackage_missing_name/metadata.json +32 -0
- data/spec/acceptance/files/testpackage_missing_source/CHANGELOG +2 -0
- data/spec/acceptance/files/testpackage_missing_source/Rakefile +3 -0
- data/spec/acceptance/files/testpackage_missing_source/build/rpm_metadata/requires +1 -0
- data/spec/acceptance/files/testpackage_missing_source/metadata.json +32 -0
- data/spec/acceptance/files/testpackage_missing_summary/CHANGELOG +2 -0
- data/spec/acceptance/files/testpackage_missing_summary/Rakefile +3 -0
- data/spec/acceptance/files/testpackage_missing_summary/build/rpm_metadata/requires +1 -0
- data/spec/acceptance/files/testpackage_missing_summary/metadata.json +32 -0
- data/spec/acceptance/files/testpackage_missing_version/CHANGELOG +2 -0
- data/spec/acceptance/files/testpackage_missing_version/Rakefile +3 -0
- data/spec/acceptance/files/testpackage_missing_version/build/rpm_metadata/requires +1 -0
- data/spec/acceptance/files/testpackage_missing_version/metadata.json +32 -0
- data/spec/acceptance/files/testpackage_with_bad_changelog_date/CHANGELOG +2 -0
- data/spec/acceptance/files/testpackage_with_bad_changelog_date/Rakefile +3 -0
- data/spec/acceptance/files/testpackage_with_bad_changelog_date/build/rpm_metadata/requires +1 -0
- data/spec/acceptance/files/testpackage_with_bad_changelog_date/metadata.json +33 -0
- data/spec/acceptance/files/testpackage_with_release/CHANGELOG +2 -0
- data/spec/acceptance/files/testpackage_with_release/Rakefile +3 -0
- data/spec/acceptance/files/testpackage_with_release/build/rpm_metadata/release +1 -0
- data/spec/acceptance/files/testpackage_with_release/build/rpm_metadata/requires +1 -0
- data/spec/acceptance/files/testpackage_with_release/metadata.json +33 -0
- data/spec/acceptance/files/testpackage_without_changelog/Rakefile +3 -0
- data/spec/acceptance/files/testpackage_without_changelog/build/rpm_metadata/requires +1 -0
- data/spec/acceptance/files/testpackage_without_changelog/metadata.json +33 -0
- data/spec/acceptance/pkg_rpm_spec.rb +215 -41
- metadata +44 -2
@@ -0,0 +1,387 @@
|
|
1
|
+
%{lua:
|
2
|
+
|
3
|
+
--
|
4
|
+
-- When you build you must to pass this along so that we know how
|
5
|
+
-- to get the preliminary information.
|
6
|
+
-- This directory should hold the following items:
|
7
|
+
-- * 'build/rpm_metadata/requires' <- optional list of 'Requires', 'Provides',
|
8
|
+
-- and 'Obsoletes' to supplement those auto-generated in this spec file
|
9
|
+
-- * 'build/rpm_metadata/release' <- optional RPM release number to use in
|
10
|
+
-- lieu of number hard-coded in this spec file
|
11
|
+
-- * 'CHANGELOG' <- optional RPM formatted Changelog to use in lieu of minimal,
|
12
|
+
-- changelog entry auto-generated in this spec file
|
13
|
+
-- * 'metadata.json' <- required file that must contain the following metadata:
|
14
|
+
-- - 'name' - package name
|
15
|
+
-- - 'version' - package version
|
16
|
+
-- - 'license' - package license
|
17
|
+
-- - 'summary' - package summary
|
18
|
+
-- - 'source' - package source
|
19
|
+
--
|
20
|
+
-- Example:
|
21
|
+
-- rpmbuild -D 'pup_module_info_dir /home/user/project/puppet_module' -ba SPECS/specfile.spec
|
22
|
+
--
|
23
|
+
-- If this is not found, we will look in %{_sourcedir} for the files and fall
|
24
|
+
-- back to the current directory
|
25
|
+
--
|
26
|
+
|
27
|
+
src_dir = rpm.expand('%{pup_module_info_dir}')
|
28
|
+
|
29
|
+
if string.match(src_dir, '^%%') or (posix.stat(src_dir, 'type') ~= 'directory') then
|
30
|
+
src_dir = rpm.expand('%{_sourcedir}')
|
31
|
+
|
32
|
+
if (posix.stat((src_dir .. "/metadata.json"), 'type') ~= 'regular') then
|
33
|
+
src_dir = './'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
-- These UNKNOWN entries should break the build if something bad happens
|
38
|
+
|
39
|
+
package_name = "UNKNOWN"
|
40
|
+
package_version = "UNKNOWN"
|
41
|
+
module_license = "UNKNOWN"
|
42
|
+
|
43
|
+
--
|
44
|
+
-- Default to 2016
|
45
|
+
-- This was done due to the change in naming scheme across all of the modules.
|
46
|
+
--
|
47
|
+
|
48
|
+
package_release = '2016'
|
49
|
+
|
50
|
+
}
|
51
|
+
|
52
|
+
%{lua:
|
53
|
+
-- Pull the Relevant Metadata out of the Puppet module metadata.json.
|
54
|
+
|
55
|
+
metadata = ''
|
56
|
+
metadata_file = io.open(src_dir .. "/metadata.json","r")
|
57
|
+
if metadata_file then
|
58
|
+
metadata = metadata_file:read("*all")
|
59
|
+
|
60
|
+
-- Ignore the first curly brace
|
61
|
+
metadata = metadata:gsub("{}?", '|', 1)
|
62
|
+
|
63
|
+
-- Ignore all keys that are below the first level
|
64
|
+
metadata = metadata:gsub("{.-}", '')
|
65
|
+
metadata = metadata:gsub("%[.-%]", '')
|
66
|
+
else
|
67
|
+
error("Could not open 'metadata.json'", 0)
|
68
|
+
end
|
69
|
+
|
70
|
+
-- This starts as an empty string so that we can build it later
|
71
|
+
module_requires = ''
|
72
|
+
|
73
|
+
}
|
74
|
+
|
75
|
+
%{lua:
|
76
|
+
|
77
|
+
-- Get the Module Name and put it in the correct format
|
78
|
+
|
79
|
+
local name_match = string.match(metadata, '"name":%s+"(.-)"%s*,')
|
80
|
+
|
81
|
+
module_author = ''
|
82
|
+
module_name = ''
|
83
|
+
|
84
|
+
if name_match then
|
85
|
+
package_name = ('pupmod-' .. name_match)
|
86
|
+
|
87
|
+
local i = 0
|
88
|
+
for str in string.gmatch(name_match,'[^-]+') do
|
89
|
+
if i == 0 then
|
90
|
+
module_author = str
|
91
|
+
else
|
92
|
+
if module_name == '' then
|
93
|
+
module_name = str
|
94
|
+
else
|
95
|
+
module_name = (module_name .. '-' .. str)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
i = i+1
|
100
|
+
end
|
101
|
+
else
|
102
|
+
error("Could not find valid package name in 'metadata.json'", 0)
|
103
|
+
end
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
%{lua:
|
108
|
+
|
109
|
+
-- Get the Module Version
|
110
|
+
|
111
|
+
local version_match = string.match(metadata, '"version":%s+"(.-)"%s*,')
|
112
|
+
|
113
|
+
if version_match then
|
114
|
+
package_version = version_match
|
115
|
+
else
|
116
|
+
error("Could not find valid package version in 'metadata.json'", 0)
|
117
|
+
end
|
118
|
+
|
119
|
+
}
|
120
|
+
|
121
|
+
%{lua:
|
122
|
+
|
123
|
+
-- Get the Module License
|
124
|
+
|
125
|
+
local license_match = string.match(metadata, '"license":%s+"(.-)"%s*,')
|
126
|
+
|
127
|
+
if license_match then
|
128
|
+
module_license = license_match
|
129
|
+
else
|
130
|
+
error("Could not find valid package license in 'metadata.json'", 0)
|
131
|
+
end
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
%{lua:
|
136
|
+
|
137
|
+
-- Get the Module Summary
|
138
|
+
|
139
|
+
local summary_match = string.match(metadata, '"summary":%s+"(.-)"%s*,')
|
140
|
+
|
141
|
+
if summary_match then
|
142
|
+
module_summary = summary_match
|
143
|
+
else
|
144
|
+
error("Could not find valid package summary in 'metadata.json'", 0)
|
145
|
+
end
|
146
|
+
|
147
|
+
}
|
148
|
+
|
149
|
+
%{lua:
|
150
|
+
|
151
|
+
-- Get the Module Source line for the URL string
|
152
|
+
|
153
|
+
local source_match = string.match(metadata, '"source":%s+"(.-)"%s*,')
|
154
|
+
|
155
|
+
if source_match then
|
156
|
+
module_source = source_match
|
157
|
+
else
|
158
|
+
error("Could not find valid package source in 'metadata.json'", 0)
|
159
|
+
end
|
160
|
+
|
161
|
+
}
|
162
|
+
|
163
|
+
%{lua:
|
164
|
+
|
165
|
+
-- Snag the RPM-specific items out of the 'build/rpm_metadata' directory
|
166
|
+
|
167
|
+
-- First, the Release Number
|
168
|
+
|
169
|
+
rel_file = io.open(src_dir .. "/build/rpm_metadata/release", "r")
|
170
|
+
|
171
|
+
if not rel_file then
|
172
|
+
-- Need this for the SRPM case
|
173
|
+
rel_file = io.open(src_dir .. "/release", "r")
|
174
|
+
end
|
175
|
+
|
176
|
+
|
177
|
+
if rel_file then
|
178
|
+
for line in rel_file:lines() do
|
179
|
+
is_comment = string.match(line, "^%s*#")
|
180
|
+
is_blank = string.match(line, "^%s*$")
|
181
|
+
|
182
|
+
if not (is_comment or is_blank) then
|
183
|
+
package_release = line
|
184
|
+
break
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
}
|
190
|
+
|
191
|
+
%{lua:
|
192
|
+
|
193
|
+
-- Next, the Requirements
|
194
|
+
req_file = io.open(src_dir .. "/build/rpm_metadata/requires", "r")
|
195
|
+
|
196
|
+
if not req_file then
|
197
|
+
-- Need this for the SRPM case
|
198
|
+
req_file = io.open(src_dir .. "/requires", "r")
|
199
|
+
end
|
200
|
+
|
201
|
+
if req_file then
|
202
|
+
for line in req_file:lines() do
|
203
|
+
valid_line = (string.match(line, "^Requires: ") or string.match(line, "^Obsoletes: ") or string.match(line, "^Provides: "))
|
204
|
+
|
205
|
+
if valid_line then
|
206
|
+
module_requires = (module_requires .. "\n" .. line)
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
}
|
211
|
+
|
212
|
+
%define module_name %{lua: print(module_name)}
|
213
|
+
%define base_name %{lua: print(package_name)}
|
214
|
+
|
215
|
+
%{lua:
|
216
|
+
-- Determine which Variant we are going to build
|
217
|
+
|
218
|
+
local variant = rpm.expand("%{_variant}")
|
219
|
+
local variant_version = nil
|
220
|
+
|
221
|
+
local foo = ""
|
222
|
+
|
223
|
+
local i = 0
|
224
|
+
for str in string.gmatch(variant,'[^-]+') do
|
225
|
+
if i == 0 then
|
226
|
+
variant = str
|
227
|
+
elseif i == 1 then
|
228
|
+
variant_version = str
|
229
|
+
else
|
230
|
+
break
|
231
|
+
end
|
232
|
+
|
233
|
+
i = i+1
|
234
|
+
end
|
235
|
+
|
236
|
+
rpm.define("variant " .. variant)
|
237
|
+
|
238
|
+
if variant == "pe" then
|
239
|
+
rpm.define("puppet_user pe-puppet")
|
240
|
+
else
|
241
|
+
rpm.define("puppet_user puppet")
|
242
|
+
end
|
243
|
+
|
244
|
+
if variant == "pe" then
|
245
|
+
if variant_version and ( rpm.vercmp(variant_version,'4') >= 0 ) then
|
246
|
+
rpm.define("_sysconfdir /etc/puppetlabs/code")
|
247
|
+
else
|
248
|
+
rpm.define("_sysconfdir /etc/puppetlabs/puppet")
|
249
|
+
end
|
250
|
+
elseif variant == "p4" then
|
251
|
+
rpm.define("_sysconfdir /etc/puppetlabs/code")
|
252
|
+
else
|
253
|
+
rpm.define("_sysconfdir /etc/puppet")
|
254
|
+
end
|
255
|
+
}
|
256
|
+
|
257
|
+
Summary: %{module_name} Puppet Module
|
258
|
+
%if 0%{?_variant:1}
|
259
|
+
Name: %{base_name}-%{_variant}
|
260
|
+
%else
|
261
|
+
Name: %{base_name}
|
262
|
+
%endif
|
263
|
+
|
264
|
+
Version: %{lua: print(package_version)}
|
265
|
+
Release: %{lua: print(package_release)}
|
266
|
+
License: %{lua: print(module_license)}
|
267
|
+
Group: Applications/System
|
268
|
+
Source0: %{base_name}-%{version}-%{release}.tar.gz
|
269
|
+
Source1: %{lua: print("metadata.json")}
|
270
|
+
%{lua:
|
271
|
+
-- Include our sources as appropriate
|
272
|
+
changelog = io.open(src_dir .. "/CHANGELOG","r")
|
273
|
+
if changelog then
|
274
|
+
print("Source2: " .. "CHANGELOG\n")
|
275
|
+
end
|
276
|
+
|
277
|
+
if rel_file then
|
278
|
+
print("Source3: " .. "release\n")
|
279
|
+
end
|
280
|
+
if req_file then
|
281
|
+
print("Source4: " .. "requires\n")
|
282
|
+
end
|
283
|
+
}
|
284
|
+
URL: %{lua: print(module_source)}
|
285
|
+
BuildRoot: %{_tmppath}/%{base_name}-%{version}-%{release}-buildroot
|
286
|
+
BuildArch: noarch
|
287
|
+
|
288
|
+
%if "%{variant}" == "pe"
|
289
|
+
Requires: pe-puppet >= 3.8.6
|
290
|
+
%else
|
291
|
+
Requires: puppet >= 3.8.6
|
292
|
+
%endif
|
293
|
+
|
294
|
+
%if ("%{base_name}" != "pupmod-simp-simplib") && ("%{base_name}" != "pupmod-puppetlabs-stdlib")
|
295
|
+
Requires: pupmod-simp-simplib >= 1.2.6
|
296
|
+
%endif
|
297
|
+
|
298
|
+
%if "%{base_name}" != "pupmod-puppetlabs-stdlib"
|
299
|
+
Requires: pupmod-puppetlabs-stdlib >= 4.9.0
|
300
|
+
Requires: pupmod-puppetlabs-stdlib < 6.0.0
|
301
|
+
%endif
|
302
|
+
|
303
|
+
%{lua: print(module_requires)}
|
304
|
+
|
305
|
+
Provides: pupmod-%{lua: print(module_name)} = %{lua: print(package_version .. "-" .. package_release)}
|
306
|
+
Obsoletes: pupmod-%{lua: print(module_name)} < %{lua: print(package_version .. "-" .. package_release)}
|
307
|
+
|
308
|
+
%{lua:
|
309
|
+
|
310
|
+
-- This is a workaround for the 'simp-rsync' real RPM conflict but is
|
311
|
+
-- required by some external modules.
|
312
|
+
-- This should be removed when SIMP 6 is stable
|
313
|
+
|
314
|
+
author_rpm_name = module_author .. "-" .. module_name
|
315
|
+
|
316
|
+
if author_rpm_name ~= 'simp-rsync' then
|
317
|
+
print("Provides: " .. author_rpm_name .. " = " .. package_version .. "-" .. package_release .. "\n")
|
318
|
+
print("Obsoletes: " .. author_rpm_name .. " < " .. package_version .. "-" .. package_release .. "\n")
|
319
|
+
end
|
320
|
+
}
|
321
|
+
|
322
|
+
Prefix: %{_sysconfdir}/environments/simp/modules
|
323
|
+
|
324
|
+
%description
|
325
|
+
%{lua: print(module_summary)}
|
326
|
+
|
327
|
+
%prep
|
328
|
+
%setup -q -n %{base_name}-%{version}
|
329
|
+
|
330
|
+
%build
|
331
|
+
|
332
|
+
%install
|
333
|
+
[ "%{buildroot}" != "/" ] && rm -rf %{buildroot}
|
334
|
+
|
335
|
+
mkdir -p %{buildroot}/%{prefix}
|
336
|
+
|
337
|
+
curdir=`pwd`
|
338
|
+
dirname=`basename $curdir`
|
339
|
+
cp -r ../$dirname %{buildroot}/%{prefix}/%{module_name}
|
340
|
+
cd %{buildroot}%{prefix}/%{module_name}
|
341
|
+
rm -rf %{buildroot}/%{prefix}/%{module_name}/.git
|
342
|
+
rm -f %{buildroot}/%{prefix}/*.lock
|
343
|
+
rm -rf %{buildroot}/%{prefix}/spec/fixtures/modules
|
344
|
+
rm -rf %{buildroot}/%{prefix}/dist
|
345
|
+
rm -rf %{buildroot}/%{prefix}/junit
|
346
|
+
rm -rf %{buildroot}/%{prefix}/log
|
347
|
+
|
348
|
+
%clean
|
349
|
+
[ "%{buildroot}" != "/" ] && rm -rf %{buildroot}
|
350
|
+
|
351
|
+
mkdir -p %{buildroot}/%{prefix}
|
352
|
+
|
353
|
+
%files
|
354
|
+
%defattr(0640,root,%{puppet_user},0750)
|
355
|
+
%{prefix}/%{module_name}
|
356
|
+
|
357
|
+
%changelog
|
358
|
+
%{lua:
|
359
|
+
-- Finally, the CHANGELOG
|
360
|
+
|
361
|
+
-- A default CHANGELOG in case we cannot find a real one
|
362
|
+
|
363
|
+
default_changelog = [===[
|
364
|
+
* $date Auto Changelog <auto@no.body> - $version-$release
|
365
|
+
- Latest release of $name
|
366
|
+
]===]
|
367
|
+
|
368
|
+
default_lookup_table = {
|
369
|
+
date = os.date("%a %b %d %Y"),
|
370
|
+
version = package_version,
|
371
|
+
release = package_release,
|
372
|
+
name = package_name
|
373
|
+
}
|
374
|
+
|
375
|
+
changelog = io.open(src_dir .. "/CHANGELOG","r")
|
376
|
+
if changelog then
|
377
|
+
first_line = changelog:read()
|
378
|
+
if string.match(first_line, "^*%s+%a%a%a%s+%a%a%a%s+%d%d?%s+%d%d%d%d%s+.+") then
|
379
|
+
changelog:seek("set",0)
|
380
|
+
print(changelog:read("*all"))
|
381
|
+
else
|
382
|
+
print((default_changelog:gsub('$(%w+)', default_lookup_table)))
|
383
|
+
end
|
384
|
+
else
|
385
|
+
print((default_changelog:gsub('$(%w+)', default_lookup_table)))
|
386
|
+
end
|
387
|
+
}
|
@@ -0,0 +1,387 @@
|
|
1
|
+
%{lua:
|
2
|
+
|
3
|
+
--
|
4
|
+
-- When you build you must to pass this along so that we know how
|
5
|
+
-- to get the preliminary information.
|
6
|
+
-- This directory should hold the following items:
|
7
|
+
-- * 'build/rpm_metadata/requires' <- optional list of 'Requires', 'Provides',
|
8
|
+
-- and 'Obsoletes' to supplement those auto-generated in this spec file
|
9
|
+
-- * 'build/rpm_metadata/release' <- optional RPM release number to use in
|
10
|
+
-- lieu of number hard-coded in this spec file
|
11
|
+
-- * 'CHANGELOG' <- optional RPM formatted Changelog to use in lieu of minimal,
|
12
|
+
-- changelog entry auto-generated in this spec file
|
13
|
+
-- * 'metadata.json' <- required file that must contain the following metadata:
|
14
|
+
-- - 'name' - package name
|
15
|
+
-- - 'version' - package version
|
16
|
+
-- - 'license' - package license
|
17
|
+
-- - 'summary' - package summary
|
18
|
+
-- - 'source' - package source
|
19
|
+
--
|
20
|
+
-- Example:
|
21
|
+
-- rpmbuild -D 'pup_module_info_dir /home/user/project/puppet_module' -ba SPECS/specfile.spec
|
22
|
+
--
|
23
|
+
-- If this is not found, we will look in %{_sourcedir} for the files and fall
|
24
|
+
-- back to the current directory
|
25
|
+
--
|
26
|
+
|
27
|
+
src_dir = rpm.expand('%{pup_module_info_dir}')
|
28
|
+
|
29
|
+
if string.match(src_dir, '^%%') or (posix.stat(src_dir, 'type') ~= 'directory') then
|
30
|
+
src_dir = rpm.expand('%{_sourcedir}')
|
31
|
+
|
32
|
+
if (posix.stat((src_dir .. "/metadata.json"), 'type') ~= 'regular') then
|
33
|
+
src_dir = './'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
-- These UNKNOWN entries should break the build if something bad happens
|
38
|
+
|
39
|
+
package_name = "UNKNOWN"
|
40
|
+
package_version = "UNKNOWN"
|
41
|
+
module_license = "UNKNOWN"
|
42
|
+
|
43
|
+
--
|
44
|
+
-- Default to 2016
|
45
|
+
-- This was done due to the change in naming scheme across all of the modules.
|
46
|
+
--
|
47
|
+
|
48
|
+
package_release = '2016'
|
49
|
+
|
50
|
+
}
|
51
|
+
|
52
|
+
%{lua:
|
53
|
+
-- Pull the Relevant Metadata out of the Puppet module metadata.json.
|
54
|
+
|
55
|
+
metadata = ''
|
56
|
+
metadata_file = io.open(src_dir .. "/metadata.json","r")
|
57
|
+
if metadata_file then
|
58
|
+
metadata = metadata_file:read("*all")
|
59
|
+
|
60
|
+
-- Ignore the first curly brace
|
61
|
+
metadata = metadata:gsub("{}?", '|', 1)
|
62
|
+
|
63
|
+
-- Ignore all keys that are below the first level
|
64
|
+
metadata = metadata:gsub("{.-}", '')
|
65
|
+
metadata = metadata:gsub("%[.-%]", '')
|
66
|
+
else
|
67
|
+
error("Could not open 'metadata.json'", 0)
|
68
|
+
end
|
69
|
+
|
70
|
+
-- This starts as an empty string so that we can build it later
|
71
|
+
module_requires = ''
|
72
|
+
|
73
|
+
}
|
74
|
+
|
75
|
+
%{lua:
|
76
|
+
|
77
|
+
-- Get the Module Name and put it in the correct format
|
78
|
+
|
79
|
+
local name_match = string.match(metadata, '"name":%s+"(.-)"%s*,')
|
80
|
+
|
81
|
+
module_author = ''
|
82
|
+
module_name = ''
|
83
|
+
|
84
|
+
if name_match then
|
85
|
+
package_name = ('pupmod-' .. name_match)
|
86
|
+
|
87
|
+
local i = 0
|
88
|
+
for str in string.gmatch(name_match,'[^-]+') do
|
89
|
+
if i == 0 then
|
90
|
+
module_author = str
|
91
|
+
else
|
92
|
+
if module_name == '' then
|
93
|
+
module_name = str
|
94
|
+
else
|
95
|
+
module_name = (module_name .. '-' .. str)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
i = i+1
|
100
|
+
end
|
101
|
+
else
|
102
|
+
error("Could not find valid package name in 'metadata.json'", 0)
|
103
|
+
end
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
%{lua:
|
108
|
+
|
109
|
+
-- Get the Module Version
|
110
|
+
|
111
|
+
local version_match = string.match(metadata, '"version":%s+"(.-)"%s*,')
|
112
|
+
|
113
|
+
if version_match then
|
114
|
+
package_version = version_match
|
115
|
+
else
|
116
|
+
error("Could not find valid package version in 'metadata.json'", 0)
|
117
|
+
end
|
118
|
+
|
119
|
+
}
|
120
|
+
|
121
|
+
%{lua:
|
122
|
+
|
123
|
+
-- Get the Module License
|
124
|
+
|
125
|
+
local license_match = string.match(metadata, '"license":%s+"(.-)"%s*,')
|
126
|
+
|
127
|
+
if license_match then
|
128
|
+
module_license = license_match
|
129
|
+
else
|
130
|
+
error("Could not find valid package license in 'metadata.json'", 0)
|
131
|
+
end
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
%{lua:
|
136
|
+
|
137
|
+
-- Get the Module Summary
|
138
|
+
|
139
|
+
local summary_match = string.match(metadata, '"summary":%s+"(.-)"%s*,')
|
140
|
+
|
141
|
+
if summary_match then
|
142
|
+
module_summary = summary_match
|
143
|
+
else
|
144
|
+
error("Could not find valid package summary in 'metadata.json'", 0)
|
145
|
+
end
|
146
|
+
|
147
|
+
}
|
148
|
+
|
149
|
+
%{lua:
|
150
|
+
|
151
|
+
-- Get the Module Source line for the URL string
|
152
|
+
|
153
|
+
local source_match = string.match(metadata, '"source":%s+"(.-)"%s*,')
|
154
|
+
|
155
|
+
if source_match then
|
156
|
+
module_source = source_match
|
157
|
+
else
|
158
|
+
error("Could not find valid package source in 'metadata.json'", 0)
|
159
|
+
end
|
160
|
+
|
161
|
+
}
|
162
|
+
|
163
|
+
%{lua:
|
164
|
+
|
165
|
+
-- Snag the RPM-specific items out of the 'build/rpm_metadata' directory
|
166
|
+
|
167
|
+
-- First, the Release Number
|
168
|
+
|
169
|
+
rel_file = io.open(src_dir .. "/build/rpm_metadata/release", "r")
|
170
|
+
|
171
|
+
if not rel_file then
|
172
|
+
-- Need this for the SRPM case
|
173
|
+
rel_file = io.open(src_dir .. "/release", "r")
|
174
|
+
end
|
175
|
+
|
176
|
+
|
177
|
+
if rel_file then
|
178
|
+
for line in rel_file:lines() do
|
179
|
+
is_comment = string.match(line, "^%s*#")
|
180
|
+
is_blank = string.match(line, "^%s*$")
|
181
|
+
|
182
|
+
if not (is_comment or is_blank) then
|
183
|
+
package_release = line
|
184
|
+
break
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
}
|
190
|
+
|
191
|
+
%{lua:
|
192
|
+
|
193
|
+
-- Next, the Requirements
|
194
|
+
req_file = io.open(src_dir .. "/build/rpm_metadata/requires", "r")
|
195
|
+
|
196
|
+
if not req_file then
|
197
|
+
-- Need this for the SRPM case
|
198
|
+
req_file = io.open(src_dir .. "/requires", "r")
|
199
|
+
end
|
200
|
+
|
201
|
+
if req_file then
|
202
|
+
for line in req_file:lines() do
|
203
|
+
valid_line = (string.match(line, "^Requires: ") or string.match(line, "^Obsoletes: ") or string.match(line, "^Provides: "))
|
204
|
+
|
205
|
+
if valid_line then
|
206
|
+
module_requires = (module_requires .. "\n" .. line)
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
}
|
211
|
+
|
212
|
+
%define module_name %{lua: print(module_name)}
|
213
|
+
%define base_name %{lua: print(package_name)}
|
214
|
+
|
215
|
+
%{lua:
|
216
|
+
-- Determine which Variant we are going to build
|
217
|
+
|
218
|
+
local variant = rpm.expand("%{_variant}")
|
219
|
+
local variant_version = nil
|
220
|
+
|
221
|
+
local foo = ""
|
222
|
+
|
223
|
+
local i = 0
|
224
|
+
for str in string.gmatch(variant,'[^-]+') do
|
225
|
+
if i == 0 then
|
226
|
+
variant = str
|
227
|
+
elseif i == 1 then
|
228
|
+
variant_version = str
|
229
|
+
else
|
230
|
+
break
|
231
|
+
end
|
232
|
+
|
233
|
+
i = i+1
|
234
|
+
end
|
235
|
+
|
236
|
+
rpm.define("variant " .. variant)
|
237
|
+
|
238
|
+
if variant == "pe" then
|
239
|
+
rpm.define("puppet_user pe-puppet")
|
240
|
+
else
|
241
|
+
rpm.define("puppet_user puppet")
|
242
|
+
end
|
243
|
+
|
244
|
+
if variant == "pe" then
|
245
|
+
if variant_version and ( rpm.vercmp(variant_version,'4') >= 0 ) then
|
246
|
+
rpm.define("_sysconfdir /etc/puppetlabs/code")
|
247
|
+
else
|
248
|
+
rpm.define("_sysconfdir /etc/puppetlabs/puppet")
|
249
|
+
end
|
250
|
+
elseif variant == "p4" then
|
251
|
+
rpm.define("_sysconfdir /etc/puppetlabs/code")
|
252
|
+
else
|
253
|
+
rpm.define("_sysconfdir /etc/puppet")
|
254
|
+
end
|
255
|
+
}
|
256
|
+
|
257
|
+
Summary: %{module_name} Puppet Module
|
258
|
+
%if 0%{?_variant:1}
|
259
|
+
Name: %{base_name}-%{_variant}
|
260
|
+
%else
|
261
|
+
Name: %{base_name}
|
262
|
+
%endif
|
263
|
+
|
264
|
+
Version: %{lua: print(package_version)}
|
265
|
+
Release: %{lua: print(package_release)}
|
266
|
+
License: %{lua: print(module_license)}
|
267
|
+
Group: Applications/System
|
268
|
+
Source0: %{base_name}-%{version}-%{release}.tar.gz
|
269
|
+
Source1: %{lua: print("metadata.json")}
|
270
|
+
%{lua:
|
271
|
+
-- Include our sources as appropriate
|
272
|
+
changelog = io.open(src_dir .. "/CHANGELOG","r")
|
273
|
+
if changelog then
|
274
|
+
print("Source2: " .. "CHANGELOG\n")
|
275
|
+
end
|
276
|
+
|
277
|
+
if rel_file then
|
278
|
+
print("Source3: " .. "release\n")
|
279
|
+
end
|
280
|
+
if req_file then
|
281
|
+
print("Source4: " .. "requires\n")
|
282
|
+
end
|
283
|
+
}
|
284
|
+
URL: %{lua: print(module_source)}
|
285
|
+
BuildRoot: %{_tmppath}/%{base_name}-%{version}-%{release}-buildroot
|
286
|
+
BuildArch: noarch
|
287
|
+
|
288
|
+
%if "%{variant}" == "pe"
|
289
|
+
Requires: pe-puppet >= 3.8.6
|
290
|
+
%else
|
291
|
+
Requires: puppet >= 3.8.6
|
292
|
+
%endif
|
293
|
+
|
294
|
+
%if ("%{base_name}" != "pupmod-simp-simplib") && ("%{base_name}" != "pupmod-puppetlabs-stdlib")
|
295
|
+
Requires: pupmod-simp-simplib >= 1.2.6
|
296
|
+
%endif
|
297
|
+
|
298
|
+
%if "%{base_name}" != "pupmod-puppetlabs-stdlib"
|
299
|
+
Requires: pupmod-puppetlabs-stdlib >= 4.9.0
|
300
|
+
Requires: pupmod-puppetlabs-stdlib < 6.0.0
|
301
|
+
%endif
|
302
|
+
|
303
|
+
%{lua: print(module_requires)}
|
304
|
+
|
305
|
+
Provides: pupmod-%{lua: print(module_name)} = %{lua: print(package_version .. "-" .. package_release)}
|
306
|
+
Obsoletes: pupmod-%{lua: print(module_name)} < %{lua: print(package_version .. "-" .. package_release)}
|
307
|
+
|
308
|
+
%{lua:
|
309
|
+
|
310
|
+
-- This is a workaround for the 'simp-rsync' real RPM conflict but is
|
311
|
+
-- required by some external modules.
|
312
|
+
-- This should be removed when SIMP 6 is stable
|
313
|
+
|
314
|
+
author_rpm_name = module_author .. "-" .. module_name
|
315
|
+
|
316
|
+
if author_rpm_name ~= 'simp-rsync' then
|
317
|
+
print("Provides: " .. author_rpm_name .. " = " .. package_version .. "-" .. package_release .. "\n")
|
318
|
+
print("Obsoletes: " .. author_rpm_name .. " < " .. package_version .. "-" .. package_release .. "\n")
|
319
|
+
end
|
320
|
+
}
|
321
|
+
|
322
|
+
Prefix: %{_sysconfdir}/environments/simp/modules
|
323
|
+
|
324
|
+
%description
|
325
|
+
%{lua: print(module_summary)}
|
326
|
+
|
327
|
+
%prep
|
328
|
+
%setup -q -n %{base_name}-%{version}
|
329
|
+
|
330
|
+
%build
|
331
|
+
|
332
|
+
%install
|
333
|
+
[ "%{buildroot}" != "/" ] && rm -rf %{buildroot}
|
334
|
+
|
335
|
+
mkdir -p %{buildroot}/%{prefix}
|
336
|
+
|
337
|
+
curdir=`pwd`
|
338
|
+
dirname=`basename $curdir`
|
339
|
+
cp -r ../$dirname %{buildroot}/%{prefix}/%{module_name}
|
340
|
+
cd %{buildroot}%{prefix}/%{module_name}
|
341
|
+
rm -rf %{buildroot}/%{prefix}/%{module_name}/.git
|
342
|
+
rm -f %{buildroot}/%{prefix}/*.lock
|
343
|
+
rm -rf %{buildroot}/%{prefix}/spec/fixtures/modules
|
344
|
+
rm -rf %{buildroot}/%{prefix}/dist
|
345
|
+
rm -rf %{buildroot}/%{prefix}/junit
|
346
|
+
rm -rf %{buildroot}/%{prefix}/log
|
347
|
+
|
348
|
+
%clean
|
349
|
+
[ "%{buildroot}" != "/" ] && rm -rf %{buildroot}
|
350
|
+
|
351
|
+
mkdir -p %{buildroot}/%{prefix}
|
352
|
+
|
353
|
+
%files
|
354
|
+
%defattr(0640,root,%{puppet_user},0750)
|
355
|
+
%{prefix}/%{module_name}
|
356
|
+
|
357
|
+
%changelog
|
358
|
+
%{lua:
|
359
|
+
-- Finally, the CHANGELOG
|
360
|
+
|
361
|
+
-- A default CHANGELOG in case we cannot find a real one
|
362
|
+
|
363
|
+
default_changelog = [===[
|
364
|
+
* $date Auto Changelog <auto@no.body> - $version-$release
|
365
|
+
- Latest release of $name
|
366
|
+
]===]
|
367
|
+
|
368
|
+
default_lookup_table = {
|
369
|
+
date = os.date("%a %b %d %Y"),
|
370
|
+
version = package_version,
|
371
|
+
release = package_release,
|
372
|
+
name = package_name
|
373
|
+
}
|
374
|
+
|
375
|
+
changelog = io.open(src_dir .. "/CHANGELOG","r")
|
376
|
+
if changelog then
|
377
|
+
first_line = changelog:read()
|
378
|
+
if string.match(first_line, "^*%s+%a%a%a%s+%a%a%a%s+%d%d?%s+%d%d%d%d%s+.+") then
|
379
|
+
changelog:seek("set",0)
|
380
|
+
print(changelog:read("*all"))
|
381
|
+
else
|
382
|
+
print((default_changelog:gsub('$(%w+)', default_lookup_table)))
|
383
|
+
end
|
384
|
+
else
|
385
|
+
print((default_changelog:gsub('$(%w+)', default_lookup_table)))
|
386
|
+
end
|
387
|
+
}
|