diff options
author | Jan Pokorný <jpokorny@redhat.com> | 2013-05-06 22:22:24 +0200 |
---|---|---|
committer | Jan Pokorný <jpokorny@redhat.com> | 2013-05-06 22:22:24 +0200 |
commit | 3c2e648cf35eee4f4bf7e55c9c3eb09a55b9645b (patch) | |
tree | 98f67556b71ce455148505056406cdea3541e3a2 | |
parent | 4905097ceabec9eb8e9a429e43c71424f9038c38 (diff) | |
download | watch-bz-3c2e648cf35eee4f4bf7e55c9c3eb09a55b9645b.tar.gz watch-bz-3c2e648cf35eee4f4bf7e55c9c3eb09a55b9645b.tar.xz watch-bz-3c2e648cf35eee4f4bf7e55c9c3eb09a55b9645b.zip |
Fix annoying situation with 2+ started instances waiting for password
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
-rwxr-xr-x | watch-bz | 70 |
1 files changed, 44 insertions, 26 deletions
@@ -87,36 +87,54 @@ do_logout () { rm "${BUGZILLA_COOKIE}" && echo "watch-bz: Authorization cookie removed" } -# exclusively using globals -do_init () { - # login when available - if [ -n "$BZUSER" ] && [ ! -f "${BUGZILLA_COOKIE}" ]; then - [ -n "$BZPASSWORD" ] \ - || read -s -t 60 -p 'Password (1 min timeout): ' BZPASSWORD \ - || exit $? - if which expect &>/dev/null; then - expect - <<-EOF - log_user 0 - spawn $BUGZILLA --cookiefile=${BUGZILLA_COOKIE} login $BZUSER - expect "Password: " - send "${BZPASSWORD}\r" - send_user "wait a bit..." - expect eof - EOF - else - echo "Passing password through command-line argument is DANGEROUS" - local yn; read -p 'Continue? [yN]' yn - [ "${yn}" -ne "y" ] && exit - spawn $BUGZILLA --cookiefile=${BUGZILLA_COOKIE} login $BZUSER $BZPASSWORD - fi - if [ $? -ne 0 ]; then - echo "Cannot log in" - exit 2 - fi +do_init_login () { + if [ -z "$BZPASSWORD" ]; then + trap return USR1 + { + timeout 60 /bin/sh -c \ + "while [ ! -f \"${BUGZILLA_COOKIE}\" ]; do \ + sleep 1; \ + done" \ + && echo "wow, cookie emerged" + kill -USR1 -$$ + } & read -s -p 'Password (1 min timeout): ' BZPASSWORD \ + || return $? + trap '' USR1 + fi + + rm -f -- ${BUGZILLA_COOKIE}.init + if which expect &>/dev/null; then + expect - <<-EOF + log_user 0 + spawn $BUGZILLA --cookiefile=${BUGZILLA_COOKIE}.init login $BZUSER + expect "Password: " + send "${BZPASSWORD}\r" + send_user "wait a bit..." + expect eof + EOF + else + echo "Passing password through command-line argument is DANGEROUS" + local yn; read -p 'Continue? [yN]' yn + [ "${yn}" -ne "y" ] && exit + spawn $BUGZILLA --cookiefile=${BUGZILLA_COOKIE}.init login $BZUSER $BZPASSWORD + fi + if [ $? -ne 0 ]; then + echo "Cannot log in" + return 2 fi + cp -n -- ${BUGZILLA_COOKIE}{.init,} + rm -f -- ${BUGZILLA_COOKIE}.init +} +# exclusively using globals +do_init () { # C-c handler to optionally remove cookie on exit test $BUGZILLA_LOGOUT -ne 0 && trap do_logout INT + + # login when appropriate + if [ -n "$BZUSER" ] && [ ! -f "${BUGZILLA_COOKIE}" ]; then + do_init_login || exit $? + fi } # exclusively using globals |