2019-09-06 00:39:11 +02:00
|
|
|
|
require "../backends.cr"
|
|
|
|
|
|
2021-03-02 15:42:17 +01:00
|
|
|
|
class Package::Backend::Packaging::APK < Package::Backend::Packaging
|
2019-09-06 00:39:11 +02:00
|
|
|
|
def initialize
|
|
|
|
|
@name = "apk"
|
|
|
|
|
end
|
|
|
|
|
|
2021-03-02 15:42:17 +01:00
|
|
|
|
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
|
|
|
|
|
|
2021-03-02 15:42:17 +01:00
|
|
|
|
APK.pkginfo package, "#{package.fake_root_directory}/.PKGINFO"
|
2019-09-06 00:39:11 +02:00
|
|
|
|
|
|
|
|
|
# Create data.tar.gz here.
|
2021-03-02 15:42:17 +01:00
|
|
|
|
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 shouldn’t have to be in users’ PATH. libexec?
|
2021-03-02 15:42:17 +01:00
|
|
|
|
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.
|
2021-03-02 15:42:17 +01:00
|
|
|
|
def self.pkginfo(package : ::Package::Package, file_name : String)
|
2021-02-28 20:56:51 +01:00
|
|
|
|
du = `du -sk #{package.fake_root_directory}`
|
2021-03-02 15:42:17 +01:00
|
|
|
|
size = du.sub(/[ \t].*/, "").to_u64 * 1024_u64
|
2021-02-28 20:56:51 +01:00
|
|
|
|
|
2021-03-02 15:42:17 +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" # This’ll need to be imported from Context.
|
|
|
|
|
file.puts "builddate = #{Time.utc.to_unix}"
|
2021-02-28 20:56:51 +01:00
|
|
|
|
|
2021-03-02 15:42:17 +01:00
|
|
|
|
package.dependencies.each do |atom|
|
|
|
|
|
file.puts "depend = #{atom.to_s}"
|
|
|
|
|
end
|
2021-02-28 20:56:51 +01:00
|
|
|
|
|
2021-03-02 15:42:17 +01:00
|
|
|
|
package.provides.each do |atom|
|
|
|
|
|
file.puts "provides = #{atom.to_s}"
|
|
|
|
|
end
|
2021-02-28 20:56:51 +01:00
|
|
|
|
|
2021-03-02 15:42:17 +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
|
|
|
|
|
|