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/main.cr

142 lines
5.3 KiB
Crystal
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

require "./context.cr"
require "./recipe.cr"
extend Package
# FIXME: recipe.clean? context autoclean?
context = Context.new()
context.packaging_backend = "apk"
recipes = [] of Package::Recipe
# FIXME: context.new_recipe? context.recipe?
recipes << Recipe.new(context, "hello", "2.10").tap do |recipe|
recipe.sources << "https://ftp.gnu.org/gnu/hello/hello-2.10.tar.gz"
# This is a voluntary mix of automatic and manual build
# instructions.
# Also, installing in /package makes testing with a real-life
# package manager trivial and reduces the damage done in case
# of… containment failure. ]:->
recipe.instructions.configure << "cd hello-#{recipe.version} && ./configure --prefix=/package"
recipe.url = "https://www.gnu.org/software/hello/"
recipe.description = "The GNU Hello program produces a familiar, friendly greeting."
recipe.dependencies << "gettext"
# Should be automatic now.
#recipe.packages << Package::Package.new(recipe).tap do |package|
# package.name = "#{recipe.name}-man"
# package.files = ["/package/share/man"]
#end
end
# Be careful with that one. Its not configured to use proper prefixes.
# (Not sure that it should though. Its gotta put things in /sbin anyway.)
recipes << Recipe.new(context, "sysvinit", "2.95").tap do |recipe|
recipe.sources << "https://git.savannah.nongnu.org/cgit/sysvinit.git/snapshot/sysvinit-#{recipe.version}.tar.gz"
recipe.url = "https://savannah.nongnu.org/projects/sysvinit"
recipe.description = "System V-like init system."
recipe.instructions.install << "cd sysvinit-#{recipe.version} && make ROOT='#{recipe.fake_root_directory}' install"
end
recipes << Recipe.new(context, "musl", "1.1.23").tap do |recipe|
recipe.sources << "https://www.musl-libc.org/releases/musl-#{recipe.version}.tar.gz"
recipe.url = "https://www.musl-libc.org/"
recipe.description = "The musl c library (libc) implementation."
end
recipes << Recipe.new(context, "llvm", "6.0.1").tap do |recipe|
recipe.sources << "http://releases.llvm.org/6.0.1/llvm-#{recipe.version}.src.tar.xz"
recipe.url = "http://llvm.org"
recipe.description = "The LLVM Project is a collection of modular and reusable compiler and toolchain technologies."
# Build-deps.
#recipe.build_dependencies << "cmake"
#recipe.build_dependencies << "make"
recipe.instructions.configure << "mkdir #{recipe.name}-#{recipe.version}"
recipe.instructions.configure << "cd #{recipe.name}-#{recipe.version} && cmake ../llvm-#{recipe.version}.src -DCMAKE_INSTALL_PREFIX=/package -DCMAKE_BUILD_TYPE=Release"
recipe.instructions.build << "pwd && ls && cd #{recipe.name}-#{recipe.version} && make"
recipe.instructions.install << "cd #{recipe.name}-#{recipe.version} && make DESTDIR='#{recipe.fake_root_directory}' install"
end
recipes << Recipe.new(context, "zsh", "5.7.1").tap do |recipe|
recipe.sources << "https://downloads.sourceforge.net/project/zsh/zsh/#{recipe.version}/zsh-#{recipe.version}.tar.xz"
recipe.url = "https://zsh.org"
recipe.description = "Zsh is a shell designed for interactive use, although it is also a powerful scripting language."
recipe.dependencies << "ncurses"
# Build-deps.
#recipe.build_dependencies << "ncurses-dev"
end
recipes << Recipe.new(context, "ncurses", "6.1").tap do |recipe|
recipe.sources << "ftp://ftp.invisible-island.net/ncurses/ncurses-#{recipe.version}.tar.gz"
recipe.url = "https://www.gnu.org/software/ncurses/"
end
recipes << Recipe.new(context, "busybox", "1.31.0").tap do |recipe|
recipe.sources << "https://busybox.net/downloads/busybox-#{recipe.version}.tar.bz2"
recipe.instructions.configure << "cd busybox-#{recipe.version} && make defconfig"
recipe.instructions.configure << "sed -i -e 's/.*CONFIG_STATIC.*/CONFIG_STATIC=y/' busybox-#{recipe.version}/.config"
recipe.instructions.install << "mkdir -p '#{recipe.fake_root_directory}/package/bin'"
recipe.instructions.install << "cp busybox-#{recipe.version}/busybox '#{recipe.fake_root_directory}/package/bin/busybox'"
recipe.instructions.install << "chroot '#{recipe.fake_root_directory}' /package/bin/busybox --install -s /package"
#recipe.build_dependencies << "linux-dev"
end
recipes << Recipe.new(context, "rc", "0.0.1").tap do |recipe|
recipe.sources << "https://git.karchnu.fr/JunkOS/rc/archive/579e431144e33b2510260b1bce5505fd328d2961.tar.gz"
# Those two are required due to a lack of robustness in our current backends.
recipe.instructions.configure << "true"
recipe.instructions.build << "true"
recipe.instructions.install << "mkdir -p '#{recipe.fake_root_directory}/etc'"
recipe.instructions.install << "cp rc/* '#{recipe.fake_root_directory}/etc/'"
end
if ARGV.size == 0 || ARGV[0]? == "-h"
pp recipes.map &.name
exit 0
end
selected_recipes = ARGV.map do |name|
recipes.find(&.name.==(name)) || name
end
if selected_recipes.any? &.is_a?(String)
puts "At least one of the requested recipes is not known."
selected_recipes.select! &.is_a?(String)
pp! selected_recipes
end
# Getting rid of Strings.
selected_recipes = selected_recipes.compact_map do |recipe|
if recipe.is_a? String
nil
else
recipe
end
end
selected_recipes.each do |recipe|
pp recipe
raise "oh no, download failed" unless recipe.download
raise "oh no, extraction failed" unless recipe.extract
raise "oh no, build failed" unless recipe.build
raise "oh no, packaging failed" unless recipe.package
recipe.clean
end