From 074c1edec52c2c4faacc33043083669735e62a51 Mon Sep 17 00:00:00 2001 From: frank-cizmich Date: Mon, 18 May 2015 14:25:25 -0300 Subject: [PATCH] pt-mysql-summary added ask-pass option --- bin/pt-mysql-summary | 15 ++++++++++++++- lib/bash/mysql_options.sh | 10 +++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/bin/pt-mysql-summary b/bin/pt-mysql-summary index 57a81806..0065df5a 100755 --- a/bin/pt-mysql-summary +++ b/bin/pt-mysql-summary @@ -75,6 +75,7 @@ HAVE_EXT_ARGV="" # Got --, everything else is put into EXT_ARGV OPT_ERRS=0 # How many command line option errors OPT_VERSION="" # If --version was specified OPT_HELP="" # If --help was specified +OPT_ASK_PASS="" # If --ask-pass was specified PO_DIR="" # Directory with program option spec files usage() { @@ -175,6 +176,7 @@ parse_options() { OPT_ERRS=0 OPT_VERSION="" OPT_HELP="" + OPT_ASK_PASS="" PO_DIR="$PT_TMPDIR/po" if [ ! -d "$PO_DIR" ]; then @@ -489,7 +491,14 @@ mysql_options() { if [ -n "$OPT_USER" ]; then MYSQL_ARGS="$MYSQL_ARGS --user=$OPT_USER" fi - if [ -n "$OPT_PASSWORD" ]; then + if [ -n "$OPT_ASK_PASS" ]; then + stty -echo + >&2 printf "Enter MySQL password: " + read GIVEN_PASS + stty echo + printf "\n" + MYSQL_ARGS="$MYSQL_ARGS --password=$GIVEN_PASS" + elif [ -n "$OPT_PASSWORD" ]; then MYSQL_ARGS="$MYSQL_ARGS --password=$OPT_PASSWORD" fi @@ -2923,6 +2932,10 @@ All options after -- are passed to C. mysqldump and summarize all databases. See L<"--databases">. +=item --ask-pass + +Prompt for a password when connecting to MySQL. + =item --config type: string diff --git a/lib/bash/mysql_options.sh b/lib/bash/mysql_options.sh index c248bd1f..09a9e5d5 100644 --- a/lib/bash/mysql_options.sh +++ b/lib/bash/mysql_options.sh @@ -40,7 +40,15 @@ mysql_options() { if [ -n "$OPT_USER" ]; then MYSQL_ARGS="$MYSQL_ARGS --user=$OPT_USER" fi - if [ -n "$OPT_PASSWORD" ]; then + # handle ask-pass option (issue lp#1455486) + if [ -n "$OPT_ASK_PASS" ]; then + stty -echo + >&2 printf "Enter MySQL password: " + read GIVEN_PASS + stty echo + printf "\n" + MYSQL_ARGS="$MYSQL_ARGS --password=$GIVEN_PASS" + elif [ -n "$OPT_PASSWORD" ]; then MYSQL_ARGS="$MYSQL_ARGS --password=$OPT_PASSWORD" fi