File rpm-distribution.patch of Package etc-update

etc-update: Basic support for RPM distributions

Making etc-update aware of new configuration files that rpm loves to create and
making it work on non Gentoo distributions by setting some reasonable defaults
if we can't rely on portageq and we are not on Gentoo.

Index: etc-update
===================================================================
--- etc-update.orig
+++ etc-update
@@ -77,10 +77,10 @@ scan() {
 			[[ ! -f ${path} ]] && continue
 			local my_basename="${path##*/}"
 			path="${path%/*}"
-			find_opts=( -maxdepth 1 -name "._cfg????_${my_basename}" )
+			find_opts=( -maxdepth 1 \( -name "._cfg????_${my_basename}" -o -name "${my_basename}.rpmnew" \) )
 		else
 			# Do not traverse hidden directories such as .svn or .git.
-			find_opts=( -name '.*' -type d -prune -o -name '._cfg????_*' )
+			find_opts=( -name '.*' -type d -prune -o \( -name '._cfg????_*' -o -name '*.rpmnew' \) )
 		fi
 		find_opts+=( ! -name '.*~' ! -iname '.*.bak' -print )
 
@@ -93,7 +93,8 @@ scan() {
 		for file in $(find "${path}"/ "${find_opts[@]}" |
 		              sed \
 						-e 's://*:/:g' \
-						-e "s:\(^.*/\)\(\._cfg[0-9]*_\)\(.*$\):\1\2\3$b\1$b\2$b\3:" |
+						-e "s:\(^.*/\)\(\._cfg[0-9]*_\)\(.*$\):\1\2\3$b\1$b\2$b\3:" \
+						-e "s:\(^.*/\)\(.*\)\(\.rpmnew\):\1\2\3$b\1$b\3$b\2:" |
 		              sort -t"$b" -k2,2 -k4,4 -k3,3 |
 		              LC_ALL=C cut -f1 -d"$b")
 		do
@@ -101,7 +102,8 @@ scan() {
 			rpath=${file%/*}
 			rfile=${file##*/}
 			cfg_file="${rpath}/${rfile}"
-			live_file="${rpath}/${rfile:10}"
+			live_file="${cfg_file%.rpmnew}"
+			[[ "${live_file}" !=  "${cfg_file}" ]] || live_file="${rpath}/${rfile:10}"
 
 			local mpath
 			for mpath in ${CONFIG_PROTECT_MASK}; do
@@ -620,17 +622,25 @@ while [[ -n $1 ]] ; do
 done
 ${SET_X} && set -x
 
-type portageq >/dev/null || die "missing portageq"
-portage_vars=(
-	CONFIG_PROTECT{,_MASK}
-	PORTAGE_CONFIGROOT
-	PORTAGE_INST_{G,U}ID
-	PORTAGE_TMPDIR
-	EROOT
-	USERLAND
-	NOCOLOR
-)
-eval $(portageq envvar -v ${portage_vars[@]})
+if type portageq 2>/dev/null; then
+	portage_vars=(
+		CONFIG_PROTECT{,_MASK}
+		PORTAGE_CONFIGROOT
+		PORTAGE_INST_{G,U}ID
+		PORTAGE_TMPDIR
+		EROOT
+		USERLAND
+		NOCOLOR
+	)
+	eval $(portageq envvar -v ${portage_vars[@]})
+else
+	[[ ! -f /etc/gentoo-release ]] || die "missing portageq"
+	PORTAGE_CONFIGROOT='/'
+	PORTAGE_TMPDIR='/tmp'
+	CONFIG_PROTECT='/etc'
+	CONFIG_PROTECT_MASK=''
+	[[ ! -f /etc/sysconfig/etc-update ]] || . /etc/sysconfig/etc-update
+fi
 export PORTAGE_TMPDIR
 SCAN_PATHS=${*:-${CONFIG_PROTECT}}
 
openSUSE Build Service is sponsored by