Class: Depot::DebPackage

Inherits:
Object
  • Object
show all
Defined in:
lib/depot/packages/deb.rb

Defined Under Namespace

Classes: FormatError

Constant Summary collapse

SCRIPT_NAMES =
%w[preinst postinst prerm postrm config].freeze
DESKTOP_PATH =
%r{\A(?:\./)?usr/share/applications/[^/]+\.desktop\z}
ICON_PATH =
%r{/icons/hicolor/([^/]+)/apps/([^/]+)\.(png|svg|xpm)\z}i

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ DebPackage

Returns a new instance of DebPackage.



16
17
18
# File 'lib/depot/packages/deb.rb', line 16

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



14
15
16
# File 'lib/depot/packages/deb.rb', line 14

def path
  @path
end

Instance Method Details

#ar_membersObject



81
82
83
# File 'lib/depot/packages/deb.rb', line 81

def ar_members
  @ar_members ||= parse_ar.keys
end

#control_archive_nameObject



73
74
75
# File 'lib/depot/packages/deb.rb', line 73

def control_archive_name
  @control_archive_name ||= archive_name("control.tar")
end

#control_fieldsObject



30
31
32
# File 'lib/depot/packages/deb.rb', line 30

def control_fields
  @control_fields ||= parse_control(read_control_file("control").to_s)
end

#control_membersObject



34
35
36
# File 'lib/depot/packages/deb.rb', line 34

def control_members
  @control_members ||= list_tar(control_archive_name)
end

#data_archive_nameObject



77
78
79
# File 'lib/depot/packages/deb.rb', line 77

def data_archive_name
  @data_archive_name ||= archive_name("data.tar")
end

#data_membersObject



38
39
40
# File 'lib/depot/packages/deb.rb', line 38

def data_members
  @data_members ||= list_tar(data_archive_name)
end

#debian_binaryObject



26
27
28
# File 'lib/depot/packages/deb.rb', line 26

def debian_binary
  member("debian-binary")&.strip
end

#desktop_entriesObject



48
49
50
51
# File 'lib/depot/packages/deb.rb', line 48

def desktop_entries
  data_members.map { |entry| clean_entry(entry) }
              .select { |entry| entry.end_with?(".desktop") }
end

#executable_entriesObject



67
68
69
70
71
# File 'lib/depot/packages/deb.rb', line 67

def executable_entries
  data_members.map { |entry| clean_entry(entry) }
              .select { |entry| entry.start_with?("usr/bin/", "usr/local/bin/", "opt/") }
              .reject { |entry| entry.end_with?("/") }
end

#extract_data_to(destination) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/depot/packages/deb.rb', line 89

def extract_data_to(destination)
  FileUtils.mkdir_p(destination)
  assert_safe_entries!(data_members)
  with_member_file(data_archive_name) do |archive|
    stdout, stderr, status = Open3.capture3(
      "tar",
      *tar_options(data_archive_name),
      "-xf",
      archive,
      "-C",
      destination
    )
    raise FormatError, "Could not extract data archive: #{stderr.empty? ? stdout : stderr}" unless status.success?
  end
end

#icon_entriesObject



57
58
59
60
# File 'lib/depot/packages/deb.rb', line 57

def icon_entries
  data_members.map { |entry| clean_entry(entry) }
              .select { |entry| entry.match?(ICON_PATH) }
end

#image_entriesObject



62
63
64
65
# File 'lib/depot/packages/deb.rb', line 62

def image_entries
  data_members.map { |entry| clean_entry(entry) }
              .select { |entry| entry.match?(/\.(png|svg|xpm)\z/i) }
end

#maintainer_scriptsObject



42
43
44
45
46
# File 'lib/depot/packages/deb.rb', line 42

def maintainer_scripts
  control_members.map { |entry| clean_entry(entry) }
                 .select { |entry| SCRIPT_NAMES.include?(File.basename(entry)) }
                 .uniq
end

#primary_desktop_entryObject



53
54
55
# File 'lib/depot/packages/deb.rb', line 53

def primary_desktop_entry
  desktop_entries.min_by { |entry| desktop_score(entry) }
end

#read_data_entry(entry) ⇒ Object



85
86
87
# File 'lib/depot/packages/deb.rb', line 85

def read_data_entry(entry)
  read_tar_entry(data_archive_name, entry)
end

#valid?Boolean

Returns:

  • (Boolean)


20
21
22
23
24
# File 'lib/depot/packages/deb.rb', line 20

def valid?
  debian_binary && control_archive_name && data_archive_name
rescue FormatError
  false
end