: nply/foundationpkgs-binaries

1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 
53 
54 
55 
56 
57 
58 
59 
60 
61 
62 
63 
64 
65 
66 
67 
68 
69 
70 
71 
72 
73 
74 
75 
76 
77 
78 
79 
80 
81 
82 
83 
84 
85 
86 
87 
88 
89 
90 
91 
92 
93 
#!/bin/sh
# Build Debian-native upstream abuild and apk-tools. No live installation.
set -eu
root=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)
[ "$(dpkg --print-architecture)" = amd64 ] || { echo 'This release is tested on Debian 13 amd64 only.' >&2; exit 1; }
for tool in cc make pkg-config dpkg-deb strip patch; do
	command -v "$tool" >/dev/null || { echo "Missing build tool: $tool" >&2; exit 1; }
done
pkg-config --exists openssl zlib libzstd
out=${OUTDIR:-$root/packages/debian/trixie/amd64}
mkdir -p "$out"
out=$(CDPATH= cd -- "$out" && pwd)
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT HUP INT TERM
(cd "$root/sources" && sha256sum -c SHA256SUMS)
tar -xzf "$root/sources/apk-tools-v2.14.12.tar.gz" -C "$work"
tar -xzf "$root/sources/abuild-2770c8e.tar.gz" -C "$work"
apksrc=$work/apk-tools-v2.14.12
abuildsrc=$work/abuild-2770c8ec05ca2a5bbdaf74e340b9dba0257c1fd5
make -C "$apksrc" -j"${JOBS:-1}" LUA=no compile
(cd "$abuildsrc" && patch -p1 <"$root/patches/abuild-debian-shell.patch")
programs='abuild abuild-keygen abuild-sign newapkbuild abump apkgrel apkbuild-cpan apkbuild-pypi checkapk apkbuild-gem-resolver'
helpers='abuild-tar abuild-gzsplit abuild-fetch abuild-rm abuild-sudo'
# Man pages use scdoc; these bootstrap binaries don't require it to build.
make -C "$abuildsrc" -j"${JOBS:-1}" $programs $helpers functions.sh abuild.conf

apkstage=$work/apk-tools
abuildstage=$work/abuild
mkdir -p "$apkstage/DEBIAN" "$apkstage/usr/bin" "$apkstage/usr/lib" "$apkstage/usr/share/doc/apk-tools"
install -m755 "$apksrc/src/apk" "$apkstage/usr/bin/apk"
install -m755 "$apksrc/src/libapk.so.2.14.10" "$apkstage/usr/lib/"
install -m644 "$apksrc/LICENSE" "$apkstage/usr/share/doc/apk-tools/copyright"
cat >"$apkstage/DEBIAN/control" <<'CONTROL'
Package: apk-tools
Version: 2.14.12-1
Architecture: amd64
Maintainer: Bootstrap Binaries Maintainers <maintainers@localhost>
Section: admin
Priority: optional
Depends: libc6 (>= 2.38), libssl3t64, zlib1g, libzstd1, ca-certificates
Description: Upstream Alpine package tools built natively for Debian
 Produces, indexes, verifies, and manages Alpine APK packages.
 No host APK database or repositories are configured by this package.
CONTROL
printf 'activate-noawait ldconfig\n' >"$apkstage/DEBIAN/triggers"

mkdir -p "$abuildstage/DEBIAN" "$abuildstage/usr/bin" "$abuildstage/usr/share/abuild" "$abuildstage/etc" "$abuildstage/usr/share/doc/abuild"
for program in $programs $helpers; do
	install -m755 "$abuildsrc/$program" "$abuildstage/usr/bin/$program"
done
# Keep upstream aliases, but don't introduce a setuid binary on the Debian host.
for name in apk adduser addgroup; do
	ln -s abuild-sudo "$abuildstage/usr/bin/abuild-$name"
done
for file in functions.sh default.conf config.sub config.guess sample.APKBUILD sample.initd sample.confd sample.pre-install sample.post-install; do
	install -m644 "$abuildsrc/$file" "$abuildstage/usr/share/abuild/$file"
done
chmod 0755 "$abuildstage/usr/share/abuild/config.sub" "$abuildstage/usr/share/abuild/config.guess"
install -m644 "$abuildsrc/abuild.conf" "$abuildstage/etc/abuild.conf"
printf '\n# Debian installs getcap in /usr/sbin.\nexport PATH="$PATH:/usr/sbin:/sbin"\n' >>"$abuildstage/etc/abuild.conf"
install -m644 "$abuildsrc/COPYING" "$abuildstage/usr/share/doc/abuild/copyright"
printf '/etc/abuild.conf\n' >"$abuildstage/DEBIAN/conffiles"
cat >"$abuildstage/DEBIAN/control" <<'CONTROL'
Package: abuild
Version: 3.18.0~rc5+git20260823-1
Architecture: amd64
Maintainer: Bootstrap Binaries Maintainers <maintainers@localhost>
Section: devel
Priority: optional
Depends: apk-tools (>= 2.14), busybox, fakeroot, pax-utils, libcap2-bin, bc, openssl, libc6 (>= 2.38), libssl3t64, zlib1g, binutils, build-essential, pkgconf, git, patch, curl, tar, gzip, bzip2, xz-utils, zstd, util-linux
Description: Upstream Alpine APKBUILD packaging tools for a Debian build host
 Uses BusyBox ash in place of Alpine's /bin/ash.
 Use abuild -d with build dependencies supplied by the Debian host or user.
 Cross toolchains and target binary compatibility are controlled by the recipe.
CONTROL
strip --strip-unneeded "$apkstage/usr/bin/apk" "$apkstage/usr/lib/libapk.so.2.14.10"
for helper in $helpers; do strip --strip-unneeded "$abuildstage/usr/bin/$helper"; done
for stage in "$apkstage" "$abuildstage"; do
	find "$stage" -type d -exec chmod 0755 {} +
	(cd "$stage" && find . -type f ! -path './DEBIAN/*' -exec md5sum {} + | sed 's|  ./|  |') >"$stage/DEBIAN/md5sums"
	name=$(awk '/^Package:/ {print $2}' "$stage/DEBIAN/control")
	version=$(awk '/^Version:/ {print $2}' "$stage/DEBIAN/control")
	dpkg-deb --root-owner-group --build "$stage" "$out/${name}_${version}_amd64.deb"
done
(cd "$out" && sha256sum ./*.deb >SHA256SUMS)
{
	printf 'Built-At: %s\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
	printf 'Build-Host: '; cat /etc/debian_version
	printf 'Compiler: '; cc --version | head -n1
	printf 'Abuild-Upstream: 2770c8ec05ca2a5bbdaf74e340b9dba0257c1fd5\nApk-Tools-Upstream: v2.14.12\n'
	sha256sum "$root/patches/abuild-debian-shell.patch" "$root/scripts/build-debs.sh" | sed "s|$root/||"
} >"$out/BUILDINFO"
printf 'Packages written to %s\n' "$out"