mirror of
https://github.com/chromebrew/chromebrew.git
synced 2026-01-08 23:18:10 -05:00
34 lines
1.2 KiB
Ruby
34 lines
1.2 KiB
Ruby
require 'json'
|
|
require_relative 'const'
|
|
|
|
class PackageUtils
|
|
def self.installed?(pkg_name)
|
|
device_json = JSON.load_file(File.join(CREW_CONFIG_PATH, 'device.json'))
|
|
return device_json['installed_packages'].any? { |elem| elem['name'] == pkg_name }
|
|
end
|
|
|
|
def self.compatible?(pkg)
|
|
return pkg.compatibility.casecmp?('all') || pkg.compatibility.include?(ARCH)
|
|
end
|
|
|
|
def self.get_url(pkg, build_from_source: false)
|
|
if !build_from_source && pkg.binary_sha256&.key?(ARCH.to_sym)
|
|
return "https://gitlab.com/api/v4/projects/26210301/packages/generic/#{pkg.name}/#{pkg.version}_#{ARCH}/#{pkg.name}-#{pkg.version}-chromeos-#{ARCH}.#{pkg.binary_compression}"
|
|
elsif pkg.source_url.is_a?(Hash) && pkg.source_url&.key?(ARCH.to_sym)
|
|
return pkg.source_url[ARCH.to_sym]
|
|
else
|
|
return pkg.source_url
|
|
end
|
|
end
|
|
|
|
def self.get_sha256(pkg, build_from_source: false)
|
|
if !build_from_source && pkg.binary_sha256&.key?(ARCH.to_sym)
|
|
return pkg.binary_sha256[ARCH.to_sym]
|
|
elsif pkg.source_sha256.is_a?(Hash) && pkg.source_sha256&.key?(ARCH.to_sym)
|
|
return pkg.source_sha256[ARCH.to_sym]
|
|
else
|
|
return pkg.source_sha256
|
|
end
|
|
end
|
|
end
|