diff --git a/scripts/repo/gen-pacman-repo b/scripts/repo/gen-pacman-repo index 762c687c1c..63fe6564a9 100755 --- a/scripts/repo/gen-pacman-repo +++ b/scripts/repo/gen-pacman-repo @@ -26,8 +26,8 @@ set -euo pipefail -BUILD_DIR="${BUILD_DIR:-$(ls -1dt build.*-RK3326 2>/dev/null | head -1)}" -[ -z "${BUILD_DIR:-}" ] && { echo "BUILD_DIR not set and no build.*-RK3326 found"; exit 2; } +BUILD_DIR="${BUILD_DIR:-$(ls -1dt build.*-RK3326*aarch64* 2>/dev/null | head -1)}" +[ -z "${BUILD_DIR:-}" ] && { echo "BUILD_DIR not set and no build.*-RK3326*aarch64* found"; exit 2; } [ -d "${BUILD_DIR}/install_pkg" ] || { echo "no install_pkg/ under ${BUILD_DIR}"; exit 2; } OUT_DIR="${OUT_DIR:-${BUILD_DIR}/../repo-out}" @@ -46,32 +46,58 @@ echo "gen-pacman-repo: build=${BUILD_DIR} out=${OUT_DIR} channel=${CHANNEL} sign build_one_pkg() { local src="$1" - local name - name="$(basename "${src}")" + local dirname + dirname="$(basename "${src}")" # Skip anything that is not an actually built package tree. [ -d "${src}" ] || return 0 - # Pull version from the package.mk if present; fallback to date. - local pkgmk version - pkgmk="projects/ArchR/packages/*/${name}/package.mk packages/*/${name}/package.mk" + # The install_pkg dir name is "-". Strip + # the trailing suffix to recover the package name; the suffix is + # either a 40-char git hash or starts with a digit (semver). + local name version + name="$(echo "${dirname}" | sed -E 's/-[0-9a-f]{40}$//; s/-[0-9].*$//')" + + # Try to recover the exact PKG_VERSION from a matching package.mk + # under either the ArchR overlay or the top-level packages tree. + # Search any depth; multiple categories share the same package name + # in some cases, take the ArchR overlay first. + local pkgmk="" + pkgmk="$(find projects/ArchR/packages -mindepth 2 -maxdepth 6 \ + -path "*/${name}/package.mk" -print -quit 2>/dev/null)" + if [ -z "${pkgmk}" ]; then + pkgmk="$(find packages -mindepth 2 -maxdepth 6 \ + -path "*/${name}/package.mk" -print -quit 2>/dev/null)" + fi + version="" - for f in $(ls ${pkgmk} 2>/dev/null); do - version="$(awk -F'"' '/^PKG_VERSION/ {print $2; exit}' "${f}")" - [ -n "${version}" ] && break - done + if [ -n "${pkgmk}" ]; then + version="$(awk -F'"' '/^PKG_VERSION/ {print $2; exit}' "${pkgmk}")" + fi + # Fallback: pull the suffix back out of the dirname. + if [ -z "${version}" ]; then + version="${dirname#${name}-}" + fi version="${version:-$(date +%Y%m%d)}" - # pacman version must match [a-zA-Z0-9.+_]+; drop unsupported chars. - version="$(echo "${version}" | tr -c 'a-zA-Z0-9.+_' '.')" + + # pacman version must match [a-zA-Z0-9.+_]+. Long hashes are fine + # by this charset, but '/' or '~' would break: tr the rest. Use + # printf instead of echo to avoid the trailing newline being + # turned into a stray '.' by tr -c. + version="$(printf '%s' "${version}" | tr -c 'a-zA-Z0-9.+_' '.')" local pkgrel=1 local outfile="${OUT_DIR}/${name}-${version}-${pkgrel}-${ARCH}.pkg.tar.zst" - # .PKGINFO sidecar that pacman reads on install. + # .PKGINFO sidecar that pacman reads on install. pkgbase is + # required by repo-add (pacman 7+); xdata pkgtype=pkg matches + # makepkg output so clients treat us as a normal split-package. local pkginfo="${src}/.PKGINFO" cat >"${pkginfo}" < "${filelist}" + tar --zstd -cf "${outfile}" --owner=0 --group=0 -T "${filelist}" + rm -f "${filelist}" + ) rm -f "${pkginfo}" if [ -n "${SIGNER}" ]; then