commit a98c64521d2904491701a5e7b62538bd537a358b Author: Sebastian Hugentobler Date: Thu Jun 22 09:49:39 2023 +0200 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..765efc1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*~ +.DS_Store +*.pkg.tar.zst +*.pkg.tar.zst.sig diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 0000000..4f5d75a --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,20 @@ +# Maintainer: Sebastian Hugentobler + +pkgname=repo-tool +pkgver=0.1.0 +pkgrel=1 +pkgdesc="Build a tree of pacman packages and build a repo of them." +arch=("any") +url="https://code.vanwa.ch" +license=('MIT') +depends=("pacman" "gnupg" "findutils") +source=( + "repo-tool" +) +sha256sums=("9eae4888a23637580d2323678ba0218bdce2d924e381ddbe2b0114b4a8dbe408") + +package() { + cd "$srcdir/" + + install -Dm 755 repo-tool "$pkgdir/usr/bin/repo-tool" +} diff --git a/repo-tool b/repo-tool new file mode 100755 index 0000000..8a2ef71 --- /dev/null +++ b/repo-tool @@ -0,0 +1,57 @@ +#!/usr/bin/env sh +set -o errexit + +build_exclude_arg() { + x="$1" + if [ -n "$x" ]; then + set -- -path "$x" -prune -o + exclude_arg="$*" + else + set -- exclude_arg + fi +} + +build_pkgs() { + pkg_root="$1" + build_exclude_arg "$2" + + # shellcheck disable=2086 + find "$pkg_root" $exclude_arg -name "PKGBUILD" \ + -exec sh -c 'p="$1"; echo "building and signing $(basename "$p")..."; cd $(dirname "$p") && makepkg -src --sign' shell {} \; +} + +build_repo() { + pkg_root="$1" + repo="$2" + repo_name="$3" + build_exclude_arg "$repo" + + if [ ! -d "$repo" ]; then + mkdir -p "$repo" + fi + + # shellcheck disable=2086 + find "$pkg_root" $exclude_arg -type f \ + \( -name "*.pkg.tar.zst" -o -name "*.pkg.tar.zst.sig" \) -exec cp "{}" "$repo" \; + # shellcheck disable=2035 + cd "$repo" && repo-add --new --prevent-downgrade --sign "$repo_name.db.tar.gz" *.pkg.tar.zst +} + +if [ -z "$1" ] || { [ "$1" != "pkgs" ] && [ "$1" != "repo" ]; }; then + echo "usage: $0 pkgs|repo" + echo + echo "pkgs takes two additional arguments:" + echo " - root directory of the package tree" + echo " - repo directory (use if it is in the same directory tree, optional)" + echo + echo "repo takes two additional arguments:" + echo " - root directory of the package tree" + echo " - repo directory" + echo " - repo name" +else + if [ "$1" = "pkgs" ]; then + build_pkgs "$2" "$3" + else + build_repo "$2" "$3" "$4" + fi +fi