Class: FPM::Package::Pacman

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

Constant Summary collapse

COMPRESSION_TYPES =

The list of supported compression types. Default is xz (LZMA2)

[ "gz", "bzip2", "xz", "zstd", "none" ]

Instance Attribute Summary

Attributes inherited from FPM::Package

#attributes, #attrs, #category, #conflicts, #description, #directories, #epoch, #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, option, #script, #staging_path, #type, type, types

Methods included from Util

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

Constructor Details

#initialize(*args) ⇒ Pacman

Returns a new instance of Pacman.


32
33
34
35
# File 'lib/fpm/package/pacman.rb', line 32

def initialize(*args)
  super(*args)
  attributes[:pacman_optional_depends] = []
end

Instance Method Details

#architectureObject

def initialize


37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/fpm/package/pacman.rb', line 37

def architecture
  case @architecture
    when nil
      return %x{uname -m}.chomp   # default to current arch
    when "amd64" # debian and pacman disagree on architecture names
      return "x86_64"
    when "native"
      return %x{uname -m}.chomp   # 'native' is current arch
    when "all", "any", "noarch"
      return "any"
    else
      return @architecture
  end
end

#compression_endingObject


229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/fpm/package/pacman.rb', line 229

def compression_ending
  case self.attributes[:pacman_compression]
    when nil, "zstd"
      return ".zst"
    when "none"
      return ""
    when "gz"
      return ".gz"
    when "zx"
      return ".xz"
    when "bzip2"
      return ".bz2"
    when "zstd"
      return ".zst"
    else
      return ".zst"
    end
end

#compression_optionObject

def input


210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/fpm/package/pacman.rb', line 210

def compression_option
  case self.attributes[:pacman_compression]
    when nil, "zstd"
      return "--zstd"
    when "none"
      return ""
    when "gz"
      return "-z"
    when "xz"
      return "--xz"
    when "bzip2"
      return "-j"
    when "zstd"
      return "--zstd"
    else
      return "--zstd"
    end
end

#config_filesObject

def iteration


56
57
58
# File 'lib/fpm/package/pacman.rb', line 56

def config_files
  return @config_files || []
end

#data_tar_flagsObject

def output


293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
# File 'lib/fpm/package/pacman.rb', line 293

def data_tar_flags
  data_tar_flags = []
  if attributes[:pacman_use_file_permissions?].nil?
    if !attributes[:pacman_user].nil?
      if attributes[:pacman_user] == 'root'
        data_tar_flags += [ "--numeric-owner", "--owner", "0" ]
      else
        data_tar_flags += [ "--owner", attributes[:deb_user] ]
      end
    end

    if !attributes[:pacman_group].nil?
      if attributes[:pacman_group] == 'root'
        data_tar_flags += [ "--numeric-owner", "--group", "0" ]
      else
        data_tar_flags += [ "--group", attributes[:deb_group] ]
      end
    end
  end
  return data_tar_flags
end

#default_outputObject

def data_tar_flags


315
316
317
318
319
320
321
322
323
# File 'lib/fpm/package/pacman.rb', line 315

def default_output
  v = version
  v = "#{epoch}:#{v}" if epoch
  if iteration
    "#{name}_#{v}-#{iteration}_#{architecture}.#{type}"
  else
    "#{name}_#{v}_#{architecture}.#{type}"
  end
end

#dependenciesObject

def config_files


60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/fpm/package/pacman.rb', line 60

def dependencies
  bogus_regex = /[^\sA-Za-z0-9><[email protected]]/
  # Actually modifies depencies if they are not right
  bogus_dependencies = @dependencies.grep bogus_regex
  if bogus_dependencies.any?
    @dependencies.reject! { |a| a =~ bogus_regex }
    logger.warn("Some of the dependencies looked like they weren't package " \
                "names. Such dependency entries only serve to confuse arch. " \
                "I am removing them.",
                :removed_dependencies => bogus_dependencies,
                :fixed_dependencies => @dependencies)
  end
  return @dependencies
end

#input(pacman_pkg_path) ⇒ Object

Add a new source to this package. The exact behavior depends on the kind of package being managed.

For instance:

  • for FPM::Package::Dir, << expects a path to a directory or files.

  • for FPM::Package::RPM, << expects a path to an rpm.

The idea is that you can keep pumping in new things to a package for later conversion or output.

Implementations are expected to put files relevant to the 'input' in the staging_path


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

def input(pacman_pkg_path)
  control = {}
  # Unpack the control tarball
  safesystem(tar_cmd, "-C", staging_path, "-xf", pacman_pkg_path)
  pkginfo = staging_path(".PKGINFO")
  mtree = staging_path(".MTREE")
  install = staging_path(".INSTALL")

  control_contents = File.read(pkginfo)
  FileUtils.rm(pkginfo)
  FileUtils.rm(mtree)


  control_lines = control_contents.split("\n")
  control_lines.each do |line|
    key, val = line.split(/ += +/, 2)
    if control.has_key? key
      control[key].push(val)
    else
      control[key] = [val]
    end
  end

  self.name = control["pkgname"][0]

  # Parse 'epoch:version-iteration' in the version string
  version_re = /^(?:([0-9]+):)?(.+?)(?:-(.*))?$/
  m = version_re.match(control["pkgver"][0])
  if !m
    raise "Unsupported version string '#{control["pkgver"][0]}'"
  end
  self.epoch, self.version, self.iteration = m.captures

  self.maintainer = control["packager"][0]

  # Arch has no notion of vendor, so...
  #self.vendor =

  self.url = control["url"][0]
  # Groups could include more than one.
  # Speaking of just taking the first entry of the field:
  # A crude thing to do, but I suppose it's better than nothing.
  # -- Daniel Haskin, 3/24/2015
  self.category = control["group"] && control["group"][0] || self.category

  # Licenses could include more than one.
  # Speaking of just taking the first entry of the field:
  # A crude thing to do, but I suppose it's better than nothing.
  # -- Daniel Haskin, 3/24/2015
  self.license = control["license"][0] || self.license

  self.architecture = control["arch"][0]

  self.dependencies = control["depend"] || self.dependencies

  self.provides = control["provides"] || self.provides

  self.conflicts = control["conflict"] || self.conflicts

  self.replaces = control["replaces"] || self.replaces

  self.description = control["pkgdesc"][0]

  if control.include? "backup"
    self.config_files = control["backup"].map{|file| "/" + file}
  else
    self.config_files = []
  end

  self.dependencies = control["depend"] || self.dependencies
  
  if attributes[:no_auto_depends?]
    self.dependencies = []
  end

  self.attributes[:pacman_optional_depends] = control["optdepend"] || []
  # There are other available attributes, but I didn't include them because:
  # - makedepend: deps needed to make the arch package. But it's already
  #   made. It just needs to be converted at this point
  # - checkdepend: See above
  # - makepkgopt: See above
  # - size: can be dynamically generated
  # - builddate: Should be changed to time of package conversion in the new
  #   package, so this value should be thrown away.

  if File.exist?(install)
    functions = parse_install_script(install)
    if functions.include?("pre_install")
      self.scripts[:before_install] = functions["pre_install"].join("\n")
    end
    if functions.include?("post_install")
      self.scripts[:after_install] = functions["post_install"].join("\n")
    end
    if functions.include?("pre_upgrade")
      self.scripts[:before_upgrade] = functions["pre_upgrade"].join("\n")
    end
    if functions.include?("post_upgrade")
      self.scripts[:after_upgrade] = functions["post_upgrade"].join("\n")
    end
    if functions.include?("pre_remove")
      self.scripts[:before_remove] = functions["pre_remove"].join("\n")
    end
    if functions.include?("post_remove")
      self.scripts[:after_remove] = functions["post_remove"].join("\n")
    end
    FileUtils.rm(install)
  end

  # Note: didn't use `self.directories`.
  # Pacman doesn't really record that information, to my knowledge.

end

#iterationObject

def architecture


52
53
54
# File 'lib/fpm/package/pacman.rb', line 52

def iteration
  return @iteration || 1
end

#output(output_path) ⇒ Object

Output this package to the given path.


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

def output(output_path)
  output_check(output_path)

  # Copy all files from staging to BUILD dir
  Find.find(staging_path) do |path|
    src = path.gsub(/^#{staging_path}/, '')
    dst = build_path(src)
    begin
      copy_entry(path, dst, preserve=true, remove_destination=true)
    rescue
      copy_entry(path, dst, preserve=false, remove_destination=true)
    end
    (path, dst)
  end

  # This value is used later in the template for PKGINFO
  size = safesystemout("du", "-sk", build_path).split(/\s+/)[0].to_i * 1024
  builddate = Time.new.to_i

  pkginfo = template("pacman.erb").result(binding)
  pkginfo_file = build_path(".PKGINFO")
  File.write(pkginfo_file, pkginfo)

  if script?(:before_install) or script?(:after_install) or \
      script?(:before_upgrade) or script?(:after_upgrade) or \
      script?(:before_remove) or script?(:after_remove)
    install_script = template("pacman/INSTALL.erb").result(binding)
    install_script_file = build_path(".INSTALL")
    File.write(install_script_file, install_script)
  end

  generate_mtree

  File.expand_path(output_path).tap do |path|
    ::Dir.chdir(build_path) do
      safesystem(*([tar_cmd,
                    compression_option,
                    "-cf",
                    path] + data_tar_flags + \
                    ::Dir.entries(".").reject{|entry| entry =~ /^\.{1,2}$/ }))
    end
  end
end

#to_s(format = nil) ⇒ Object


327
328
329
330
331
# File 'lib/fpm/package/pacman.rb', line 327

def to_s(format=nil)
  # Default format if nil
  # git_1.7.9.3-1-amd64.pkg.tar.xz
  return super(format.nil? ? "NAME-FULLVERSION-ARCH.EXTENSION" : format)
end

#to_s_extensionObject

def default_output


325
# File 'lib/fpm/package/pacman.rb', line 325

def to_s_extension; "pkg.tar#{compression_ending}"; end