From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org)
	by finch.gentoo.org with esmtp (Exim 4.60)
	(envelope-from <gentoo-commits+bounces-437140-garchives=archives.gentoo.org@lists.gentoo.org>)
	id 1S5iMJ-0005Vb-3d
	for garchives@archives.gentoo.org; Thu, 08 Mar 2012 18:46:39 +0000
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id 7954FE06FD;
	Thu,  8 Mar 2012 18:46:31 +0000 (UTC)
Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183])
	by pigeon.gentoo.org (Postfix) with ESMTP id 39371E06FD
	for <gentoo-commits@lists.gentoo.org>; Thu,  8 Mar 2012 18:46:31 +0000 (UTC)
Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163])
	(using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by smtp.gentoo.org (Postfix) with ESMTPS id 70AB71B4037
	for <gentoo-commits@lists.gentoo.org>; Thu,  8 Mar 2012 18:46:30 +0000 (UTC)
Received: from localhost.localdomain (localhost [127.0.0.1])
	by hornbill.gentoo.org (Postfix) with ESMTP id 3A007E5428
	for <gentoo-commits@lists.gentoo.org>; Thu,  8 Mar 2012 18:46:29 +0000 (UTC)
From: "Mike Frysinger" <vapier@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Content-type: text/plain; charset=UTF-8
Reply-To: gentoo-dev@lists.gentoo.org, "Mike Frysinger" <vapier@gentoo.org>
Message-ID: <1331232329.0788886b0e001fcf57d4c1bddded1d809b5d9d31.vapier@gentoo>
Subject: [gentoo-commits] proj/portage:master commit in: bin/
X-VCS-Repository: proj/portage
X-VCS-Files: bin/etc-update
X-VCS-Directories: bin/
X-VCS-Committer: vapier
X-VCS-Committer-Name: Mike Frysinger
X-VCS-Revision: 0788886b0e001fcf57d4c1bddded1d809b5d9d31
X-VCS-Branch: master
Date: Thu,  8 Mar 2012 18:46:29 +0000 (UTC)
Precedence: bulk
List-Post: <mailto:gentoo-commits@lists.gentoo.org>
List-Help: <mailto:gentoo-commits+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org>
X-BeenThere: gentoo-commits@lists.gentoo.org
Content-Transfer-Encoding: quoted-printable
X-Archives-Salt: 512ba5e3-8911-4199-9e11-c1f20e64468c
X-Archives-Hash: 63592f9443f1af54749b37cc2ef78ac1

commit:     0788886b0e001fcf57d4c1bddded1d809b5d9d31
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Thu Mar  8 18:45:29 2012 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Thu Mar  8 18:45:29 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=3Dproj/portage.git;a=
=3Dcommit;h=3D0788886b

etc-update: turn -[3579] flags into command line option

This lets people do `etc-update --automode -3` rather than having
to do something like `echo "-3" | etc-update`.

Signed-off-by: Mike Frysinger <vapier <AT> gentoo.org>

---
 bin/etc-update |   85 +++++++++++++++++++++++++++++++++++---------------=
-----
 1 files changed, 54 insertions(+), 31 deletions(-)

diff --git a/bin/etc-update b/bin/etc-update
index 4058229..989d367 100755
--- a/bin/etc-update
+++ b/bin/etc-update
@@ -148,7 +148,39 @@ scan() {
 			fi
 		done
 	done
+}
=20
+parse_automode_flag() {
+	case $1 in
+	-9)
+		local reply
+		read -p "Are you sure that you want to delete all updates (type YES): =
" reply
+		if [[ ${reply} !=3D "YES" ]] ; then
+			echo "Did not get a 'YES', so ignoring request"
+			return 1
+		else
+			parse_automode_flag -7
+			export rm_opts=3D""
+		fi
+		;;
+	-7)
+		input=3D0
+		export DELETE_ALL=3D"yes"
+		;;
+	-5)
+		parse_automode_flag -3
+		export mv_opts=3D" ${mv_opts} "
+		mv_opts=3D"${mv_opts// -i / }"
+		;;
+	-3)
+		input=3D0
+		export OVERWRITE_ALL=3D"yes"
+		;;
+	*)
+		return 1
+		;;
+	esac
+	return 0
 }
=20
 sel_file() {
@@ -189,11 +221,11 @@ sel_file() {
 					$(<"${TMP}"/menuitems)
 					Please select a file to edit by entering the corresponding number.
 					              (don't use -3, -5, -7 or -9 if you're unsure what to =
do)
-					              (-1 to exit) (-3 to auto merge all remaining files)
-					                           (-5 to auto-merge AND not use 'mv -i')
-					                           (-7 to discard all updates)
+					              (-1 to exit) (${_3_HELP_TEXT})
+					                           (${_5_HELP_TEXT})
+					                           (${_7_HELP_TEXT})
 				EOF
-				printf "                           (-9 to discard all updates AND no=
t use 'rm -i'): "
+				printf "                           (${_9_HELP_TEXT}): "
 				input=3D$(read_int)
 			else
 				dialog \
@@ -204,28 +236,8 @@ sel_file() {
 					|| die "$(<"${TMP}"/input)\n\nUser termination!" 0
 				input=3D$(<"${TMP}"/input)
 			fi
-			if [[ ${input} =3D=3D -9 ]] ; then
-				read -p "Are you sure that you want to delete all updates (type YES)=
: " reply
-				if [[ ${reply} !=3D "YES" ]] ; then
-					continue
-				else
-					input=3D-7
-					export rm_opts=3D""
-				fi
-			fi
-			if [[ ${input} =3D=3D -7 ]] ; then
-				input=3D0
-				export DELETE_ALL=3D"yes"
-			fi
-			if [[ ${input} =3D=3D -5 ]] ; then
-				input=3D-3
-				export mv_opts=3D" ${mv_opts} "
-				mv_opts=3D"${mv_opts// -i / }"
-			fi
-			if [[ ${input} =3D=3D -3 ]] ; then
-				input=3D0
-				export OVERWRITE_ALL=3D"yes"
-			fi
+
+			parse_automode_flag ${input} || continue
 		fi # -3 automerge
 		if [[ ${input:-0} =3D=3D 0 ]] ; then
 			input=3D${isfirst}
@@ -524,6 +536,10 @@ die() {
 	exit ${exitcode}
 }
=20
+_3_HELP_TEXT=3D"-3 to auto merge all files"
+_5_HELP_TEXT=3D"-5 to auto-merge AND not use 'mv -i'"
+_7_HELP_TEXT=3D"-7 to discard all updates"
+_9_HELP_TEXT=3D"-9 to discard all updates AND not use 'rm -i'"
 usage() {
 	cat <<-EOF
 	etc-update: Handle configuration file updates
@@ -535,6 +551,12 @@ usage() {
 	  -h, --help     Show help and run away
 	  -v, --verbose  Show settings and such along the way
 	  -V, --version  Show version and trundle away
+
+	  --automode <mode>
+	             ${_3_HELP_TEXT}
+	             ${_5_HELP_TEXT}
+	             ${_7_HELP_TEXT}
+	             ${_9_HELP_TEXT}
 	EOF
=20
 	[[ $# -gt 1 ]] && printf "\nError: %s\n" "${*:2}" 1>&2
@@ -546,6 +568,10 @@ usage() {
 # Run the script
 #
=20
+declare -i count=3D0
+declare input=3D0
+declare title=3D"Gentoo's etc-update tool!"
+
 SET_X=3Dfalse
 VERBOSE=3Dfalse
 while [[ -n $1 ]] ; do
@@ -553,7 +579,8 @@ while [[ -n $1 ]] ; do
 		-d|--debug)   SET_X=3Dtrue;;
 		-h|--help)    usage;;
 		-v|--verbose) VERBOSE=3Dtrue;;
-		-V|--version) emerge --version ; exit 0;;
+		-V|--version) emerge --version; exit 0;;
+		--automode)   parse_automode_flag $2 && shift || usage 1 "Invalid mode=
 '$2'";;
 		*)            usage 1 "Invalid option '$1'";;
 	esac
 	shift
@@ -641,10 +668,6 @@ if ${VERBOSE} ; then
 	done
 fi
=20
-declare -i count=3D0
-declare input=3D0
-declare title=3D"Gentoo's etc-update tool!"
-
 scan
=20
 until (( input =3D=3D -1 )); do