summaryrefslogtreecommitdiff
path: root/offload-build.in
diff options
context:
space:
mode:
authorLevente Polyak <anthraxx@archlinux.org>2019-12-28 19:05:28 +0100
committerLevente Polyak <anthraxx@archlinux.org>2020-02-10 23:02:41 +0100
commit9b4d8ae93053fcebc281f54d8a374839a7a50861 (patch)
treeb204b31e2d4a20d9c197387f4fe57d8ed6cb907f /offload-build.in
parent4c206ab549b7944801f11387cbc57807e8e24338 (diff)
downloaddevtools-9b4d8ae93053fcebc281f54d8a374839a7a50861.tar.xz
offload-build: convert to in-prog so we can perform pre-processing
Diffstat (limited to 'offload-build.in')
-rwxr-xr-xoffload-build.in121
1 files changed, 121 insertions, 0 deletions
diff --git a/offload-build.in b/offload-build.in
new file mode 100755
index 0000000..e607a16
--- /dev/null
+++ b/offload-build.in
@@ -0,0 +1,121 @@
+#!/bin/bash
+#
+# offload-build - build a PKGBUILD on a remote server using makechrootpkg.
+#
+# Copyright (c) 2019 by Eli Schwartz <eschwartz@archlinux.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+#
+
+source /usr/share/makepkg/util/config.sh
+
+
+# global defaults suitable for use by Arch staff
+repo=extra
+arch=x86_64
+server=dragon.archlinux.org
+
+die() { printf "error: $1\n" "${@:2}"; exit 1; }
+
+usage() {
+ cat <<- _EOF_
+ Usage: ${BASH_SOURCE[0]##*/} [--repo REPO] [--arch ARCHITECTURE] [--server SERVER] -- [ARCHBUILD_ARGS]
+
+ Build a PKGBUILD on a remote server using makechrootpkg. Requires a remote user
+ that can run archbuild without password auth. Options passed after a -- are
+ passed on to archbuild, and eventually to makechrootpkg.
+
+ OPTIONS
+ -r, --repo Build against a specific repository (current: $repo)
+ -a, --arch Build against a specific architecture (current: $arch)
+ -s, --server Offload to a specific build server (current: $server)
+ -h, --help Show this help text
+_EOF_
+}
+
+# option checking
+while (( $# )); do
+ case $1 in
+ -h|--help)
+ usage
+ exit 0
+ ;;
+ -r|--repo)
+ repo=$2
+ shift 2
+ ;;
+ -a|--arch)
+ arch=$2
+ shift 2
+ ;;
+ -s|--server)
+ server=$2
+ shift 2
+ ;;
+ --)
+ shift
+ break
+ ;;
+ *)
+ die "invalid argument: %s" "$1"
+ ;;
+ esac
+done
+
+# multilib must be handled specially
+if [[ $repo = multilib* ]]; then
+ arch=
+fi
+
+archbuild_cmd=("${repo}${arch:+-$arch}-build" "$@")
+
+trap 'rm -rf $SRCPKGDEST' EXIT INT TERM QUIT
+
+# Use a source-only tarball as an intermediate to transfer files. This
+# guarantees the checksums are okay, and guarantees that all needed files are
+# transferred, including local sources, install scripts, and changelogs.
+export SRCPKGDEST=$(mktemp -d)
+makepkg --source || die "unable to make source package"
+
+# Temporary cosmetic workaround makepkg if SRCDEST is set somewhere else
+# but an empty src dir is created in PWD. Remove once fixed in makepkg.
+rmdir --ignore-fail-on-non-empty src 2>/dev/null || true
+
+mapfile -t files < <(
+ # This is sort of bash golfing but it allows running a mildly complex
+ # command over ssh with a single connection.
+ # shellcheck disable=SC2145
+ cat "$SRCPKGDEST"/*.src.tar.gz |
+ ssh $server '
+ temp="${XDG_CACHE_HOME:-$HOME/.cache}/offload-build" &&
+ mkdir -p "$temp" &&
+ temp=$(mktemp -d -p "$temp") &&
+ cd "$temp" &&
+ {
+ bsdtar --strip-components 1 -xvf - &&
+ script -qefc "'"${archbuild_cmd[@]@Q}"'" /dev/null &&
+ printf "%s\n" "" "-> build complete" &&
+ printf "\t%s\n" "$temp"/*
+ } >&2 &&
+ makepkg --packagelist
+')
+
+
+if (( ${#files[@]} )); then
+ printf '%s\n' '' '-> copying files...'
+ load_makepkg_config
+ scp "${files[@]/#/$server:}" "${PKGDEST:-${PWD}}/"
+else
+ exit 1
+fi