From 8fe4fd8722fa03b9a118b20ad826085279dd78e6 Mon Sep 17 00:00:00 2001 From: Colin Guthrie Date: Thu, 31 Jul 2014 17:31:36 +0100 Subject: move: Bail if we pass --no-confirm, but do not supply all SRPM names. As --no-confirm may be used from automated scripts, better bail out here rather than waiting for user input that will never come. --- mga-move-pkg | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/mga-move-pkg b/mga-move-pkg index 6662476..0f5af54 100755 --- a/mga-move-pkg +++ b/mga-move-pkg @@ -145,25 +145,33 @@ function sanity_check() { local cauldronmsg - if [ "$_fullsrpmname" != "y" -o -z "$noconfirm" ]; then - echo "The following SRPMs (and matching binaries) will be moved:" - for ((i=0;i<${#_releases[*]};++i)); do - echo "- ${_pkgfiles[$i]}" - if [ 'release' = "${_destsubsections[$i]}" -a -n "${_oldpkgfiles[$i]}" ]; then - cauldronmsg="${cauldronmsg}- ${_oldpkgfiles[$i]}\n" - fi - done - echo - if [ -n "$cauldronmsg" ]; then - echo "The following SRPMs (and matching binaries) will be moved from 'release' to '\~schedbot/old':" - echo "$cauldronmsg" + if [ -n "$noconfirm" ]; then + # We've requested no confirmation. This is only valid when the user + # supplies a full SRPM name for every package. + [ "$_fullsrpmname" = "y" ] && return 0 + echo "Sorry, but you requested --no-confirm, but did not give me full SRPM names." >&1 + exit 1 + fi + + echo "The following SRPMs (and their corresponding binaries) will be moved:" + for ((i=0;i<${#_releases[*]};++i)); do + echo "- ${_pkgfiles[$i]}" + if [ 'release' = "${_destsubsections[$i]}" -a -n "${_oldpkgfiles[$i]}" ]; then + cauldronmsg="${cauldronmsg}- ${_oldpkgfiles[$i]}\n" fi + done + echo - read -n 1 -p "Are you sure? [Y/n] " yn - [ -n "$yn" ] && echo - [ -z "$yn" -o "Y" = "$yn" ] && yn=y - [ "y" != "$yn" ] && exit + if [ -n "$cauldronmsg" ]; then + echo "The following SRPMs (and their corresponding binaries) will be moved from 'release' to '\~schedbot/old':" + echo "$cauldronmsg" + # The above always ends with a blank line... so no need to echo another fi + + read -n 1 -p "Are you sure? [Y/n] " yn + [ -n "$yn" ] && echo + [ -z "$yn" -o "Y" = "$yn" ] && yn=y + [ "y" != "$yn" ] && exit return 0 } sanity_check -- cgit v1.2.1