From 3c1f6750e8f906d8230266f904d69ce76d8909b9 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Wed, 21 Mar 2018 10:15:31 +0100 Subject: bin/copy-to-build-support: --wait new --- bin/copy-to-build-support | 56 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 3 deletions(-) (limited to 'bin/copy-to-build-support') diff --git a/bin/copy-to-build-support b/bin/copy-to-build-support index b3decd4..404a2b9 100755 --- a/bin/copy-to-build-support +++ b/bin/copy-to-build-support @@ -5,12 +5,62 @@ # shellcheck source=conf/default.conf . "${0%/*}/../conf/default.conf" +# shellcheck disable=SC2016 +usage() { + >&2 echo '' + >&2 echo 'copy-to-build-support [options] package-list:' + >&2 echo ' copy the packages listed in package-list into [build-support]' + >&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 'usage:' - >&2 echo ' copy-to-build-support package-list' - exit 2 + >&2 echo 'No package-list was given.' + usage fi +exec 9> "${sanity_check_lock_file}" +flock -s ${wait_for_lock} 9 + +exec 8> "${package_database_lock_file}" +flock ${wait_for_lock} 8 + tmp_dir=$(mktemp -d "${work_dir}/tmp.copy-to-build-support.0.XXXXXXXXXX") trap 'rm -rf --one-file-system "${tmp_dir}"' EXIT -- cgit v1.2.3-70-g09d2