This repository has been archived on 2022-01-17. You can view files and clone it, but cannot push or open issues/pull-requests.
packaging/src/backends/apk.cr

73 lines
2.1 KiB
Crystal
Raw Permalink Normal View History

2019-09-06 00:39:11 +02:00
require "../backends.cr"
class Package::Backend::Packaging::APK < Package::Backend::Packaging
2019-09-06 00:39:11 +02:00
def initialize
@name = "apk"
end
def package(pkgdir : String, architecture : String, package : ::Package::Package) : Bool
2019-09-06 00:39:11 +02:00
# FIXME: This needs to have access to architecture (from Context?)
# to work properly.
old_cwd = Dir.current
APK.pkginfo package, "#{package.fake_root_directory}/.PKGINFO"
2019-09-06 00:39:11 +02:00
# Create data.tar.gz here.
package_target = "#{pkgdir}/"
package_target += "#{architecture}/"
package_target += "#{package.name}-#{package.version}-r#{package.release}.apk"
2019-09-06 00:39:11 +02:00
Dir.mkdir_p File.dirname package_target
# FIXME: This shouldnt have to be in users PATH. libexec?
r = Do.run package.fake_root_directory, "#{OWN_LIBEXEC_DIR}/assemble-apk.sh", [
2019-09-06 00:39:11 +02:00
package_target
]
r.exit_status == 0
end
2021-02-28 20:56:51 +01:00
# This generated file content is specific to the Apk package manager.
def self.pkginfo(package : ::Package::Package, file_name : String)
2021-02-28 20:56:51 +01:00
du = `du -sk #{package.fake_root_directory}`
size = du.sub(/[ \t].*/, "").to_u64 * 1024_u64
2021-02-28 20:56:51 +01:00
File.open file_name, "w" do |file|
file.puts "# Generated by `packaging`."
file.puts "pkgname = #{package.name}"
file.puts "pkgver = #{package.version}-r#{package.release}"
file.puts "url = #{package.url || ""} "
file.puts "size = #{size}"
file.puts "origin = #{package.recipe.name}"
file.puts "buildtype = host" # Thisll need to be imported from Context.
file.puts "builddate = #{Time.utc.to_unix}"
2021-02-28 20:56:51 +01:00
package.dependencies.each do |atom|
file.puts "depend = #{atom.to_s}"
end
2021-02-28 20:56:51 +01:00
package.provides.each do |atom|
file.puts "provides = #{atom.to_s}"
end
2021-02-28 20:56:51 +01:00
package.conflicts.each do |atom|
file.puts "conflicts = #{atom.to_s}"
end
2021-02-28 20:56:51 +01:00
end
end
# Install programs.
def self.install(packages : Array(String))
opts = ["add"] + (ENV["APK_FLAGS"]? || "-i").split(/[ \t]+/) + packages
puts "+ apk #{opts.join " "}"
r = Process.run "apk", opts,
output: Process::Redirect::Inherit,
input: Process::Redirect::Inherit,
error: Process::Redirect::Inherit
if r.exit_status != 0
STDERR.puts "!! Running apk failed!"
exit 8
end
end
2019-09-06 00:39:11 +02:00
end