Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 70668 | Differences between
and this patch

Collapse All | Expand All

(-)etc-update (-53 / +115 lines)
Lines 26-34 Link Here
26
		sed -ne "s/^ *$item *= *\([\"']\{0,1\}\)\(.*\)\1/\2/p" |sed -e '$p;d'
26
		sed -ne "s/^ *$item *= *\([\"']\{0,1\}\)\(.*\)\1/\2/p" |sed -e '$p;d'
27
}
27
}
28
28
29
function scan() {
29
function option() {
30
	echo -ne "${OPTION}${*}${NORMAL}"
31
}
32
33
function cfgfile() {
34
	echo -ne "${CFGFILE}${*}${NORMAL}"
35
}
36
37
function updatefile() {
38
	echo -ne "${UPDATEFILE}${*}${NORMAL}"
39
}
40
41
function menu_title() {
42
	echo
43
	echo -e "${MENU}>> ${*}:${NORMAL}"
44
}
45
46
function beautify_diff() {
47
	awk 'BEGIN { u_fmt = 1 }
48
		 /^[<>]/ { u_fmt = 0 }
49
		 /^[^-+<>]/ || ( !u_fmt && /^-/ ) { print $0 }
50
		 /^</ || ( u_fmt && /^-/ ) { print "'${CFGFILE}'" $0 "'${NORMAL}'" }
51
		 /^[+>]/ { print "'${UPDATEFILE}'" $0 "'${NORMAL}'" }'
52
}
30
53
31
	echo "Scanning Configuration files..."
54
function scan() {
55
	einfo "Scanning configuration files..."
32
	rm -rf ${TMP}/files > /dev/null 2>&1
56
	rm -rf ${TMP}/files > /dev/null 2>&1
33
	mkdir ${TMP}/files || die "Failed mkdir command!" 1
57
	mkdir ${TMP}/files || die "Failed mkdir command!" 1
34
	count=0
58
	count=0
Lines 65-71 Link Here
65
					MATCHES=1
89
					MATCHES=1
66
				fi
90
				fi
67
				if [[ "${MATCHES}" == "1" ]]; then
91
				if [[ "${MATCHES}" == "1" ]]; then
68
					echo "Automerging trivial changes in: ${rfile:10}"
92
					einfo "Auto-applying trivial update to $(cfgfile ${rpath}/${rfile:10})"
69
					mv ${rpath}/${rfile} ${rpath}/${rfile:10}
93
					mv ${rpath}/${rfile} ${rpath}/${rfile:10}
70
					continue
94
					continue
71
				else
95
				else
Lines 90-95 Link Here
90
		done
114
		done
91
	fi; done
115
	fi; done
92
116
117
	echo
93
}
118
}
94
119
95
function sel_file() {
120
function sel_file() {
Lines 99-110 Link Here
99
			if (( ${isfirst} == 0 )); then
124
			if (( ${isfirst} == 0 )); then
100
				isfirst=${file}
125
				isfirst=${file}
101
			fi
126
			fi
102
			echo -n "${file}${PAR} "
103
			if (( ${mode} == 0 )); then
127
			if (( ${mode} == 0 )); then
104
				for word in `cat ${TMP}/files/${file}`; do
128
				echo "$(option ${file})${PAR} $(cfgfile $(head -n1 "${TMP}/files/${file}"))"
105
					echo ${word}
129
				if [ "${show_update_files}" == "yes" ]; then
106
				done
130
					for update in $(tail -n+2 ${TMP}/files/${file}); do
131
						echo ${update}
132
					done
133
					echo
134
				fi
107
			else
135
			else
136
				echo -n "${file}${PAR} "
108
				head -n1 ${TMP}/files/${file}
137
				head -n1 ${TMP}/files/${file}
109
			fi
138
			fi
110
		done > ${TMP}/menuitems
139
		done > ${TMP}/menuitems
Lines 113-130 Link Here
113
			input=0
142
			input=0
114
		else
143
		else
115
			if (( ${mode} == 0 )); then
144
			if (( ${mode} == 0 )); then
116
				echo "The following is the list of files which need updating, each 
145
				menu_title "Select a configuration file to update"
117
configuration file is followed by a list of possible replacement files."
146
				echo
118
			else
147
			else
119
				local my_title="Please select a file to update"
148
				local my_title="Please select a file to update"
120
			fi
149
			fi
121
150
122
			if (( ${mode} == 0 )); then
151
			if (( ${mode} == 0 )); then
123
				cat ${TMP}/menuitems
152
				cat ${TMP}/menuitems
124
				echo    "Please select a file to edit by entering the corresponding number."
153
				echo
125
				echo    "              (don't use -3 or -5 if you're unsure what to do)"
154
				echo "($(option -1) to exit)"
126
				echo    "              (-1 to exit) (-3 to auto merge all remaining files)"
155
				echo "($(option -3) to replace all remaining files with their updates)"
127
				echo -n "                           (-5 to auto-merge AND not use 'mv -i'): "
156
				echo "($(option -5) to replace all without further confirmation)"
157
				echo -n "Enter the number for a given file/action (use -3 and -5 with CAUTION): "
128
				read input
158
				read input
129
			else
159
			else
130
				dialog --title "${title}" --menu "${my_title}" \
160
				dialog --title "${title}" --menu "${my_title}" \
Lines 137-142 Link Here
137
				export mv_opts=""
167
				export mv_opts=""
138
			fi
168
			fi
139
			if (( ${input} == -3 )); then
169
			if (( ${input} == -3 )); then
170
				echo
140
				input=0
171
				input=0
141
				export OVERWRITE_ALL="yes"
172
				export OVERWRITE_ALL="yes"
142
			fi
173
			fi
Lines 148-154 Link Here
148
}
179
}
149
180
150
function do_file() {
181
function do_file() {
151
	echo
182
	if [ "${OVERWRITE_ALL}" != "yes" ]; then
183
		echo
184
		menu_title "Updating $(head -n1 ${TMP}/files/${input})"
185
	fi
152
	local -i my_input
186
	local -i my_input
153
	local -i fcount=0
187
	local -i fcount=0
154
	until (( `cat ${TMP}/files/${input}|wc -l` < 2 )); do
188
	until (( `cat ${TMP}/files/${input}|wc -l` < 2 )); do
Lines 164-176 Link Here
164
			else
198
			else
165
				for line in `cat ${TMP}/files/${input}`; do
199
				for line in `cat ${TMP}/files/${input}`; do
166
					if (( ${fcount} > 0 )); then
200
					if (( ${fcount} > 0 )); then
167
						echo -n "${fcount}${PAR} "
201
						echo "$(option ${fcount})${PAR} $(updatefile "${line}") ($(find "${line}" -printf "%t"))"
168
						echo "${line}"
169
					else
202
					else
170
						if (( ${mode} == 0 )); then
203
						if (( ${mode} == 0 )); then
171
							echo "Below are the new config files for ${line}:"
204
							echo
205
							echo "Multiple updates exist for ${line}:"
172
						else
206
						else
173
							local my_title="Please select a file to process for ${line}"
207
							local my_title="Please select an update to process for ${line}"
174
						fi
208
						fi
175
					fi
209
					fi
176
					fcount=${fcount}+1
210
					fcount=${fcount}+1
Lines 178-184 Link Here
178
212
179
				if (( ${mode} == 0 )); then
213
				if (( ${mode} == 0 )); then
180
					cat ${TMP}/menuitems
214
					cat ${TMP}/menuitems
181
					echo -n "Please select a file to process (-1 to exit this file): "
215
					echo -n "Please select an update to process ($(option -1) to return to the previous menu): "
182
					read my_input
216
					read my_input
183
				else
217
				else
184
					dialog --title "${title}" --menu "${my_title}" \
218
					dialog --title "${title}" --menu "${my_title}" \
Lines 215-221 Link Here
215
			break
249
			break
216
		fi
250
		fi
217
	done
251
	done
218
	echo
252
	[ "${OVERWRITE_ALL}" != "yes" ] && echo
219
	rm ${TMP}/files/${input}
253
	rm ${TMP}/files/${input}
220
	count=${count}-1
254
	count=${count}-1
221
}
255
}
Lines 230-274 Link Here
230
		if [ "${OVERWRITE_ALL}" == "yes" ]; then
264
		if [ "${OVERWRITE_ALL}" == "yes" ]; then
231
			my_input=1
265
			my_input=1
232
		else
266
		else
267
			echo
233
		  showdiffcmd=$(echo "${diff_command}" |
268
		  showdiffcmd=$(echo "${diff_command}" |
234
				sed -e "s:%file1:${ofile}:" -e "s:%file2:${file}:")
269
				sed -e "s:%file1:${ofile}:" -e "s:%file2:${file}:")
235
				
270
				
236
			if [ "${using_editor}" == 0 ]; then
271
			if [ "${using_editor}" == 0 ]; then
237
				(
272
				(
238
					echo "Showing differences between ${ofile} and ${file}"
273
					echo "Differences between original and update:"
239
					${showdiffcmd}
274
					${showdiffcmd} | beautify_diff
240
				) | ${pager}
275
				) | ${pager}
241
			else
276
			else
242
				echo "Beginning of differences between ${ofile} and ${file}"
277
				echo "Beginning of differences between $(cfgfile ${ofile}) and $(updatefile ${file})"
243
				${showdiffcmd}
278
				${showdiffcmd}
244
				echo "End of differences between ${ofile} and ${file}"
279
				echo "End of differences between $(cfgfile ${ofile}) and $(updatefile ${file})"
245
			fi
280
			fi
246
			if [ -L "${file}" ]; then
281
			if [ -L "${file}" ]; then
247
				echo
282
				echo
248
				echo "-------------------------------------------------------------"
283
				ewarn "-------------------------------------------------------------"
249
				echo "NOTE: File is a symlink to another file. REPLACE recommended."
284
				ewarn "NOTE: File is a symlink to another file. REPLACE recommended."
250
				echo "      The original file may simply have moved. Please review."
285
				ewarn "	  The original file may simply have moved. Please review."
251
				echo "-------------------------------------------------------------"
286
				ewarn "-------------------------------------------------------------"
252
				echo
287
				echo
253
			fi
288
			fi
254
			echo -n "1) Replace original with update
289
			echo -ne "$(option 1)${PAR} Replace $(cfgfile ${ofile}) with update
255
2) Delete update, keeping original as is
290
$(option 2)${PAR} Delete update, keeping original as is
256
3) Interactively merge original with update
291
$(option 3)${PAR} Interactively merge original with update
257
4) Show differences again
292
$(option 4)${PAR} Show differences again
258
Please select from the menu above (-1 to ignore this update): "
293
Please select from the menu above ($(option -1) to ignore this update): "
259
			read my_input
294
			read my_input
260
		fi
295
		fi
261
		
296
262
		case ${my_input} in
297
		case ${my_input} in
263
			1) echo "Replacing ${ofile} with ${file}"
298
			1) [ "${OVERWRITE_ALL}" != "yes" ] && echo
299
			   einfo "Replacing $(cfgfile ${ofile}) with $(updatefile ${file})"
264
			   mv ${mv_opts} ${file} ${ofile}
300
			   mv ${mv_opts} ${file} ${ofile}
265
			   continue
301
			   continue
266
			   ;;
302
			   ;;
267
			2) echo "Deleting ${file}"
303
			2) [ "${OVERWRITE_ALL}" != "yes" ] && echo
304
			   einfo "Deleting $(updatefile ${file})"
268
			   rm ${rm_opts} ${file}
305
			   rm ${rm_opts} ${file}
269
			   continue
306
			   continue
270
			   ;;
307
			   ;;
271
			3) do_merge "${file}" "${ofile}"
308
			3) echo
309
			   do_merge "${file}" "${ofile}"
272
			   my_input=${?}
310
			   my_input=${?}
273
#			   [ ${my_input} == 255 ] && my_input=-1
311
#			   [ ${my_input} == 255 ] && my_input=-1
274
			   continue
312
			   continue
Lines 287-324 Link Here
287
	local ofile="${2}"
325
	local ofile="${2}"
288
	local mfile="${2}.merged"
326
	local mfile="${2}.merged"
289
	local -i my_input=0
327
	local -i my_input=0
290
	echo "${file} ${ofile} ${mfile}"
291
328
292
	if [ -e ${mfile} ] ; then
329
	if [ -e ${mfile} ] ; then
293
		echo "A previous version of the merged file exists, cleaning..."
330
		einfo "A previous version of the merged file exists, cleaning..."
294
		rm ${rm_opts} ${mfile}
331
		rm ${rm_opts} "${mfile}"
295
	fi
332
	fi
296
333
297
	until (( ${my_input} == -1 )); do
334
	until (( ${my_input} == -1 )); do
298
		echo "Merging ${file} and ${ofile}"
335
		menu_title "Merging ${ofile} with update"
336
		echo
299
		`echo "${merge_command}" |
337
		`echo "${merge_command}" |
300
		 sed -e "s:%merged:${mfile}:g" \
338
		 sed -e "s:%merged:${mfile}:g" \
301
		 	 -e "s:%orig:${ofile}:g" \
339
		 	 -e "s:%orig:${ofile}:g" \
302
			 -e "s:%new:${file}:g"`
340
			 -e "s:%new:${file}:g"`
303
		until (( ${my_input} == -1 )); do	
341
		until (( ${my_input} == -1 )); do	
304
			echo -n "1) Replace ${ofile} with merged file
342
			echo -n "$(option 1)${PAR} Replace $(cfgfile ${ofile}) with merged file
305
2) Show differences between merged file and original
343
$(option 2)${PAR} Show differences between merged file and original
306
3) Remerge original with update
344
$(option 3)${PAR} Remerge original with update
307
4) Edit merged file
345
$(option 4)${PAR} Edit merged file
308
5) Return to the previous menu
346
$(option 5)${PAR} Return to the previous menu
309
Please select from the menu above (-1 to exit, losing this merge): "
347
Please select from the menu above ($(option -1) to exit, losing this merge): "
310
			read my_input
348
			read my_input
311
			case ${my_input} in
349
			case ${my_input} in
312
				1) echo "Replacing ${ofile} with ${mfile}"
350
				1) echo
351
				   einfo "Replacing $(cfgfile ${ofile}) with $(updatefile ${mfile})"
313
				   chmod --reference=${ofile} ${mfile}
352
				   chmod --reference=${ofile} ${mfile}
314
				   mv ${mv_opts} ${mfile} ${ofile}
353
				   mv ${mv_opts} ${mfile} ${ofile}
315
				   rm ${rm_opts} ${file}
354
				   rm ${rm_opts} ${file}
316
				   return 255
355
				   return 255
317
				   ;;
356
				   ;;
318
				2) ( echo "Showing differences between ${ofile} and ${mfile}"
357
				2) echo
358
				   ( echo "Differences between original and merged file:"
319
					 `echo "${diff_command}" | \
359
					 `echo "${diff_command}" | \
320
					  sed -e "s:%file1:${ofile}:" \
360
					  sed -e "s:%file1:${ofile}:" \
321
					  	  -e "s:%file2:${mfile}:"` ) | ${pager}
361
						  -e "s:%file2:${mfile}:"` ) | beautify_diff | ${pager}
322
				   continue
362
				   continue
323
				   ;;
363
				   ;;
324
				3) break
364
				3) break
Lines 341-346 Link Here
341
function die() {
381
function die() {
342
	trap "" term
382
	trap "" term
343
	trap "" kill
383
	trap "" kill
384
	echo
344
	echo "Exiting: ${1}"
385
	echo "Exiting: ${1}"
345
	rm -rf ${TMP}
386
	rm -rf ${TMP}
346
	exit ${2}
387
	exit ${2}
Lines 358-365 Link Here
358
mkdir ${TMP} || die "failed mkdir command!" 1
399
mkdir ${TMP} || die "failed mkdir command!" 1
359
400
360
# I need the CONFIG_PROTECT value
401
# I need the CONFIG_PROTECT value
361
CONFIG_PROTECT=$(/usr/lib/portage/bin/portageq config_protect)
402
if [[ $# == 0 ]]; then
362
CONFIG_PROTECT_MASK=$(/usr/lib/portage/bin/portageq config_protect_mask)
403
	CONFIG_PROTECT=$(/usr/lib/portage/bin/portageq config_protect)
404
	CONFIG_PROTECT_MASK=$(/usr/lib/portage/bin/portageq config_protect_mask)
405
else
406
	# For testing purposes
407
	CONFIG_PROTECT="$*"
408
	CONFIG_PROTECT_MASK=
409
fi
363
410
364
# load etc-config's configuration
411
# load etc-config's configuration
365
EU_AUTOMERGE=`get_config eu_automerge`
412
EU_AUTOMERGE=`get_config eu_automerge`
Lines 370-375 Link Here
370
diff_command=`get_config diff_command`
417
diff_command=`get_config diff_command`
371
using_editor=`get_config using_editor`
418
using_editor=`get_config using_editor`
372
merge_command=`get_config merge_command`
419
merge_command=`get_config merge_command`
420
show_update_files=`get_config show_update_files`
373
declare -i mode=`get_config mode`
421
declare -i mode=`get_config mode`
374
[ -z ${mode} ] && mode=0
422
[ -z ${mode} ] && mode=0
375
[ -z "${pager}" ] && pager="cat"
423
[ -z "${pager}" ] && pager="cat"
Lines 377-382 Link Here
377
#echo "rm_opts: $rm_opts, mv_opts: $mv_opts, cp_opts: $cp_opts"
425
#echo "rm_opts: $rm_opts, mv_opts: $mv_opts, cp_opts: $cp_opts"
378
#echo "pager: $pager, diff_command: $diff_command, merge_command: $merge_command" 
426
#echo "pager: $pager, diff_command: $diff_command, merge_command: $merge_command" 
379
427
428
# set up colours (and ensure that the function ewarn() and einfo() can be used)
429
source /etc/init.d/functions.sh
430
if [ "${RC_NOCOLOR}" = "yes" ]
431
then
432
	OPTION=
433
	CFGFILE=
434
	MENU=
435
else
436
	OPTION=$'\e[37;01m'
437
	CFGFILE=$'\e[32m'
438
	UPDATEFILE=$'\e[33m'
439
	MENU=$'\e[37;01m'
440
fi
441
380
if (( ${mode} == 0 )); then
442
if (( ${mode} == 0 )); then
381
	PAR=")"
443
	PAR=")"
382
else
444
else
Lines 395-401 Link Here
395
457
396
until (( ${input} == -1 )); do
458
until (( ${input} == -1 )); do
397
	if (( ${count} == 0 )); then
459
	if (( ${count} == 0 )); then
398
		die "Nothing left to do; exiting. :)" 0
460
		die "Nothing left to do. :)" 0
399
	fi
461
	fi
400
	sel_file
462
	sel_file
401
	if (( ${input} != -1 )); then
463
	if (( ${input} != -1 )); then

Return to bug 70668