aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Arakaki Giovanini <mail@gabrielgio.me>2022-10-14 21:04:20 +0200
committerGabriel Arakaki Giovanini <mail@gabrielgio.me>2022-10-14 21:09:35 +0200
commit307af8fd5a3e74ebcb64ac5bbe57493b59ead233 (patch)
treed7f1e97a46713925041a6fa4de4dab5694529c7c
parent6d706f14b057e25b4b116ed1ee8c4db4b89454ab (diff)
downloadapkbuilds-307af8fd5a3e74ebcb64ac5bbe57493b59ead233.tar.gz
apkbuilds-307af8fd5a3e74ebcb64ac5bbe57493b59ead233.tar.bz2
apkbuilds-307af8fd5a3e74ebcb64ac5bbe57493b59ead233.zip
feat: shamelessly copy pkgkit from sr.ht-apkbuilds
Copy some code from sourcehut's alpine build[0] to build my own packages. [0]: https://git.sr.ht/~sircmpwn/sr.ht-apkbuilds
-rw-r--r--build.yml20
-rwxr-xr-xpkgkit336
-rw-r--r--pkgs/gallery-dl/APKBUILD (renamed from gallery-dl/APKBUILD)0
-rw-r--r--pkgs/genpass/APKBUILD (renamed from genpass/APKBUILD)0
-rw-r--r--pkgs/genpass/genpass.nginx.conf (renamed from genpass/genpass.nginx.conf)0
-rw-r--r--pkgs/jsonpickle/APKBUILD (renamed from jsonpickle/APKBUILD)0
-rw-r--r--pkgs/jsonpickle/tests.patch (renamed from jsonpickle/tests.patch)0
-rw-r--r--pkgs/midr/APKBUILD (renamed from midr/APKBUILD)0
-rw-r--r--pkgs/midr/midr.confd (renamed from midr/midr.confd)0
-rw-r--r--pkgs/midr/midr.initd (renamed from midr/midr.initd)0
-rw-r--r--pkgs/midr/midr.pre-install (renamed from midr/midr.pre-install)0
-rw-r--r--pkgs/nextcloud-api-wrapper/APKBUILD (renamed from nextcloud-api-wrapper/APKBUILD)0
-rw-r--r--pkgs/reddit-nextcloud-importer/APKBUILD (renamed from reddit-nextcloud-importer/APKBUILD)0
-rw-r--r--pkgs/reddit-nextcloud-importer/reddit-nextcloud-importer.confd (renamed from reddit-nextcloud-importer/reddit-nextcloud-importer.confd)0
-rw-r--r--pkgs/reddit-nextcloud-importer/reddit-nextcloud-importer.initd (renamed from reddit-nextcloud-importer/reddit-nextcloud-importer.initd)0
-rw-r--r--pkgs/reddit-nextcloud-importer/reddit-nextcloud-importer.pre-install (renamed from reddit-nextcloud-importer/reddit-nextcloud-importer.pre-install)0
-rwxr-xr-xsubmit-builds66
17 files changed, 411 insertions, 11 deletions
diff --git a/build.yml b/build.yml
index 7b2adf7..f1aa372 100644
--- a/build.yml
+++ b/build.yml
@@ -9,9 +9,9 @@ packages:
- rsync
- alpine-sdk
environment:
- deploy: builds@gabrielgio.me
- target: artifacts.gabrielgio.me/repo/
- packages: ["genpass", "midr"]
+ remote: builds@gabrielgio.me
+ remote_path: /var/www/artifacts.gabrielgio.me/repo/
+ packages: []
sources:
- https://git.sr.ht/~gabrielgio/apkbuilds
secrets:
@@ -19,14 +19,12 @@ secrets:
- df9d57f4-43bb-4084-a748-dbf02848bdd0
tasks:
- setup: |
- echo "PACKAGER_PRIVKEY=\"/home/build/.abuild/mail@gabrielgio.me-62ddc4dc.rsa\"" > ~/.abuild/abuild.conf
+ cd apkbuilds
+ ./pkgkit add-repo -s apks ~/.abuild/mail@gabrielgio.me-62ddc4dc.rsa
- build: |
cd apkbuilds
- for pkg in "${packages[@]}"; do
- cd "$pkg"
- abuild -r
- cd ..
- done
+ ./pkgkit build -cu "${packages[@]}"
- deploy: |
- sshopts="ssh -o StrictHostKeyChecking=no"
- rsync --rsh="$sshopts" -rP ~/packages/apkbuilds/ $deploy:/var/www/$target
+ cd apkbuilds
+ echo "StrictHostKeyChecking=no" >> ~/.ssh/config
+ ./pkgkit upload "$remote" "$remote_path" "${packages[@]}"
diff --git a/pkgkit b/pkgkit
new file mode 100755
index 0000000..327c0ec
--- /dev/null
+++ b/pkgkit
@@ -0,0 +1,336 @@
+#!/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 [-cu] [-v <pkgver>] <packages...>"
+ printf "\t%s\n" "Builds packages"
+ printf "\t%s\n" "-c: update checksums"
+ printf "\t%s\n" "-u: update pkgrel"
+ printf "\t%s\n\n" "-v <pkgver>: update pkgver"
+ printf "%s\n" "$0 pkgver"
+ printf "\t%s\n\n" "Prints the suggested package ver for this directory"
+ 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_ver=$(apk search -x "$pkg" | cut -c$((${#pkg}+2))-)
+ prev_pkgver=$(printf "%s" "$prev_ver" | cut -d'-' -f1)
+ prev_pkgrel=$(printf "%s" "$prev_ver" | 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 '-' -f2)
+ 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
+ if ! [ -f "$key" ]
+ then
+ echo "Warning: generating new abuild key"
+ key="$HOME/.abuild/abuild.rsa"
+ mkdir -p $HOME/.abuild
+ (
+ umask 0007
+ openssl genrsa -out "$key" 2048
+ )
+ fi
+ 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() (
+ builddeps=0
+ checksum=0
+ updpkgrel=0
+ pkgver=""
+ # Disable progress on abuild-apk
+ cat <<-"EOF" | sudo tee /usr/local/bin/abuild-apk
+ #!/bin/sh
+ exec /usr/bin/abuild-apk --no-progress $@
+ EOF
+ sudo chmod +x /usr/local/bin/abuild-apk
+ export PATH=/usr/local/bin:$PATH
+ while getopts Rcuv: flag
+ do
+ case $flag in
+ R) builddeps=1 ;;
+ 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 [ -n "$pkgver" ]
+ then
+ update_pkgver "$pkgver"
+ fi
+ if [ $updpkgrel -eq 1 ]
+ then
+ update_pkgrel "$pkg"
+ fi
+ if [ $checksum -eq 1 ]
+ then
+ abuild checksum
+ fi
+ if [ $builddeps -eq 1 ]
+ then
+ abuild -R
+ else
+ abuild -r
+ fi
+ )
+ done
+)
+
+print_pkgver() {
+ if [ $# -ne 0 ]
+ then
+ usage
+ exit 1
+ fi
+ if [ -d .git ]
+ then
+ set +e
+ pkgver=$(git describe --abbrev=0 2>/dev/null)
+ if [ $? -ne 0 ]
+ then
+ pkgver=0
+ fi
+ set -e
+ if ! git describe --exact-match HEAD >/dev/null 2>&1
+ then
+ cdate=$(git show -s -1 --format='%ci' HEAD)
+ cdate=$(echo "$cdate" | cut -d' ' -f1 | sed -e 's/-//g')
+ pkgver="${pkgver}_git${cdate}"
+ fi
+ elif [ -d .hg ]
+ then
+ pkgver=$(hg id -T '{latesttag}')
+ if [ "$(hg id -T '{latesttagdistance}')" -ne 0 ]
+ then
+ pkgver="$(hg id -T '{latesttag}_hg{sub("-", "", date|shortdate)}')"
+ fi
+ else
+ pkgver=unknown_0000
+ fi
+ echo "$pkgver"
+}
+
+mirror_ver() (
+ mirror="$1"
+ pkg="$2"
+ apk policy "$pkg" | while read -r line
+ do
+ case "$line" in
+ *:)
+ ver="${line%:}"
+ ver="${ver## }"
+ ;;
+ *$mirror*)
+ echo "$ver"
+ ;;
+ esac
+ done
+)
+
+get_aver() {
+ aver="${REPOSITORY:-}"
+ if [ ${#aver} -eq 0 ]
+ then
+ . /etc/os-release
+ aver="v$(printf "%s" "$VERSION_ID" | cut -d. -f1-2)"
+ fi
+ echo "$aver"
+}
+
+upload_pkg() (
+ repo="$1"
+ pkg="$2"
+ arch="$(uname -m)"
+ aver="$(get_aver)"
+
+ set -x
+ path="$remote_path/$aver/$repo/$arch"
+ ssh "$remote" mkdir -p "$path"
+
+ url=$(echo "$remote" | cut -d@ -f2)
+ prev_ver=$(mirror_ver "$url" "$pkg")
+
+ for ver in $prev_ver
+ do
+ if [ "$prev_ver" != "none" ]
+ then
+ ssh "$remote" rm -f "$path/$pkg-$ver.apk"
+ fi
+ done
+ pkgver="$(get_pkgvar pkgver)"
+ pkgrel="$(get_pkgvar pkgrel)"
+
+ rsync --blocking-io -rsP \
+ ~/packages/"$repo/$arch/$pkg-$pkgver-r$pkgrel.apk" "$remote":"$path/"
+ set +x
+)
+
+update_index() (
+ repo="$1"
+ arch="$(uname -m)"
+
+ . /etc/os-release
+ aver="$(get_aver)"
+
+ path="$remote_path/$aver/$repo/$arch"
+
+ set -x
+ 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/"
+ set +x
+)
+
+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 "$@"
+ ;;
+ pkgver)
+ print_pkgver "$@"
+ ;;
+ upload)
+ upload "$@"
+ ;;
+ help|-h)
+ usage
+ ;;
+esac
diff --git a/gallery-dl/APKBUILD b/pkgs/gallery-dl/APKBUILD
index e503ca3..e503ca3 100644
--- a/gallery-dl/APKBUILD
+++ b/pkgs/gallery-dl/APKBUILD
diff --git a/genpass/APKBUILD b/pkgs/genpass/APKBUILD
index 3c74124..3c74124 100644
--- a/genpass/APKBUILD
+++ b/pkgs/genpass/APKBUILD
diff --git a/genpass/genpass.nginx.conf b/pkgs/genpass/genpass.nginx.conf
index a11fd3b..a11fd3b 100644
--- a/genpass/genpass.nginx.conf
+++ b/pkgs/genpass/genpass.nginx.conf
diff --git a/jsonpickle/APKBUILD b/pkgs/jsonpickle/APKBUILD
index 6cfc40e..6cfc40e 100644
--- a/jsonpickle/APKBUILD
+++ b/pkgs/jsonpickle/APKBUILD
diff --git a/jsonpickle/tests.patch b/pkgs/jsonpickle/tests.patch
index 99d78af..99d78af 100644
--- a/jsonpickle/tests.patch
+++ b/pkgs/jsonpickle/tests.patch
diff --git a/midr/APKBUILD b/pkgs/midr/APKBUILD
index b985257..b985257 100644
--- a/midr/APKBUILD
+++ b/pkgs/midr/APKBUILD
diff --git a/midr/midr.confd b/pkgs/midr/midr.confd
index 79693ed..79693ed 100644
--- a/midr/midr.confd
+++ b/pkgs/midr/midr.confd
diff --git a/midr/midr.initd b/pkgs/midr/midr.initd
index 20a069f..20a069f 100644
--- a/midr/midr.initd
+++ b/pkgs/midr/midr.initd
diff --git a/midr/midr.pre-install b/pkgs/midr/midr.pre-install
index 74f1b59..74f1b59 100644
--- a/midr/midr.pre-install
+++ b/pkgs/midr/midr.pre-install
diff --git a/nextcloud-api-wrapper/APKBUILD b/pkgs/nextcloud-api-wrapper/APKBUILD
index 4b3bafe..4b3bafe 100644
--- a/nextcloud-api-wrapper/APKBUILD
+++ b/pkgs/nextcloud-api-wrapper/APKBUILD
diff --git a/reddit-nextcloud-importer/APKBUILD b/pkgs/reddit-nextcloud-importer/APKBUILD
index b4ea7fa..b4ea7fa 100644
--- a/reddit-nextcloud-importer/APKBUILD
+++ b/pkgs/reddit-nextcloud-importer/APKBUILD
diff --git a/reddit-nextcloud-importer/reddit-nextcloud-importer.confd b/pkgs/reddit-nextcloud-importer/reddit-nextcloud-importer.confd
index ad77d8b..ad77d8b 100644
--- a/reddit-nextcloud-importer/reddit-nextcloud-importer.confd
+++ b/pkgs/reddit-nextcloud-importer/reddit-nextcloud-importer.confd
diff --git a/reddit-nextcloud-importer/reddit-nextcloud-importer.initd b/pkgs/reddit-nextcloud-importer/reddit-nextcloud-importer.initd
index b78cf29..b78cf29 100644
--- a/reddit-nextcloud-importer/reddit-nextcloud-importer.initd
+++ b/pkgs/reddit-nextcloud-importer/reddit-nextcloud-importer.initd
diff --git a/reddit-nextcloud-importer/reddit-nextcloud-importer.pre-install b/pkgs/reddit-nextcloud-importer/reddit-nextcloud-importer.pre-install
index 74f1b59..74f1b59 100644
--- a/reddit-nextcloud-importer/reddit-nextcloud-importer.pre-install
+++ b/pkgs/reddit-nextcloud-importer/reddit-nextcloud-importer.pre-install
diff --git a/submit-builds b/submit-builds
new file mode 100755
index 0000000..de6c58d
--- /dev/null
+++ b/submit-builds
@@ -0,0 +1,66 @@
+#!/bin/sh
+upstream=https://builds.sr.ht
+manifest=build.yml
+
+if [ -e ~/.config/sr.ht ]
+then
+ . ~/.config/sr.ht
+fi
+
+while getopts m:u:t:h flag
+do
+ case $flag in
+ u)
+ upstream="$OPTARG"
+ ;;
+ t)
+ bearer_token="$OPTARG"
+ ;;
+ m)
+ manifest="$OPTARG"
+ ;;
+ h)
+ echo "Usage: $0 [-u https://upstream...] [-t oauth token] <packages...>"
+ exit 0
+ ;;
+ esac
+done
+shift $((OPTIND-1))
+
+builds=""
+note=""
+for target in $*
+do
+ if [ "$builds" = "" ]
+ then
+ builds="'${target#sr.ht/}'"
+ note="${target#sr.ht/}"
+ else
+ builds="$builds, '${target#sr.ht/}'"
+ if [ "${#note}" -lt 128 ]
+ then
+ note="$note, ${target#sr.ht/}"
+ fi
+ fi
+done
+
+vars="$(sed "s/packages: \\[\\]/packages: [$builds]/g" < $manifest | jq -sR '{
+ "manifest": .,
+ "tags": ["sr.ht-apkbuilds"],
+ "note": "'"$note"'"
+}')"
+query="$(jq -sR '.' <<"EOF"
+mutation SubmitJob($manifest: String!, $tags: [String!]!, $note: String!) {
+ submit(manifest: $manifest, tags: $tags, note: $note) {
+ id, tags
+ }
+}
+EOF
+)"
+
+curl --oauth2-bearer "$bearer_token" \
+ -H Content-Type:application/json \
+ -d '{
+ "query": '"$query"',
+ "variables": '"$vars"'
+ }' "$upstream/query" | jq .