Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/bin/create-build-support-package
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2019-02-15 15:23:23 +0100
committerErich Eckner <git@eckner.net>2019-02-15 15:27:55 +0100
commit87a944500184bd4b689a2fe1fd006d99b21e1573 (patch)
treeaebc57c2e485f0f79d35ad8e7428dd5650fe800d /bin/create-build-support-package
parent5413ad5226ba8626467606d6803617750484f673 (diff)
bin/create-build-support-package: some progress
Diffstat (limited to 'bin/create-build-support-package')
-rwxr-xr-xbin/create-build-support-package213
1 files changed, 213 insertions, 0 deletions
diff --git a/bin/create-build-support-package b/bin/create-build-support-package
new file mode 100755
index 0000000..1763b41
--- /dev/null
+++ b/bin/create-build-support-package
@@ -0,0 +1,213 @@
+#!/bin/sh
+
+# shellcheck source=../lib/load-configuration
+. "${0%/*}/../lib/load-configuration"
+
+# shellcheck disable=SC2016
+usage() {
+ >&2 echo 'usage:'
+ >&2 echo ' create-build-support-package [options] --from $pkgname-$epoch:$pkgver-$pkgrel.$sub_pkgrel [--] $file1 $file2 $file3 ...'
+ >&2 echo ' create $pkgname-shim containing'
+ >&2 echo ' $file1, $file2, ... from the original package'
+ >&2 echo ' create-build-support-package [options] --shim $pkgfile'
+ >&2 echo ' insert $pkgfile into $repo_arch/build-support/$pkgname-shim'
+ >&2 echo ''
+ >&2 echo 'possible options:'
+ >&2 echo ' -a|--arch $repo_arch: (required)'
+ >&2 echo ' Operate on repository of given architecture.'
+ >&2 echo ' -h|--help:'
+ >&2 echo ' Show this help and exit.'
+ >&2 echo ' -w|--wait:'
+ >&2 echo ' Wait for lock if necessary.'
+ [ -z "$1" ] && exit 1 || exit "$1"
+}
+
+eval set -- "$(
+ getopt -o a:hw \
+ --long arch \
+ --long from \
+ --long help \
+ --long shim \
+ --long wait \
+ -n "$(basename "$0")" -- "$@" || \
+ echo usage
+ )"
+
+repo_arch=''
+shim_package=''
+source_package=''
+wait_for_lock='-n'
+while true; do
+ case "$1" in
+ -a|--arch)
+ if [ -n "${repo_arch}" ]; then
+ >&2 prinf -- '-a|--arch given more than once.\n'
+ usage
+ fi
+ shift
+ repo_arch="$1"
+ ;;
+ --from)
+ if [ -n "${source_package}" ]; then
+ >&2 prinf -- '--from given more than once.\n'
+ usage
+ fi
+ shift
+ source_package="$1"
+ ;;
+ -h|--help)
+ usage 0
+ ;;
+ --shim)
+ if [ -n "${shim_package}" ]; then
+ >&2 prinf -- '--shim given more than once.\n'
+ usage
+ fi
+ shift
+ shim_package="$1"
+ ;;
+ -w|--wait)
+ wait_for_lock=''
+ ;;
+ --)
+ shift
+ break
+ ;;
+ *)
+ >&2 printf 'Whoops, forgot to implement option "%s" internally.\n' \
+ "$1"
+ exit 42
+ ;;
+ esac
+done
+
+if [ -n "${source_package}" ] \
+ && [ -n "${shim_package}" ]; then
+ >&2 echo 'Conflicting parameters: --from and --shim'
+ usage
+fi
+
+exec 9> "${sanity_check_lock_file}"
+verbose_flock -s ${wait_for_lock} 9
+
+tmp_dir=$(mktemp -d 'tmp.create-build-support.XXXXXXXXXX')
+# shellcheck disable=SC2064
+trap "rm -rf --one-file-system '${tmp_dir:?}'" EXIT
+
+if [ -n "${source_package}" ]; then
+ # create shim_package from source_package
+
+ if [ $# -eq 0 ]; then
+ usage 1
+ fi
+
+ pkg=$(
+ # shellcheck disable=SC2016
+ {
+ printf 'SELECT DISTINCT '
+ mysql_package_name_query
+ printf ' FROM `binary_packages`'
+ mysql_join_binary_packages_binary_packages_in_repositories
+ mysql_join_binary_packages_in_repositories_repositories
+ mysql_join_repositories_architectures
+ printf ' WHERE `repositories`.`is_on_master_mirror`'
+ printf ' AND `architectures`.`name`=from_base64("%s")' \
+ "$(
+ printf '%s' "${repo_arch}" \
+ | base64 -w0
+ )"
+ printf ' AND '
+ mysql_package_name_query '' 'XX' \
+ | sed '
+ s/,"-",`XX.*\.pkg\.tar\.xz"//
+ '
+ printf '=from_base64("%s")' \
+ "$(
+ printf '%s' "${source_package}" \
+ | base64 -w0
+ )"
+ } \
+ | mysql_run_query \
+ | tr '\t' ' '
+ )
+
+ if [ -z "${pkg}" ]; then
+ >&2 printf 'Could not find %s/%s in the database.\n' \
+ "${repo_arch}" "${source_package}"
+ exit 1
+ fi
+
+ if printf '%s\n' "${pkg}" \
+ | wc -l \
+ | grep -vqxF '1'; then
+ >&2 printf 'Package %s/%s was found multiple times:\n' \
+ "${repo_arch}" "${source_package}"
+ >&2 printf '%s\n' "${pkg}"
+ exit 1
+ fi
+
+ new_pkg="${pkg%-*-*-*}"
+ new_pkg="${new_pkg}-shim${pkg#${new_pkg}}"
+
+ failsafe_rsync \
+ "${master_mirror_rsync_directory}/pool/${pkg}" \
+ "${tmp_dir}/"
+
+ mkdir "${tmp_dir}/content"
+ bsdtar -C "${tmp_dir}/content" -xf "${tmp_dir}/${pkg}" \
+ '.BUILDINFO' \
+ '.PKGINFO' \
+ "$@"
+
+ # TODO: mangle customizable meta-infos here (new provides, keep some
+ # depends)
+ sed -i '
+ /^pkgname = / s/ \S\+$/\0-shim\nprovides =\0/
+ /^depend = /d
+ ' "${tmp_dir}/content/.PKGINFO"
+
+ # from /usr/bin/makepkg
+ list_package_files() {
+ (
+ cd "${tmp_dir}/content"
+ find . -path './.*' \! -name '.'; find . \! -path './.*' \! -name '.' \
+ | LC_ALL=C sort
+ ) \
+ | sed -e 's|^\./||' \
+ | tr '\n' '\0'
+ }
+
+ list_package_files \
+ | LANG=C bsdtar -C "${tmp_dir}/content" -cnf - --format=mtree \
+ --options='!all,use-set,type,uid,gid,mode,time,size,md5,sha256,link' \
+ --null --files-from - --exclude .MTREE \
+ | gzip -c -f -n \
+ > "${tmp_dir}/content/.MTREE"
+
+ list_package_files \
+ | LANG=C bsdtar -C "${tmp_dir}/content" -cnf - --null --files-from - \
+ | xz -c -z - \
+ > "${tmp_dir}/${new_pkg}"
+
+ rm -rf --one-file-system "${tmp_dir:?}/content"
+ mv "${tmp_dir}/${new_pkg}" "${work_dir}/"
+ >&2 printf 'Please sign %s with a build slave key and run\n' \
+ "${work_dir}/${new_pkg}"
+ # shellcheck disable=SC2016
+ >&2 printf 'create-build-support-package --shim $pkgfile\n'
+
+elif [ -n "${shim_package}" ]; then
+ # insert shim_package into [build-support]
+
+ exec 8> "${package_database_lock_file}"
+ verbose_flock ${wait_for_lock} 8
+
+ # TODO: find original package in database, check signature, retrieve
+ # db, insert package into db, copy row in `binary_packages`, insert
+ # row into `binary_packages_in_repositories`, add package to pool/,
+ # send db
+
+else
+ >&2 echo 'Need either --from or --shim.'
+ usage
+fi