~dricottone/huttese-apk

dc230e0c5f6db9732ef46d4e9e9f18d8c45afbbc — Drew DeVault 5 years ago 810a272
Add pkgkit helper binary
3 files changed, 239 insertions(+), 66 deletions(-)

A pkgkit
M sr.ht/build.yml
M sr.ht/py-asyncpg/APKBUILD
A pkgkit => pkgkit +229 -0
@@ 0,0 1,229 @@
#!/bin/sh -eu
usage() {
	printf "%s\n\n" "Usage: $0 [command...] [flags...] [args...]"
	printf "%s\n" "$0 add-repo [-s] <name> <key>"
	printf "\t%s\n" "Trusts <key> and adds the local repo to /etc/apk/repositories"
	printf "\t%s\n\n" "-s: set this key as default in abuild.conf"
	printf "%s\n" "$0 build [-cr] [-v <pkgver>] <packages...>"
	printf "\t%s\n" "Builds packages"
	printf "\t%s\n" "-c: update checksums"
	printf "\t%s\n" "-r: update pkgrel"
	printf "\t%s\n\n" "-v <pkgver>: update pkgver"
	printf "%s\n" "$0 upload <ssh server> <remote path> <packages...>"
	printf "\t%s\n" "Uploads packages via rsync and updates remote APKINDEX"
}

get_pkgvar() (
	var="$1"
	set +u
	. APKBUILD
	eval 'printf "%s\n" "$'"$var"'"'
)

find_repos() (
	find . -maxdepth 1 -type d -not -name . -not -name .git
)

find_pkg_repo() (
	pkg=$1
	for repo in $(find_repos)
	do
		if [ -d "$repo"/"$pkg" ]
		then
			echo "$repo"
			return 0
		fi
	done
	return 1
)

update_pkgrel() (
	pkg="$1"
	pkgver="$(get_pkgvar pkgver)"
	prev_pkgver=$(apk search -x "$pkg" | cut -c$((${#pkg}+2))-)
	prev_pkgrel=$(printf "%s" "$prev_pkgver" | cut -d'-' -f2 | cut -d'r' -f2)
	if [ "$prev_pkgver" != "$pkgver" ]
	then
		pkgrel=$((prev_pkgrel + 1))
		sed -e "s/pkgrel=.*/pkgrel=$pkgrel/" -i APKBUILD
	fi
)

update_pkgver() {
	pkgver="$1"
	prev_pkgver=$(apk search -x ${project} | cut -d '-' -f3-)
	sed -e "s/pkgver=.*/pkgver=$pkgver/" -i APKBUILD
	if [ "$prev_pkgver" != "$pkgver" ]
	then
		sed -e "s/pkgrel=.*/pkgrel=0/" -i APKBUILD
	fi
}

add_repo() {
	set_default=0
	while getopts s flag
	do
		case $flag in
			s) set_default=1 ;;
			*) usage && exit 1 ;;
		esac
	done
	shift $((OPTIND-1))
	echo "$@"
	if [ $# -ne 2 ]
	then
		usage
		exit 1
	fi
	repo="$1"
	key="$2"
	mkdir -p ~/packages/$repo
	echo ~/packages/$repo | cat - /etc/apk/repositories > /tmp/repositories
	sudo mv /tmp/repositories /etc/apk/repositories
	sudo openssl rsa -in $key -pubout \
		-out /etc/apk/keys/$(basename "$key").pub
	if [ $set_default -eq 1 ]
	then
		echo "PACKAGER_PRIVKEY="'"'$key'"' >> \
			~/.abuild/abuild.conf
	fi
}

build() (
	checksum=0
	updpkgrel=0
	pkgver=""
	while getopts cuv: flag
	do
		case $flag in
			c) checksum=1 ;;
			u) updpkgrel=1 ;;
			v) pkgver="$OPTARG" ;;
			*) usage && exit 1 ;;
		esac
	done
	shift $((OPTIND-1))
	if [ $# -eq 0 ]
	then
		echo "No packages specified."
		exit 1
	fi
	for pkg in $@
	do
		repo="$(find_pkg_repo "$pkg")"
		(
			cd "$repo"/"$pkg"
			if [ $checksum -eq 1 ]
			then
				abuild checksum
			fi
			if [ $updpkgrel -eq 1 ]
			then
				update_pkgrel "$pkg"
			fi
			if [ -n "$pkgver" ]
			then
				update_pkgver "$pkgver"
			fi
			abuild -r
		)
	done
)

upload_pkg() (
	repo="$1"
	pkg="$2"
	arch="$(uname -m)"

	path="$remote_path/$repo/$arch"
	ssh "$remote" mkdir -p "$path"

	prev_pkgver=$(apk search -x "$pkg" | cut -c$((${#pkg}+2))-)
	prev_pkgrel=$(printf "%s" "$prev_pkgver" | cut -d'-' -f2 | cut -d'r' -f2)
	ssh "$remote" rm -f "$path/$pkg-$prev_pkgver-r$prev_pkgrel.apk"

	pkgver="$(get_pkgvar pkgver)"
	pkgrel="$(get_pkgvar pkgrel)"
	rsync --blocking-io -rsP \
		~/packages/"$repo/$arch/$pkg-$pkgver-r$pkgrel.apk" "$remote":"$path/"
)

update_index() (
	repo="$1"
	arch="$(uname -m)"
	path="$remote_path/$repo/$arch"

	ssh "$remote" \
		find "$path" -type f -name '*.apk' -print0 |
		ssh "$remote" xargs -0 apk index \
			--rewrite-arch "$(uname -m)" \
			-x "$path"/APKINDEX.tar.gz \
			-o "$path"/APKINDEX.unsigned.tar.gz
	rsync --blocking-io -rP \
		"$remote:$path/APKINDEX.unsigned.tar.gz" \
		/tmp/APKINDEX.tar.gz
	abuild-sign /tmp/APKINDEX.tar.gz
	rsync --blocking-io -rP /tmp/APKINDEX.tar.gz "$remote:$path/"
)

upload() (
	if [ $# -lt 2 ]
	then
		usage
		exit 1
	fi
	remote="$1"
	remote_path="$2"
	shift 2
	if [ $# -eq 0 ]
	then
		echo "No packages specified"
		exit 1
	fi
	repos=""
	for pkg in $@
	do
		repo=$(find_pkg_repo "$pkg")
		if ! echo "$repos" | grep "$repo" >/dev/null
		then
			repos="$repo $repos"
		fi
		(
			cd "$repo"/"$pkg"
			arch="$(get_pkgvar arch)"
			subpkgs="$pkg:_:$arch $(get_pkgvar subpackages)"
			for subpkg in $subpkgs
			do
				name="$(echo "$subpkg" | cut -d':' -f1)"
				upload_pkg "$repo" "$name"
			done
		)
	done
	for repo in $repos
	do
		update_index $repo
	done
)

if [ $# -lt 1 ]
then
	usage
	exit 1
fi
cmd="$1"
shift

case "$cmd" in
	add-repo)
		add_repo "$@"
		;;
	build)
		build "$@"
		;;
	upload)
		upload "$@"
		;;
	help|-h)
		usage
		;;
esac

M sr.ht/build.yml => sr.ht/build.yml +8 -64
@@ 5,10 5,11 @@ repositories:
    https://mirror.sr.ht/alpine/sr.ht/alpine%40sr.ht.rsa.pub
    alpine@sr.ht.rsa.pub
packages:
  - openssl
  - rsync
environment:
  repo_server: deploy@mirror.sr.ht
  repo_path: /var/www/mirror.sr.ht/alpine/sr.ht/x86_64
  remote: deploy@mirror.sr.ht
  remote_path: /var/www/mirror.sr.ht/alpine/sr.ht-2
  packages: []
sources:
  - https://git.sr.ht/~sircmpwn/sr.ht-apkbuilds


@@ 17,69 18,12 @@ secrets:
  - d0adc1d4-af78-4852-920f-1134392f5d10 # package signing key
tasks:
  - setup: |
      mkdir ~/packages
      cat <<'EOF' >>~/.buildenv
      function get_pkgvar() {
          var="$1"
          (
              set +u
              . APKBUILD
              eval 'printf "%s\n" "$'"$var"'"'
          )
      }
      EOF
      echo 'PACKAGER_PRIVKEY="/home/build/.abuild/alpine@sr.ht.rsa"' >> \
        ~/.abuild/abuild.conf
      cd sr.ht-apkbuilds
      ./pkgkit add-repo -s sr.ht ~/.abuild/alpine@sr.ht.rsa
  - build: |
      cd sr.ht-apkbuilds/sr.ht
      for package in "${packages[@]}"
      do
          cd "$package"
          pkgver="$(get_pkgvar pkgver)"
          prev_pkgver=$(apk search -x "$package" | cut -c$((${#package}+2))-)
          prev_pkgrel=$(printf "%s" "$prev_pkgver" | cut -d'-' -f2 | cut -d'r' -f2)
          if [ "$prev_pkgver" != "$pkgver" ]
          then
              pkgrel=$((prev_pkgrel + 1))
              sed -e "s/pkgrel=.*/pkgrel=$pkgrel/" -i APKBUILD
          fi
          abuild checksum
          abuild -r
          sudo apk add ~/packages/sr.ht/$(uname -m)/"$package"-$pkgver-r$pkgrel.apk
          cd ..
      done
      cd sr.ht-apkbuilds
      ./pkgkit build -cr $packages
  - deploy: |
      cd sr.ht-apkbuilds/sr.ht
      sshopts="-o StrictHostKeyChecking=no"
      set -u
      for package in "${packages[@]}"
      do
          cd "$package"
          ssh $sshopts $repo_server rm -f $repo_path/${package}'*.apk'
          pkgver="$(get_pkgvar pkgver)"
          pkgrel="$(get_pkgvar pkgrel)"
          subpkgs="$(get_pkgvar subpackages)"
          rsync --blocking-io \
            -rPe "ssh $sshopts" \
            ~/packages/sr.ht/$(uname -m)/"$package"-$pkgver-r$pkgrel.apk \
            $repo_server:$repo_path/
          for subp in $subpkgs
          do
              subp="$(printf '%s' "$subp" | cut -d: -f1)"
              rsync --blocking-io \
                -rPe "ssh $sshopts" \
                ~/packages/sr.ht/$(uname -m)/"$subp"-$pkgver-r$pkgrel.apk \
                $repo_server:$repo_path/
          done
          ssh $sshopts $repo_server find $repo_path -type f -name '*.apk' -print0 |
            ssh $sshopts $repo_server xargs -0 apk index \
              --rewrite-arch x86_64 \
              -x $repo_path/APKINDEX.tar.gz \
              -o $repo_path/APKINDEX.unsigned.tar.gz
          rsync --blocking-io -rPe "ssh $sshopts" \
            $repo_server:$repo_path/APKINDEX.unsigned.tar.gz APKINDEX.tar.gz
          abuild-sign -k ~/.abuild/alpine@sr.ht.rsa APKINDEX.tar.gz
          rsync --blocking-io -rPe "ssh $sshopts" \
            APKINDEX.tar.gz $repo_server:$repo_path/
          cd ..
      done
      ./pkgkit upload "$remote" "$remote_path" $packages

M sr.ht/py-asyncpg/APKBUILD => sr.ht/py-asyncpg/APKBUILD +2 -2
@@ 6,9 6,9 @@ pkgver=0.18.2
pkgrel=0
pkgdesc="An asyncio PostgreSQL driver"
url="https://github.com/MagicStack/asyncpg"
arch="noarch"
arch="all"
license="Apache-2.0"
subpackages="py3-${pkgname#py-}:_py3:all"
subpackages="py3-${pkgname#py-}:_py3"
makedepends="python3-dev py-setuptools cython cython-dev"
source="https://files.pythonhosted.org/packages/source/${_pkgname:0:1}/$_pkgname/$_pkgname-$pkgver.tar.gz"
builddir="$srcdir"/$_pkgname-$pkgver