Class: Ian::Packager

Inherits:
Object
  • Object
show all
Defined in:
lib/ian/packager.rb

Instance Method Summary collapse

Constructor Details

#initialize(path, ctrl, log) ⇒ Packager

Returns a new instance of Packager.



6
7
8
9
10
11
# File 'lib/ian/packager.rb', line 6

def initialize(path, ctrl, log)
  @path = path  # this is the source path that the files to package are copied from
  @ctrl = ctrl
  @log  = log
  @dir  = nil   # this is the tmp directory that the package is built from
end

Instance Method Details

#buildObject

build the package out of the temp dir



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/ian/packager.rb', line 65

def build
  @log.info "Packaging files"
  pkgdir = File.join(@path, "pkg")
  FileUtils.mkdir_p pkgdir

  FileUtils.chmod(0755, Dir["#{Ian.debpath(@dir)}/*"])
  FileUtils.chmod(0755, Ian.debpath(@dir))

  pkg    = File.join(pkgdir, "#{pkgname}.deb")
  output = %x[fakeroot dpkg-deb -b #{@dir} #{pkg}]

  return [$?.success?, pkg, output]
end

#copy_contentsObject

copy the contents to a tmp dir



37
38
39
40
41
42
43
44
# File 'lib/ian/packager.rb', line 37

def copy_contents
  cmd = rsync_cmd

  @log.debug "Copying contents with: #{cmd}"

  %x[#{cmd}]
  $?.success?
end

#move_root_filesObject

move extraneous stuff like README and CHANGELOG to /usr/share/doc



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/ian/packager.rb', line 47

def move_root_files
  docs  = "#{@dir}/usr/share/doc/#{@ctrl[:package]}"
  files = Dir.entries(@dir).select {|f| !File.directory?(f) }
  return unless files.any?

  FileUtils.mkdir_p(docs)

  # move all the files from the root of the package
  files.each do |file|
    file = File.join(@dir, file)
    next unless File.exist?(file)

    FileUtils.mv(file, docs)
    @log.info "#{file} => usr/share/doc/#{pkgname}"
  end
end

#runObject

run the packager



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ian/packager.rb', line 14

def run
  @dir = Dir.mktmpdir

  success = copy_contents

  if success
    @log.info("Copied files for packaging to #{@dir}")
  else
    raise StandardError, "Failed to copy files for packaging"
  end

  move_root_files
  generate_md5sums
  success, pkg, output = *build

  raise RuntimeError, "Failed to build package: #{output}" unless success

  pkg
ensure
  FileUtils.rm_rf @dir if File.exist? @dir
end