Class: Pallet::Deb

Inherits:
Object
  • Object
show all
Defined in:
lib/pallet/deb.rb

Constant Summary collapse

POLICY_VERSION =

The latest version of the Debian policy we’re compliant with.

'3.7.2.2'
BUILD_DIR =

Location of the source package et al.

'debian'
TEMPLATE_LOCATION =

Filesystem location of template files

File.join(File.dirname(__FILE__), *%w{.. .. share debian}),
  File.join(*%w{/ usr share pallet debian})
].find {|f| File.directory? f }
PALLET_DEPENDS =

A list of all build dependencies required by pallet.

["pallet (>= #{Pallet::VERSION})"] << %w{rake}
PALLET_SUGGESTS =
['fakeroot']

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pallet, task_name = 'deb') {|_self| ... } ⇒ Deb

Creates a new specification for building a deb. Yields itself to the block passed for further initialization. Must be passed an instance of the pallet with information such as version, author, package name, etc. already configured.

Can be passed a hash whose key is the pallet, and whose value is either an array of Rake tasks this task depends on, or a single dependent Rake task.

# creates a new Pallet::Deb packager
p.packages << Pallet::Deb.new(p)

# creates a new Pallet::Deb packager, that depends on other tasks
p.packages << Pallet::Deb.new(p => [:build, :doc])

# changes the task name to 'package:debian'
p.packages << Pallet::Deb.new(p, 'debian')

Yields:

  • (_self)

Yield Parameters:

  • _self (Pallet::Deb)

    the object that the method was called on



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
# File 'lib/pallet/deb.rb', line 119

def initialize(pallet, task_name = 'deb')

  @pallet, self.prerequisites = deconstruct_hash(pallet)

  self.task_name     = task_name

  # file locations
  self.files         = []
  self.docs          = []
  self.configs       = []
  self.scripts       = {}
  
  # package flags
  self.architecture  = 'all'
  self.distribution  = 'unstable'
  self.priority      = 'extra'
  self.section       = 'misc'
  self.urgency       = 'low'

  # dependencies
  self.build_depends = []
  self.depends       = []
  self.recommends    = []
  self.suggests      = []
  self.conflicts     = []
  self.provides      = []
  self.enhances      = []

  # send me off to be configured
  yield self if block_given?

  # get rid of changelog, copyright if user specified them in docs
  # self.docs.delete(self.changelog)
  # self.docs.delete(self.copyright)

end

Instance Attribute Details

#architectureObject

The machine architecture the package can be built to support. Defaults to ‘all’, which indicates that the project is machine-independent. Should be changed to ‘any’ if the project requires compilation to machine language, but should run on any architecture.



61
62
63
# File 'lib/pallet/deb.rb', line 61

def architecture
  @architecture
end

#build_dependsObject

An array of Debian build dependencies needed in order to build the package for this project. Will always include any dependencies implied by pallet.



15
16
17
# File 'lib/pallet/deb.rb', line 15

def build_depends
  @build_depends
end

#changelogObject

The location on the filesystem of the Debian-style project changelog. One will be created for you if it is not specified.



65
66
67
# File 'lib/pallet/deb.rb', line 65

def changelog
  @changelog
end

#configsObject

TODO: yeah…



50
51
52
# File 'lib/pallet/deb.rb', line 50

def configs
  @configs
end

#conflictsObject

An array of Debian conflicting packages.



27
28
29
# File 'lib/pallet/deb.rb', line 27

def conflicts
  @conflicts
end

The location of the package’s copyright. Must be present.



68
69
70
# File 'lib/pallet/deb.rb', line 68

def copyright
  @copyright
end

#dependsObject

An array of Debian dependencies.



18
19
20
# File 'lib/pallet/deb.rb', line 18

def depends
  @depends
end

#distributionObject

The distribution this package should be installed in. Defaults to ‘unstable’.



79
80
81
# File 'lib/pallet/deb.rb', line 79

def distribution
  @distribution
end

#docsObject

An enumerable object containing a list of all project documentation to include in the Debian package. If a directory is specified in the list, all files under that directory will be included as documentation. TODO: blah



47
48
49
# File 'lib/pallet/deb.rb', line 47

def docs
  @docs
end

#enhancesObject

An array of Debian packages this package enhances.



33
34
35
# File 'lib/pallet/deb.rb', line 33

def enhances
  @enhances
end

#filesObject

A hash with each key being a file glob, and each value being the destination directory of files matching that glob. Do not include files specified in changelog, copyright, docs, scripts, or

TODO: flesh out meaning



41
42
43
# File 'lib/pallet/deb.rb', line 41

def files
  @files
end

#prerequisitesObject

A list of prerequisite tasks that will be completed before the packaging task starts.



10
11
12
# File 'lib/pallet/deb.rb', line 10

def prerequisites
  @prerequisites
end

#priorityObject

The priority level of the package. Defaults to ‘extra’.



82
83
84
# File 'lib/pallet/deb.rb', line 82

def priority
  @priority
end

#providesObject

An array of Debian features this package provides.



30
31
32
# File 'lib/pallet/deb.rb', line 30

def provides
  @provides
end

#recommendsObject

An array of Debian recommended packages.



21
22
23
# File 'lib/pallet/deb.rb', line 21

def recommends
  @recommends
end

#scriptsObject

A hash pointing to the location of scripts the Debian package should include. # TODO: flesh this out



54
55
56
# File 'lib/pallet/deb.rb', line 54

def scripts
  @scripts
end

#sectionObject

The section the package has been classified into. Defaults to ‘misc’. See the Debian Policy Manual for more information.



75
76
77
# File 'lib/pallet/deb.rb', line 75

def section
  @section
end

#suggestsObject

An array of Debian suggested packages.



24
25
26
# File 'lib/pallet/deb.rb', line 24

def suggests
  @suggests
end

#task_nameObject

The name the generated rake task will use. Defaults to ‘deb’.



6
7
8
# File 'lib/pallet/deb.rb', line 6

def task_name
  @task_name
end

#urgencyObject

The urgency of the package. Defaults to ‘low’.



71
72
73
# File 'lib/pallet/deb.rb', line 71

def urgency
  @urgency
end

Instance Method Details

#defineObject



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
# File 'lib/pallet/deb.rb', line 156

def define

  desc 'Build this project into a Debian package'
  task self.task_name => [ "#{self.task_name}:clean",
                           "#{self.task_name}:build",
                           "#{self.task_name}:package", ]
  
  namespace self.task_name do
  
    # perform the actual package build
    task :build => self.prerequisites

    # package the project
    task :package => %w{dh:testdir    dh:testroot
                        dh:install    dh:installdocs
                        dh:installchangelogs
                        dh:compress   dh:installdeb
                        dh:gencontrol} do
      mkdir Pallet::PACKAGE_DIR unless File.directory?(Pallet::PACKAGE_DIR)
      system *%W{dpkg-deb --build #{path_for(:bpkg)} #{path_for(:pkg)}}
    end

    desc 'Clean the Debian build tree'
    task :clean => %w{dh:clean}

    desc 'Remove all Debian files generated by pallet'
    task :clobber do
      rm_r path_for(:spkg) if File.exist? path_for(:pstamp)
    end
 
    namespace :dh do

      # perform a clean of the entire debian tree
      task :clean => %w{testdir testroot} do
        rm_r path_for(:bpkg), :force => true
        rm path_for(:spkg, 'files'), :force => true
      end

      # become fakeroot if not root already; god this is evil
      task :testroot do
        unless Process.uid == 0
          begin
            exec("fakeroot #{$0} #{ARGV.join(' ')}")
          rescue Errno::ENOENT => ex
            fail("              |fakeroot must be installed if packaging is not\n              |performed as root\n            MESSAGE\n          end\n        end\n      end\n\n      # ensure that we're in the proper directory\n      task :testdir => path_for(:spkg)\n\n      # install binary package directory\n      task :install => path_for(:bpkg)\n\n      # install changelogs\n      task :installchangelogs => path_for(:docs, 'changelog.Debian')\n\n      # install documentation directory\n      task :installdocs => path_for(:docs)\n\n      # compress non-html, non-css, non-compressed files \n      task :compress => [ path_for(:docs), path_for(:man), path_for(:info) ] do\n        [:docs, :man, :info].each do |doc|\n          Dir[path_for(doc, '*')].each do |filename|\n            next unless File.file?(filename)\n            next if File.size(filename) < 4096\n            next if filename =~ %r{\\.(html|css)$}\n            next if filename =~ %r{\\.(bz2|gz|zip)$}\n            next if filename =~ %r{changelog}\n            File.open(filename) do |f|\n              Zlib::GzipWriter.open(\"\#{filename}.gz\") do |gz|\n                gz.write f.read\n              end\n            end\n            File.unlink filename\n          end\n        end\n      end\n\n      task :fixperms do\n        [:docs, :man].each do |doc|\n          Dir[path_for(doc, '**', '*')].each do |f|\n            dirs, files = f.partition {|f| File.directory?(f) }\n            chown 'root', 'root', dirs\n            chown 'root', 'root', files\n          end\n        end\n        Dir[path_for(:bpkg, '**', '*')].each do |f|\n          mode = File.stat(f)\n          case\n            when File.dirname(f) =~ %r{/bin/}       then chmod(f, mode & 0755)\n            when File.dirname(f) =~ %r{/usr/games}  then chmod(f, mode & 0755)\n            when File.dirname(f) =~ %r{/etc/init.d} then chmod(f, mode & 0755)\n            when File.directory?(f)                 then chmod(f, mode & 0755)\n            else                                         chmod(f, mode & 0644)\n          end\n        end\n      end\n\n      task :installdeb => path_for(:ctrl)\n\n      task :gencontrol => path_for(:ctrl, 'control')\n      \n    end\n\n    # debian/\n    file path_for(:spkg) do\n      mkdir path_for(:spkg)\n      touch path_for(:pstamp)\n      install self.changelog, path_for(:spkg, 'changelog') if self.changelog\n      install self.copyright, path_for(:spkg, 'copyright') \\\n        rescue raise ArgumentError, 'copyright file must be present'\n      inflate_templates(path_for(:spkg), *Dir[path_for(:stmpl, '*')])\n    end\n\n    # debian/foo\n    file path_for(:bpkg) => path_for(:spkg) do\n      mkdir_p path_for(:bpkg)\n      files.each {|i| i.install(path_for(:bpkg)) }\n    end\n\n    # debian/foo/usr/share/doc/foo\n    file path_for(:docs) => path_for(:bpkg) do\n      mkdir_p path_for(:docs)\n      install path_for(:spkg, 'copyright'), path_for(:docs, 'copyright')\n      docs.each {|i| i.install(path_for(:docs)) }\n    end\n    \n    # debian/foo/usr/share/doc/foo/changelog.Debian\n    file path_for(:docs, 'changelog.Debian') => path_for(:docs) do\n      install path_for(:spkg, 'changelog'), path_for(:docs, 'changelog.Debian')\n    end\n\n    # man/info\n    file path_for(:man)\n    file path_for(:info)\n\n    # debian/foo/DEBIAN\n    file path_for(:ctrl) => path_for(:bpkg) do\n      mkdir_p path_for(:ctrl)\n      [:postinst, :preinst, :postrm, :prerm].each do |script|\n        cp scripts[script], path_for(:ctrl) if scripts[script]\n      end\n      File.open(path_for(:ctrl, 'conffiles'), 'w') do |f|\n        # cd into the directory, so filelists from this location will\n        # be accurate\n        chdir(path_for(:bpkg)) do\n          files = (Dir['etc/**/*'] + configs.to_a).find_all {|f| File.file? f }\n          f.write files.join(\"\\n\")\n        end\n      end\n    end\n\n    # debian/foo/DEBIAN/control\n    file path_for(:ctrl, 'control') => path_for(:ctrl) do\n      system *%W{dpkg-gencontrol -Pdebian/\#{@pallet.name} -p\#{@pallet.name}}\n    end\n\n  end\n\n  # have clean/clobber depend on our custom clean/clobber\n  task :clean   => \"\#{self.task_name}:clean\"\n  task :clobber => \"\#{self.task_name}:clobber\"\n\nend\n".margin.gsub(%r{\n}, ' '))