Fix prompt_user non-interactive mode

This commit is contained in:
Augusto Gunsch 2021-08-12 18:27:03 -03:00
parent 348eaab74d
commit 1408040294
No known key found for this signature in database
GPG Key ID: F7EEFE29825C72DC
1 changed files with 9 additions and 5 deletions

View File

@ -86,6 +86,9 @@ exclusive()
usage usage
} }
NO_CONFIRM=0
VERBOSE=0
while getopts ":nvhdpu:" c; do while getopts ":nvhdpu:" c; do
case $c in case $c in
d) d)
@ -100,8 +103,8 @@ while getopts ":nvhdpu:" c; do
u) u)
[ "$INSTALL" = "PACKAGES" ] && exclusive '-p' '<user>' [ "$INSTALL" = "PACKAGES" ] && exclusive '-p' '<user>'
set_var INSTALL_USER $OPTARG "-u" ;; set_var INSTALL_USER $OPTARG "-u" ;;
n) NO_CONFIRM=true ;; n) NO_CONFIRM=1 ;;
v) VERBOSE=true ;; v) VERBOSE=1 ;;
h) usage ;; h) usage ;;
?) echo "Unknown option -$OPTARG"; usage ;; ?) echo "Unknown option -$OPTARG"; usage ;;
esac esac
@ -128,10 +131,11 @@ if [ -n "$INSTALL_USER" ]; then
fi fi
prompt_user() { prompt_user() {
[ $NO_CONFIRM -eq 1 ] && USER_OUT="$INSTALL_USER" && return 0
echo -n "Please type user for whom $1 (leave blank to use same user as with dotfiles or to skip step): " echo -n "Please type user for whom $1 (leave blank to use same user as with dotfiles or to skip step): "
local user local user
read user read user
[ -z "$user" ] && USER_OUT="$INSTALL_USER" && return [ -z "$user" ] && USER_OUT="$INSTALL_USER" && return 0
set +e set +e
USER_OUT="$user" USER_OUT="$user"
check_user "$user" check_user "$user"
@ -145,7 +149,7 @@ prompt_user() {
### ASK FOR CONFIRMATION ### ### ASK FOR CONFIRMATION ###
if [ ! $NO_CONFIRM ]; then if [ $NO_CONFIRM -eq 0 ]; then
echo "${BOLD}Please confirm operation:${NORM}" echo "${BOLD}Please confirm operation:${NORM}"
echo -ne "Installing ${LGREEN}${INSTALL@L}${NC}" echo -ne "Installing ${LGREEN}${INSTALL@L}${NC}"
[ -n "$INSTALL_USER" ] && echo -ne " for ${LGREEN}$INSTALL_USER ($HOME_DIR)${NC}" [ -n "$INSTALL_USER" ] && echo -ne " for ${LGREEN}$INSTALL_USER ($HOME_DIR)${NC}"
@ -209,7 +213,7 @@ install() {
prompt() { prompt() {
echo -n "$1 [Y/n] " echo -n "$1 [Y/n] "
[ $NO_CONFIRM ] && echo "y" && return 1 [ $NO_CONFIRM -eq 1 ] && echo "y" && return 1
read ans read ans
case $ans in case $ans in
n|N) return 0 ;; n|N) return 0 ;;