#!/bin/sh set -eu umask 022 artifact_dir=${1:-kernel-artifacts} output_dir=${2:-dist} metadata_file=$(mktemp) staging_dir=$(mktemp -d) trap 'rm -f "$metadata_file"; rm -rf "$staging_dir"' EXIT HUP INT TERM "$(dirname "$0")/detect-kernel-packages" "$artifact_dir" > "$metadata_file" . "$metadata_file" case "$METAPACKAGE_VERSION" in *[!0-9A-Za-z.+:~-]*|'') echo "Versión Debian no válida: $METAPACKAGE_VERSION" >&2 exit 1 ;; esac mkdir -p "$staging_dir/DEBIAN" "$staging_dir/usr/share/doc/espos-kernel" "$output_dir" cat > "$staging_dir/DEBIAN/control" < Depends: $IMAGE_PACKAGE, $HEADERS_PACKAGE Section: kernel Priority: optional Description: espOS kernel metapackage This metapackage installs the current espOS kernel image and headers. EOF cat > "$staging_dir/usr/share/doc/espos-kernel/copyright" <<'EOF' Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: espos-kernel Source: https://github.com/esposlinux/espos-kernel-metapackage Files: * Copyright: 2026 espOS Project License: GPL-2+ This package may be redistributed and/or modified under the terms of the GNU General Public License version 2 or (at your option) any later version. EOF if [ -n "${SOURCE_DATE_EPOCH:-}" ]; then build_date=$(date -u -R -d "@$SOURCE_DATE_EPOCH") else build_date=$(date -R) fi cat > "$staging_dir/usr/share/doc/espos-kernel/changelog.Debian" < $build_date EOF gzip -9n "$staging_dir/usr/share/doc/espos-kernel/changelog.Debian" find "$staging_dir" -type d -exec chmod 0755 {} + find "$staging_dir" -type f -exec chmod 0644 {} + chmod 0755 "$staging_dir/DEBIAN" package_file="$output_dir/espos-kernel_${METAPACKAGE_VERSION}_all.deb" dpkg-deb --root-owner-group --build "$staging_dir" "$package_file" test "$(dpkg-deb -f "$package_file" Package)" = espos-kernel test "$(dpkg-deb -f "$package_file" Architecture)" = all test "$(dpkg-deb -f "$package_file" Version)" = "$METAPACKAGE_VERSION" test "$(dpkg-deb -f "$package_file" Depends)" = "$IMAGE_PACKAGE, $HEADERS_PACKAGE" printf 'Creado %s para kernel %s\n' "$package_file" "$KERNEL_VERSION"