Class: Depot::Backends::Rpm

Inherits:
Object
  • Object
show all
Includes:
Support
Defined in:
lib/depot/backends/rpm.rb

Instance Method Summary collapse

Constructor Details

#initialize(store:) ⇒ Rpm

Returns a new instance of Rpm.



17
18
19
# File 'lib/depot/backends/rpm.rb', line 17

def initialize(store:)
  @store = store
end

Instance Method Details

#install(inspection, settings: {}) ⇒ Object



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
47
48
49
50
51
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
82
83
84
85
86
87
88
89
90
91
# File 'lib/depot/backends/rpm.rb', line 21

def install(inspection, settings: {})
  return Result.err("RPM backend cannot install #{inspection.format}") unless inspection.rpm?

  Paths.ensure_base_dirs
  package = RpmPackage.new(inspection.input)
  return Result.err("Invalid RPM package.") unless package.valid?

  app_id = Util.unique_id(Util.slug("#{package.display_name}-#{package.version_label}"), @store.ids)
  app_dir = File.join(Paths.apps_dir, app_id)
  root_dir = File.join(app_dir, "root")
  FileUtils.mkdir_p(app_dir)

  package.extract_to(root_dir)

  desktop_source = package.primary_desktop_entry
  desktop_contents = desktop_source && read_extracted_entry(root_dir, desktop_source)
  display_name = desktop_name(desktop_contents) || package.display_name
  preferred_icon = desktop_contents&.[]( /^Icon=(.+)$/, 1)&.strip
  icon_name = install_icons(package, root_dir, app_id, preferred_icon)
  executable = executable_for(package, root_dir, desktop_contents)

  desktop_path = nil
  if settings.fetch("desktop_integration", true) && executable
    desktop_path = File.join(Paths.desktop_entries_dir, "depot-#{app_id}.desktop")
    contents = desktop_contents ? rewrite_desktop(desktop_contents, root_dir, app_id, display_name, icon_name) : generated_desktop(app_id, display_name, executable, icon_name)
    File.write(desktop_path, contents)
  end

  warnings = inspection.warnings + portable_warnings(package, executable, desktop_source)
  manifest = {
    "schema_version" => 1,
    "app_id" => app_id,
    "display_name" => display_name,
    "default_display_name" => display_name,
    "backend" => "rpm-portable",
    "install_source" => File.expand_path(inspection.input),
    "source_sha256" => inspection.sha256,
    "source_size" => inspection.size,
    "installed_executable" => executable,
    "desktop_entry" => desktop_path,
    "icons" => installed_icon_paths(app_id, preferred_icon),
    "default_icon_name" => icon_name,
    "created_files" => [desktop_path].compact + installed_icon_paths(app_id, preferred_icon),
    "created_dirs" => [app_dir],
    "installed_at" => Time.now.utc.iso8601,
    "package" => package.package_fields.merge("Requires" => package.requires),
    "desktop_source" => desktop_source,
    "portable_root" => root_dir,
    "permissions" => {
      "executable" => executable ? File.executable?(executable) : false,
      "requires_sudo" => false,
      "writes_outside_depot" => false,
      "notes" => ["RPM payload extracted user-locally. RPM scriptlets were not executed."]
    },
    "sandbox" => {
      "enabled" => false,
      "preference" => settings.fetch("sandbox_preference", "ask")
    },
    "update" => {
      "mechanism" => "manual",
      "source" => File.expand_path(inspection.input)
    },
    "warnings" => warnings
  }

  manifest_path = @store.write(manifest)
  refresh_desktop_caches if settings.fetch("desktop_integration", true)
  Result.ok(manifest.merge("manifest_path" => manifest_path), warnings:)
rescue RpmPackage::FormatError, SystemCallError => e
  Result.err("RPM install failed: #{e.message}")
end