73 lines
2.1 KiB
Crystal
73 lines
2.1 KiB
Crystal
require "../backends.cr"
|
||
|
||
class Package::Backend::Packaging::APK < Package::Backend::Packaging
|
||
def initialize
|
||
@name = "apk"
|
||
end
|
||
|
||
def package(pkgdir : String, architecture : String, package : ::Package::Package) : Bool
|
||
# 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"
|
||
|
||
# Create data.tar.gz here.
|
||
package_target = "#{pkgdir}/"
|
||
package_target += "#{architecture}/"
|
||
package_target += "#{package.name}-#{package.version}-r#{package.release}.apk"
|
||
Dir.mkdir_p File.dirname package_target
|
||
|
||
# FIXME: This shouldn’t have to be in users’ PATH. libexec?
|
||
r = Do.run package.fake_root_directory, "#{OWN_LIBEXEC_DIR}/assemble-apk.sh", [
|
||
package_target
|
||
]
|
||
|
||
r.exit_status == 0
|
||
end
|
||
|
||
# This generated file content is specific to the Apk package manager.
|
||
def self.pkginfo(package : ::Package::Package, file_name : String)
|
||
du = `du -sk #{package.fake_root_directory}`
|
||
size = du.sub(/[ \t].*/, "").to_u64 * 1024_u64
|
||
|
||
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}"
|
||
|
||
package.dependencies.each do |atom|
|
||
file.puts "depend = #{atom.to_s}"
|
||
end
|
||
|
||
package.provides.each do |atom|
|
||
file.puts "provides = #{atom.to_s}"
|
||
end
|
||
|
||
package.conflicts.each do |atom|
|
||
file.puts "conflicts = #{atom.to_s}"
|
||
end
|
||
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
|
||
end
|
||
|