Class: FPM::Fry::Recipe::PackageRecipe

Inherits:
Object
  • Object
show all
Defined in:
lib/fpm/fry/recipe.rb

Constant Summary collapse

SYNTAX_CHECK_SHELLS =
['/bin/sh','/bin/bash', '/bin/dash']

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePackageRecipe

Returns a new instance of PackageRecipe.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/fpm/fry/recipe.rb', line 41

def initialize
  @name = nil
  @iteration = nil
  @version = '0.0.0'
  @maintainer = nil
  @vendor = nil
  @depends = {}
  @provides = {}
  @conflicts = {}
  @replaces = {}
  @scripts = {
    before_install: [],
    after_install:  [],
    before_remove:  [],
    after_remove:   []
  }
  @output_hooks = []
  @files = []
end

Instance Attribute Details

#conflictsObject

Returns the value of attribute conflicts.



25
26
27
# File 'lib/fpm/fry/recipe.rb', line 25

def conflicts
  @conflicts
end

#dependsObject Also known as: dependencies

Returns the value of attribute depends.



25
26
27
# File 'lib/fpm/fry/recipe.rb', line 25

def depends
  @depends
end

#filesObject

Returns the value of attribute files.



25
26
27
# File 'lib/fpm/fry/recipe.rb', line 25

def files
  @files
end

#iterationObject

Returns the value of attribute iteration.



25
26
27
# File 'lib/fpm/fry/recipe.rb', line 25

def iteration
  @iteration
end

#maintainerObject

Returns the value of attribute maintainer.



25
26
27
# File 'lib/fpm/fry/recipe.rb', line 25

def maintainer
  @maintainer
end

#nameObject

Returns the value of attribute name.



25
26
27
# File 'lib/fpm/fry/recipe.rb', line 25

def name
  @name
end

#output_hooksObject

Returns the value of attribute output_hooks.



25
26
27
# File 'lib/fpm/fry/recipe.rb', line 25

def output_hooks
  @output_hooks
end

#providesObject

Returns the value of attribute provides.



25
26
27
# File 'lib/fpm/fry/recipe.rb', line 25

def provides
  @provides
end

#recommendsObject

Returns the value of attribute recommends.



25
26
27
# File 'lib/fpm/fry/recipe.rb', line 25

def recommends
  @recommends
end

#replacesObject

Returns the value of attribute replaces.



25
26
27
# File 'lib/fpm/fry/recipe.rb', line 25

def replaces
  @replaces
end

#scriptsObject

Returns the value of attribute scripts.



25
26
27
# File 'lib/fpm/fry/recipe.rb', line 25

def scripts
  @scripts
end

#suggestsObject

Returns the value of attribute suggests.



25
26
27
# File 'lib/fpm/fry/recipe.rb', line 25

def suggests
  @suggests
end

#vendorObject

Returns the value of attribute vendor.



25
26
27
# File 'lib/fpm/fry/recipe.rb', line 25

def vendor
  @vendor
end

#versionObject

Returns the value of attribute version.



25
26
27
# File 'lib/fpm/fry/recipe.rb', line 25

def version
  @version
end

Instance Method Details

#apply_output(package) ⇒ Object Also known as: apply



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/fpm/fry/recipe.rb', line 63

def apply_output( package )
  package.name = name
  package.version = version
  package.iteration = iteration
  package.maintainer = maintainer if maintainer
  package.vendor = vendor if vendor
  scripts.each do |type, scripts|
    package.scripts[type] = scripts.join("\n") if scripts.any?
  end
  [:dependencies, :conflicts, :replaces, :provides].each do |sym|
    send(sym).each do |name, options|
      constr = Array(options[:constraints])
      if constr.any?
        constr.each do | c |
          package.send(sym) << "#{name} #{c}"
        end
      else
        package.send(sym) << name
      end
    end
  end
  output_hooks.each{|h| h.call(self, package) }
  return package
end

#lintObject



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
# File 'lib/fpm/fry/recipe.rb', line 92

def lint
  problems = []
  problems << "Name is empty." if name.to_s == ''
  scripts.each do |type,scripts|
    next if scripts.none?
    s = scripts.join("\n")
    if s == ''
      problems << "#{type} script is empty. This will produce broken packages."
      next
    end
    m = /\A#!([^\n]+)\n/.match(s)
    if !m
      problems << "#{type} script doesn't have a valid shebang"
      next
    end
    begin
      args = m[1].shellsplit
    rescue ArgumentError => e
      problems << "#{type} script doesn't have a valid command in shebang"
    end
    if SYNTAX_CHECK_SHELLS.include? args[0]
      sin, sout, serr, th = Open3.popen3(args[0],'-n')
      sin.write(s)
      sin.close
      if th.value.exitstatus != 0
        problems << "#{type} script is not valid #{args[0]} code: #{serr.read.chomp}"
      end
      serr.close
      sout.close
    end
  end
  return problems
end