forked from tpkg/client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
469 lines (414 loc) · 13 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
require 'rbconfig'
require 'tempfile'
require 'tmpdir'
require 'open-uri'
require 'openssl'
require 'rake/testtask'
require 'bundler/gem_tasks'
TPKGVER = `ruby -Ilib -e "require 'tpkg'; puts Tpkg::VERSION"`.chomp
TARBALLFILE = "tpkg-client-#{TPKGVER}.tar.gz"
TARBALL = File.expand_path(TARBALLFILE)
BUILDROOT = '/var/tmp/tpkg-client-buildroot'
# Copies the tpkg client files to destdir. If any of the dir options
# are not specified the files that would go in that directory will not
# be copied.
# options:
# :bindir
# :libdir
# :etcdir
# :mandir
# :externalsdir
# :schemadir
# :profiledir
# :ruby (#! lines in scripts will be changed to specified ruby)
# :copythirdparty
# If not specified the thirdparty directory will not be copied. The
# package will need to express appropriate dependencies as
# replacements for the libraries contained in that directory.
def copy_tpkg_files(destdir, options={})
if options[:bindir]
bindir = File.join(destdir, options[:bindir])
mkdir_p(bindir)
binapps = ['tpkg', 'cpan2tpkg', 'gem2tpkg', 'tpkg_xml_to_yml']
binapps.each do |binapp|
if options[:ruby]
# Change #! line
File.open(File.join(bindir, binapp), 'w') do |newfile|
File.open(File.join('bin', binapp)) do |oldfile|
# Modify the first line
firstline = oldfile.gets
# Preserve any options. I.e. #!/usr/bin/ruby -w
shebang, shebangopts = firstline.split(' ', 2)
newfile.puts "#!#{options[:ruby]} #{shebangopts}"
# Then dump in the rest of the file
newfile.write(oldfile.read)
end
end
else
cp(File.join('bin', binapp), bindir, :preserve => true)
end
chmod(0555, File.join(bindir, binapp))
end
end
if options[:libdir]
libdir = File.join(destdir, options[:libdir])
mkdir_p(libdir)
# Substitute TPKGVER into tpkg.rb
# Substitute proper path into DEFAULT_CONFIGDIR in tpkg.rb if appropriate
File.open(File.join(libdir, 'tpkg.rb'), 'w') do |newfile|
IO.foreach(File.join('lib', 'tpkg.rb')) do |line|
if line =~ /^\s*VERSION/
line.sub!(/=.*/, "= '#{TPKGVER}'")
end
if options[:etcdir] && line =~ /^\s*DEFAULT_CONFIGDIR/
line.sub!(/=.*/, "= '#{options[:etcdir]}'")
end
newfile.write(line)
end
end
chmod(0444, File.join(libdir, 'tpkg.rb'))
tpkglibdir = File.join(libdir, 'tpkg')
mkdir_p(tpkglibdir)
libs = ['deployer.rb', 'metadata.rb', 'os.rb', 'silently.rb', 'thread_pool.rb', 'version.rb', 'versiontype.rb']
libs.each do |lib|
cp(File.join('lib', 'tpkg', lib), tpkglibdir, :preserve => true)
chmod(0444, File.join(tpkglibdir, lib))
end
tpkgoslibdir = File.join(tpkglibdir, 'os')
mkdir_p(tpkgoslibdir)
Dir.glob('lib/tpkg/os/*.rb').each do |lib|
cp(lib, tpkgoslibdir, :preserve => true)
chmod(0444, File.join(tpkgoslibdir, File.basename(lib)))
end
if options[:copythirdparty]
# All the nice consistent usage of FileUtils and then this...
system("cd lib/tpkg && find thirdparty -name .svn -prune -o -print | cpio -pdum #{tpkglibdir}")
end
end
if options[:mandir]
mandir = File.join(destdir, options[:mandir])
Dir.chdir('man')
Dir.glob('man*').each do |mansubdir|
mansectiondir = File.join(mandir, mansubdir)
mkdir_p(mansectiondir)
Dir.chdir(mansubdir)
Dir.glob('*').each do |manpage|
cp(manpage, mansectiondir, :preserve => true)
chmod(0444, File.join(mansectiondir, manpage))
end
Dir.chdir('..')
end
Dir.chdir('..')
end
if options[:etcdir]
etcdir = File.join(destdir, options[:etcdir])
mkdir_p(etcdir)
cp('tpkg.conf', etcdir, :preserve => true)
chmod(0644, File.join(etcdir, 'tpkg.conf'))
# All of the supporting config files go into a subdirectory
etctpkgdir = File.join(etcdir, 'tpkg')
mkdir_p(etctpkgdir)
etctpkgfiles = ['ca.pem']
etctpkgfiles.each do |etctpkgfile|
cp(etctpkgfile, etctpkgdir, :preserve => true)
chmod(0644, File.join(etctpkgdir, etctpkgfile))
end
end
if options[:externalsdir]
externalsdir = File.join(destdir, options[:externalsdir])
mkdir_p(externalsdir)
Dir.glob(File.join('externals', '*')).each do |external|
cp(external, externalsdir, :preserve => true)
chmod(0555, File.join(externalsdir, File.basename(external)))
end
end
if options[:schemadir]
schemadir = File.join(destdir, options[:schemadir])
mkdir_p(schemadir)
Dir.glob(File.join('schema', '*')).each do |schema|
cp(schema, schemadir, :preserve => true)
chmod(0555, File.join(schemadir, File.basename(schema)))
end
end
if options[:profiledir]
profiledir = File.join(BUILDROOT, options[:profiledir])
mkdir_p(profiledir)
cp('tpkg_profile.sh', File.join(profiledir, 'tpkg.sh'), :preserve => true)
chmod(0755, File.join(profiledir, 'tpkg.sh'))
end
end
# rake test
# Run a specific file: rake test TEST=test/make.rb
# Run a specific method:
# rake test TEST=test/test_make.rb TESTOPTS="--name=test_make_osarch_names"
Rake::TestTask.new do |t|
t.libs << "lib"
t.verbose = true
end
# FlogTask is broken...
# begin
# require 'flog_task'
# FlogTask.new do |t|
# t.dirs = ['lib']
# end
# rescue LoadError
# warn "Flog not installed"
# end
desc 'Run flog on code'
task :flog do
system("flog -g lib")
end
namespace :flog do
desc 'Just the flog summary'
task :summary do
system("flog -s lib")
end
end
begin
require 'flay'
require 'flay_task'
FlayTask.new do |t|
t.dirs = ['lib']
end
rescue LoadError
warn "Flay gem not installed, flay rake tasks will be unavailable"
end
desc 'Build an tpkg client RPM on a Red Hat box'
task :redhat => [:redhatprep, :rpm]
desc 'Prep a Red Hat box for building an RPM'
task :redhatprep do
# Install the package which contains the rpmbuild command
system('rpm --quiet -q rpm-build || sudo yum install rpm-build')
end
desc 'Build an tpkg client RPM'
task :rpm do
#
# Create package file structure in build root
#
rm_rf(BUILDROOT)
bindir = File.join('usr', 'bin')
libdir = File.join('usr', 'lib', 'ruby', 'site_ruby', '1.8')
mandir = File.join('usr', 'share', 'man')
etcdir = '/etc'
externalsdir = File.join('usr', 'lib', 'tpkg', 'externals')
schemadir = File.join('etc', 'tpkg', 'schema')
profiledir = File.join('etc', 'profile.d')
copy_tpkg_files(BUILDROOT,
:bindir => bindir,
:libdir => libdir,
:mandir => mandir,
:etcdir => etcdir,
:externalsdir => externalsdir,
:schemadir => schemadir,
:profiledir => profiledir,
:copythirdparty => true)
#
# Prep spec file
#
spec = Tempfile.new('tpkgrpm')
IO.foreach('tpkg.spec') do |line|
line.sub!('%VER%', TPKGVER)
spec.puts(line)
end
spec.flush
#
# Build the package
#
system("rpmbuild -bb --buildroot #{BUILDROOT} #{spec.path}")
#
# Cleanup
#
rm_rf(BUILDROOT)
end
desc 'Build an tpkg client deb'
task :deb do
#
# Create package file structure in build root
#
system("sudo rm -rf #{BUILDROOT}")
mkdir_p(File.join(BUILDROOT, 'DEBIAN'))
File.open(File.join(BUILDROOT, 'DEBIAN', 'control'), 'w') do |control|
IO.foreach('control') do |line|
next if line =~ /^\s*#/ # Remove comments
line.sub!('%VER%', TPKGVER)
control.puts(line)
end
end
bindir = File.join('usr', 'bin')
libdir = File.join('usr', 'local', 'lib', 'site_ruby')
mandir = File.join('usr', 'share', 'man')
etcdir = '/etc'
externalsdir = File.join('usr', 'lib', 'tpkg', 'externals')
schemadir = File.join('etc', 'tpkg', 'schema')
copy_tpkg_files(BUILDROOT,
:bindir => bindir,
:libdir => libdir,
:mandir => mandir,
:etcdir => etcdir,
:externalsdir => externalsdir,
:schemadir => schemadir,
:copythirdparty => true)
#
# Set permissions
#
system("sudo chown -R 0:0 #{BUILDROOT}")
#
# Build the package
#
system("dpkg --build #{BUILDROOT} tpkg-#{TPKGVER}.deb")
#
# Cleanup
#
system("sudo rm -rf #{BUILDROOT}")
end
desc 'Build tpkg client SysV packages for Solaris'
task :solaris => [:sysvpkg]
desc 'Build an tpkg client SysV package'
task :sysvpkg do
#
# Create package file structure in build root
#
rm_rf(BUILDROOT)
bindir = File.join('usr', 'bin')
libdir = File.join('opt', 'csw', 'lib', 'ruby', 'site_ruby', '1.8')
mandir = File.join('usr', 'share', 'man')
etcdir = '/etc'
externalsdir = File.join('usr', 'lib', 'tpkg', 'externals')
schemadir = File.join('etc', 'tpkg', 'schema')
profiledir = File.join('etc', 'profile.d')
copy_tpkg_files(BUILDROOT,
:bindir => bindir,
:libdir => libdir,
:mandir => mandir,
:etcdir => etcdir,
:externalsdir => externalsdir,
:schemadir => schemadir,
:profiledir => profiledir,
:copythirdparty => true,
:ruby => '/opt/csw/bin/ruby')
#
# Prep packaging files
#
rm_rf('solbuild')
mkdir('solbuild')
File.open(File.join('solbuild', 'pkginfo'), 'w') do |pkginfo|
IO.foreach('pkginfo') do |line|
line.sub!('%VER%', TPKGVER)
pkginfo.puts(line)
end
end
File.open(File.join('solbuild', 'prototype'), 'w') do |prototype|
prototype.puts("i pkginfo=./pkginfo")
cp('depend', 'solbuild/depend')
prototype.puts("i depend=./depend")
cp('postinstall.solaris', 'solbuild/postinstall')
prototype.puts("i postinstall=./postinstall")
cp('postremove.solaris', 'solbuild/postremove')
prototype.puts("i postremove=./postremove")
# The tail +2 removes the first line, which is the base directory
# and doesn't need to be included in the package.
IO.popen("find #{BUILDROOT} | tail +2 | pkgproto") do |pipe|
pipe.each do |line|
# Clean up the directory names
line.sub!(BUILDROOT, '')
# Don't force our permissions on directories
if line =~ /^d/
line.sub!(/\S+ \S+ \S+$/, '? ? ?')
end
prototype.write(line)
end
end
end
#
# Build the package
#
system("cd solbuild && pkgmk -r #{BUILDROOT} -d $PWD/solbuild")
system("pkgtrans solbuild ../OSStpkg-#{TPKGVER}.pkg OSStpkg")
#
# Cleanup
#
rm_rf('solbuild')
rm_rf(BUILDROOT)
end
# Install based on Config::CONFIG paths
task :install, :destdir do |t, args|
destdir = nil
if args.destdir
destdir = args.destdir
else
destdir = '/'
end
copy_tpkg_files(destdir,
:bindir => Config::CONFIG['bindir'],
:libdir => Config::CONFIG['sitelibdir'],
:mandir => Config::CONFIG['mandir'],
:etcdir => Config::CONFIG['sysconfdir'],
# Can't find a better way to get the path to the current ruby
:ruby => File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']),
:copythirdparty => true)
end
desc 'Fetch tarball from github'
task :fetch do
if !File.exist?(TARBALL)
url = "http://cloud.github.com/downloads/tpkg/client/#{TARBALLFILE}"
puts "Fetching tarball from #{url}"
open(url) do |df|
open(TARBALL, 'w') do |lf|
lf.write(df.read)
end
end
end
end
desc 'Prepare portfile for submission to MacPorts'
task :macport => :fetch do
md5 = `openssl md5 #{TARBALL}`.chomp.split.last
sha1 = `openssl sha1 #{TARBALL}`.chomp.split.last
rmd160 = `openssl rmd160 #{TARBALL}`.chomp.split.last
sha256 = `openssl sha256 #{TARBALL}`.chomp.split.last
portfile = File.join(Dir.tmpdir, 'Portfile')
rm_f(portfile)
File.open(portfile, 'w') do |newfile|
IO.foreach('Portfile.template') do |line|
line.sub!('%VER%', TPKGVER)
line.sub!('%MD5%', md5)
line.sub!('%SHA1%', sha1)
line.sub!('%RMD160%', rmd160)
line.sub!('%SHA256%', sha256)
newfile.puts(line)
end
end
puts "Portfile is #{portfile}"
end
# It may seem odd to package tpkg with tpkg, but if users want to
# program against the tpkg library it is handy for them to be able to
# install and depend on the library along with other tpkgs.
# In order to reduce confusion this package does not contain any of the
# executables that go in the normal packages.
desc 'Build tpkg of tpkg library'
task :tpkgpkg do
#
# Create package file structure in build root
#
rm_rf(BUILDROOT)
libdir = ENV['libdir'].nil?? File.join('root', 'opt', 'tpkg', 'lib', 'site_ruby', '1.8') : File.join('root', ENV['libdir'])
copy_tpkg_files(BUILDROOT,
:libdir => libdir,
:copythirdparty => true)
#
# Prep tpkg.xml
#
File.open(File.join(BUILDROOT, 'tpkg.xml'), 'w') do |tpkgxml|
IO.foreach('tpkg.xml') do |line|
line.sub!('%VER%', TPKGVER)
tpkgxml.puts(line)
end
end
#
# Build the package
#
system("tpkg --make #{BUILDROOT}")
#
# Cleanup
#
rm_rf(BUILDROOT)
end