Class: FPM::Package::Puppet

Inherits:
FPM::Package show all
Defined in:
lib/fpm/package/puppet.rb

Instance Attribute Summary

Attributes inherited from FPM::Package

#attributes, #attrs, #category, #config_files, #conflicts, #dependencies, #description, #directories, #epoch, #iteration, #license, #maintainer, #name, #provides, #replaces, #scripts, #url, #vendor, #version

Instance Method Summary collapse

Methods inherited from FPM::Package

apply_options, #build_path, #cleanup, #cleanup_build, #cleanup_staging, #convert, #converted_from, default_attributes, #edit_file, #files, inherited, #initialize, #input, option, #output, #script, #staging_path, #to_s, #type, type, types

Methods included from Util

#ar_cmd, #ar_cmd_deterministic?, #copied_entries, #copy_entry, #copy_metadata, #default_shell, #erbnew, #execmd, #expand_pessimistic_constraints, #logger, #program_exists?, #program_in_path?, #safesystem, #safesystemout, #tar_cmd, #tar_cmd_supports_sort_names_and_set_mtime?

Constructor Details

This class inherits a constructor from FPM::Package

Instance Method Details

#architectureObject



9
10
11
12
13
14
15
# File 'lib/fpm/package/puppet.rb', line 9

def architecture
  case @architecture
  when nil, "native"
    @architecture = %x{uname -m}.chomp
  end
  return @architecture
end

#build!(params) ⇒ Object



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
# File 'lib/fpm/package/puppet.rb', line 52

def build!(params)
  # TODO(sissel): Support these somehow, perhaps with execs and files.
  self.scripts.each do |name, path|
    case name
      when "pre-install"
      when "post-install"
      when "pre-uninstall"
      when "post-uninstall"
    end # case name
  end # self.scripts.each

  if File.exist?(params[:output])
    # TODO(sissel): Allow folks to choose output?
    logger.error("Puppet module directory '#{params[:output]}' already " \
                  "exists. Delete it or choose another output (-p flag)")
  end

  ::Dir.mkdir(params[:output])
  builddir = ::Dir.pwd

  # Copy 'files' from builddir to :output/files
  Find.find("files", "manifests") do |path|
    logger.info("Copying path: #{path}")
    if File.directory?(path)
      ::Dir.mkdir(File.join(params[:output], path))
    else
      FileUtils.cp(path, File.join(params[:output], path))
    end
  end
end

#default_outputObject

The directory we create should just be the name of the package as the module name



85
86
87
# File 'lib/fpm/package/puppet.rb', line 85

def default_output
  name
end

#generate_specfile(builddir) ⇒ Object

Default specfile generator just makes one specfile, whatever that is for this package.



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
# File 'lib/fpm/package/puppet.rb', line 19

def generate_specfile(builddir)
  paths = []
  logger.info("PWD: #{File.join(builddir, unpack_data_to)}")
  fileroot = File.join(builddir, unpack_data_to)
  Dir.chdir(fileroot) do
    Find.find(".") do |p|
      next if p == "."
      paths << p
    end
  end
  logger.info(paths[-1])
  manifests = %w{package.pp package/remove.pp}

  ::Dir.mkdir(File.join(builddir, "manifests"))
  manifests.each do |manifest|
    dir = File.join(builddir, "manifests", File.dirname(manifest))
    logger.info("manifests targeting: #{dir}")
    ::Dir.mkdir(dir) if !File.directory?(dir)

    File.open(File.join(builddir, "manifests", manifest), "w") do |f|
      logger.info("manifest: #{f.path}")
      template = template(File.join("puppet", "#{manifest}.erb"))
      ::Dir.chdir(fileroot) do
        f.puts template.result(binding)
      end
    end
  end
end

#gid2group(gid) ⇒ Object

Helper for group lookup



109
110
111
112
113
114
115
116
117
118
# File 'lib/fpm/package/puppet.rb', line 109

def gid2group(gid)
  begin
    grent = Etc.getgrgid(gid)
    return grent.name
  rescue ArgumentError => e
    # Invalid user id? No user? Return the uid.
    logger.warn("Failed to find group for gid #{gid}")
    return gid.to_s
  end
end

#puppetsort(hash) ⇒ Object

This method is used by the puppet manifest template



90
91
92
93
94
# File 'lib/fpm/package/puppet.rb', line 90

def puppetsort(hash)
  # TODO(sissel): Implement sorting that follows the puppet style guide
  # Such as, 'ensure' goes first, etc.
  return hash.to_a
end

#uid2user(uid) ⇒ Object

Helper for user lookup



97
98
99
100
101
102
103
104
105
106
# File 'lib/fpm/package/puppet.rb', line 97

def uid2user(uid)
  begin
    pwent = Etc.getpwuid(uid)
    return pwent.name
  rescue ArgumentError => e
    # Invalid user id? No user? Return the uid.
    logger.warn("Failed to find username for uid #{uid}")
    return uid.to_s
  end
end

#unpack_data_toObject

def generate_specfile



48
49
50
# File 'lib/fpm/package/puppet.rb', line 48

def unpack_data_to
  "files"
end