1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
# gitpkg hook script to push the exported package off for building via cowpoke
#
# To enable this hook, use:
# git config gitpkg.exit-hook /usr/share/gitpkg/hooks/cowpoke-exit-hook
# We're out of the repo tree, but want to check git-config
. /usr/share/gitpkg/hooks/repo-config-helper
# We need bash 4.4 or later for the ${var@Q} parameter transformation, so check
# and bail out here with a friendly warning instead of crashing obscurely later.
require_bash_version 4.4
# The --sign-source-changes option is a bit special, as --no-sign-source-changes
# is not just "don't pass this option", it's "pass a different option instead"
# equivalent in this case to --sign-source-changes=no.
get_option_value 'COWPOKE_SSC' 'sign-source-changes' \
'gitpkg-cowpoke-exit-hook.source-changes' 'notset'
EXTRA_COWPOKE_OPTS=()
case ${COWPOKE_SSC-unset} in
""|true|yes|signed) EXTRA_COWPOKE_OPTS+=( '--sign-source-changes' ) ;;
unset|false|no) EXTRA_COWPOKE_OPTS+=( '--no-sign-source-changes' ) ;;
notset) ;;
*)
echo "Unknown option value for --sign-source-changes '$COWPOKE_SSC'. Stopping."
exit 1
;;
esac
# --cowpoke command line options override the git config .options settings.
# Any cowpoke(1) option can be passed via --cowpoke or .options, but we have
# these specialised config options as well so that it is easy to override
# (and make overridable) a subset them without having to manually re-enter
# all of what would otherwise be the default configuration.
#
# Multi-value options:
get_option_values 'COWPOKE_OPTS' 'cowpoke' 'gitpkg-cowpoke-exit-hook.options'
get_option_values 'COWPOKE_ARCH' 'arch' 'gitpkg-cowpoke-exit-hook.arch'
get_option_values 'COWPOKE_DIST' 'dist' 'gitpkg-cowpoke-exit-hook.dist'
get_option_values 'COWPOKE_DPKG_BP' 'dpkg-bp' 'gitpkg-cowpoke-exit-hook.dpkg-bp'
# Single-value options:
get_option_value 'COWPOKE_SIGN' 'sign' 'gitpkg-cowpoke-exit-hook.sign-key'
get_option_value 'COWPOKE_UPLOAD' 'upload' 'gitpkg-cowpoke-exit-hook.upload-to'
get_option_value 'COWPOKE_RETURN' 'return' 'gitpkg-cowpoke-exit-hook.return-dir'
# Remove empty elements from this one so we can use --no-cowpoke to override config
# default settings and pass no options without having a stray "" as an option word.
trim_array 'COWPOKE_OPTS'
# And from these, as it never makes sense to pass an empty arch or dist.
trim_array 'COWPOKE_ARCH'
trim_array 'COWPOKE_DIST'
COWPOKE_OPTS+=( "${COWPOKE_ARCH[@]/#/--arch=}"
"${COWPOKE_DIST[@]/#/--dist=}"
"${COWPOKE_DPKG_BP[@]/#/--dpkg-bp=}"
${COWPOKE_SIGN+"--sign=${COWPOKE_SIGN}"}
${COWPOKE_UPLOAD+"--upload=${COWPOKE_UPLOAD}"}
${COWPOKE_RETURN+"--return${COWPOKE_RETURN:+=$COWPOKE_RETURN}"}
"${EXTRA_COWPOKE_OPTS[@]}"
)
# The option of a veto is a handy safety catch for running an unexpected hook,
# but if the user has explicitly passed a cowpoke-specific command line option
# then we'll take that as an implicit assent, and expressed intent, to proceed.
ASK_YES_OPTS=( 'cowpoke' 'arch' 'dist' 'upload' 'return' )
if [ "$(repo_config --get --bool gitpkg-cowpoke-exit-hook.ask-first)" = 'true' ] &&
! have_any_of_these_commandline_options "${ASK_YES_OPTS[@]}"
then
printf "Send $DEB_DSC off to cowpoke now (Y/n)? "
read -e yesno
case $yesno in
N* | n*)
echo "Ok, you're the boss. If you change your mind, just run:"
echo "cowpoke" "${COWPOKE_OPTS[@]@Q}" "$DEB_DSC"
echo
exit 0
;;
"") echo "Yes" # read doesn't echo a line feed if the user just hit <enter>
;;
*) ;;
esac
fi
echo "cowpoke" "${COWPOKE_OPTS[@]@Q}" "$DEB_DSC"
cowpoke "${COWPOKE_OPTS[@]}" "$DEB_DSC"
# vi:sts=4:sw=4:noet:foldmethod=marker
|