slitaz-base-files rev 309

libtaz.sh: confirm(): handle '--noconfirm'.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Fri Jul 22 09:37:14 2016 +0300 (2016-07-22)
parents 05b76c5655d0
children 0b27d733c811
files rootfs/lib/libtaz.sh
line diff
     1.1 --- a/rootfs/lib/libtaz.sh	Sun May 29 13:11:28 2016 +0300
     1.2 +++ b/rootfs/lib/libtaz.sh	Fri Jul 22 09:37:14 2016 +0300
     1.3 @@ -157,17 +157,24 @@
     1.4  
     1.5  # Confirmation
     1.6  confirm() {
     1.7 -	if [ -n "$yes" ]; then
     1.8 -		true
     1.9 +	local answer=''
    1.10 +	# Check auto-answer, if any
    1.11 +	[ -n "$yes" ] && answer='y'
    1.12 +	[ -n "$noconfirm" ] && answer='n'
    1.13 +	# Print question
    1.14 +	if [ -n "$1" ]; then
    1.15 +		echo -n "$1 "
    1.16  	else
    1.17 -		if [ -n "$1" ]; then
    1.18 -			echo -n "$1 "
    1.19 -		else
    1.20 -			echo -n " ($(translate_query y)/$(translate_query N)) ? "
    1.21 -		fi
    1.22 +		echo -n " ($(translate_query y)/$(translate_query N)) ? "
    1.23 +	fi
    1.24 +	# Is it auto-answer?
    1.25 +	if [ -z "$answer" ]; then
    1.26  		read answer
    1.27 -		[ "$answer" == "$(translate_query y)" ]
    1.28 +	else
    1.29 +		translate_query "$answer"; echo ' (auto)'
    1.30  	fi
    1.31 +	# Return true/false to use in conditions
    1.32 +	[ "$answer" == "$(translate_query y)" ]
    1.33  }
    1.34  
    1.35  # Log activities