#!/bin/sh # shellcheck disable=SC2119,SC2120 # shellcheck source=../lib/load-configuration . "${0%/*}/../lib/load-configuration" usage() { >&2 echo '' >&2 echo 'Usage: prioritize-build-list [options] pkg-regex-file' >&2 echo ' moves packages matching any pkg-regex in pkg-regex-file' >&2 echo ' to front of build list' >&2 echo '' >&2 echo 'possible options:' >&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 hw \ --long help \ --long wait \ -n "$(basename "$0")" -- "$@" || \ echo usage )" wait_for_lock='-n' while true do case "$1" in -h|--help) usage 0 ;; -w|--wait) wait_for_lock='' ;; --) shift break ;; *) >&2 echo 'Whoops, forgot to implement option "'"$1"'" internally.' exit 42 ;; esac shift done if [ $# -ne 1 ]; then >&2 echo 'No package-regex-list was given.' usage fi if [ ! -r "$1" ]; then >&2 printf 'Package-list "%s" is not readable.\n' "$1" usage fi if [ ! -s "$1" ]; then >&2 echo 'Empty regex file - nothing to do here.' exit fi # Create a lock file for build list. exec 9> "${sanity_check_lock_file}" verbose_flock -s ${wait_for_lock} 9 exec 8> "${build_list_lock_file}" verbose_flock ${wait_for_lock} 8 # shellcheck disable=SC2016 { printf 'UPDATE `build_assignments`' mysql_join_build_assignments_package_sources mysql_join_build_assignments_binary_packages mysql_join_binary_packages_binary_packages_in_repositories mysql_join_binary_packages_in_repositories_repositories printf ' SET `build_assignments`.`priority`=(' printf 'SELECT COALESCE(MAX(`all_priorities`.`priority`),0)+1' printf ' FROM (' printf 'SELECT `others`.`priority`' printf ' FROM `build_assignments` AS `others`' printf ') AS `all_priorities`' printf ')' printf ' WHERE (' base64_encode_each < "$1" | \ sed ' s/^/`package_sources`.`pkgbase` REGEXP from_base64("/ s/$/") OR / $ s/ OR $// ' printf ') AND `repositories`.`name`="build-list";\n' printf 'SELECT row_count();\n' } | \ mysql_run_query | \ if [ -w "$1" ]; then cat > "$1" else cat >&2 fi # Remove the lock file rm -f "${build_list_lock_file}"