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.0 KiB
Crystal
Raw Normal View History

2019-09-06 00:39:11 +02:00
require "../backends.cr"
class ApkBackend < Package::Backend::Packaging
def initialize
@name = "apk"
end
def package(context : Package::Context, 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
2021-02-28 20:56:51 +01:00
File.write "#{package.fake_root_directory}/.PKGINFO", ApkBackend.pkginfo package
2019-09-06 00:39:11 +02:00
# Create data.tar.gz here.
package_target = "#{context.packages_directory}/#{context.architecture}/#{package.name}-#{package.version}-r#{package.release}.apk"
Dir.mkdir_p File.dirname package_target
# FIXME: This shouldnt have to be in users PATH. libexec?
r = context.run package.fake_root_directory, "#{OWN_LIBEXEC_DIR}/assemble-apk.sh", [
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)
du = `du -sk #{package.fake_root_directory}`
size = du.sub(/[ \t].*/, "").to_i * 1024
lines = [] of String
lines << "# Generated by `packaging`."
lines << "pkgname = #{package.name}"
lines << "pkgver = #{package.version}-r#{package.release}"
lines << "url = #{package.url || ""} "
lines << "size = #{size}"
lines << "origin = #{package.recipe.name}"
lines << "buildtype = host" # Thisll need to be imported from Context.
lines << "builddate = #{Time.utc.to_unix}"
package.dependencies.each do |atom|
lines << "depend = #{atom.to_s}"
end
package.provides.each do |atom|
lines << "provides = #{atom.to_s}"
end
package.conflicts.each do |atom|
lines << "conflicts = #{atom.to_s}"
end
lines.join("\n") + "\n"
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