Группа :: Система/Основа
Пакет: etc-update
Главная Изменения Спек Патчи Загрузить Bugs and FR
Патч: etc-update-user.patch
--- etc-update-20020731/etc-update.bak 2002-07-31 20:43:21 +0800
+++ etc-update-20020731/etc-update 2006-07-01 16:58:53 +0800
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
# Copyright 2002 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License, v2 or later
# Authors: (C) Jochem Kossen 2002, (C) Leo Lipelis 2002
@@ -10,14 +10,17 @@
# file anymore. It also means settings will be saved during upgrading.
#
configfile="/etc/etc-updaterc"
-configdirs="/etc /usr/share/config"
-
+configdirs="/etc"
+runtimedir="$TMPDIR"
+myname="${0##*/}"
#
# Source the configurationfile
#
if [ -e $configfile ]; then
source $configfile
fi
+test -z "$runtimedir" && runtimedir="/tmp"
+configdirs="$configdirs $*"
#
# Make sure required variables are defined
@@ -32,16 +35,16 @@
#
# Find all "rpmnew" configuration files.
#
-cfg_files=`find $configdirs -iname '*.rpmnew'`
+#cfg_files=`find $configdirs -iname '*.rpmnew'`
#
# Ask which one of the given two files to install
#
rm_extra_file() {
- old=$1
- new=$2
+ old="$1"
+ new="$2"
- show_diff $old $new
+ show_diff "$old" "$new"
menu1
# read and echo 1 char from stdin
@@ -50,22 +53,26 @@
case $input in
1)
echo "*** upgrading to $new ..."
- mv $mv_opts $new $old
+ mv "$mv_opts" "$new" "$old"
;;
2)
echo "*** keeping $old ..."
- rm $rm_opts $new
+ rm "$rm_opts" "$new"
;;
3)
- merge_files $old $new
- install_merged_file $old $new
+ merge_files "$old" "$new"
+ install_merged_file "$old" "$new"
;;
4)
- rm_extra_file $old $new
+ rm_extra_file "$old" "$new"
;;
5)
echo "*** skipping ..."
;;
+ 6)
+ echo "*** bye ..."
+ exit 1
+ ;;
*)
echo "!!! Please pick a valid choice next time !!!"
menu1
@@ -83,10 +90,11 @@
echo "2) Keep existing $old"
echo "3) Merge the two files"
echo "4) Show the difference between the two files again"
-echo " OR"
echo "5) Skip (keep all files)"
+echo " OR"
+echo "6) Quit etc-update"
echo
-echo -n "Type (1, 2, 3, 4 or 5): "
+echo -n "Type (1, 2, 3, 4, 5 or 6): "
}
#
@@ -110,9 +118,9 @@
# Install merged file
#
install_merged_file() {
- old=$1
- merged=$1.merged
- new=$2
+ old="$1"
+ merged="$1.merged"
+ new="$2"
menu2
# read and echo 1 char from stdin
@@ -121,21 +129,21 @@
case $input in
1)
echo "*** upgrading to $merged ..."
- chmod --reference=$old $merged
- mv $mv_opts $merged $old
- rm $rm_opts $new
+ chmod --reference="$old" "$merged"
+ mv "$mv_opts" "$merged" "$old"
+ rm "$rm_opts" "$new"
;;
2)
- show_diff $old $merged
- install_merged_file $old $new
+ show_diff "$old" "$merged"
+ install_merged_file "$old" "$new"
;;
3)
- merge_files $old $new
- install_merged_file $old $new
+ merge_files "$old" "$new"
+ install_merged_file "$old" "$new"
;;
4)
echo "*** keeping original file ..."
- rm $rm_opts $merged $new
+ rm "$rm_opts" "$merged" "$new"
;;
5)
echo "*** skipping ..."
@@ -143,11 +151,11 @@
6)
echo "*** going back to previous menu ..."
echo
- if [ -e $merged ]; then
+ if [ -e "$merged" ]; then
echo "*** an (old?) merged file exists. It will be removed ..."
- rm $rm_opts $merged
+ rm "$rm_opts" "$merged"
fi
- rm_extra_file $old $new
+ rm_extra_file "$old" "$new"
;;
*)
echo "!!! Please pick a valid choice next time !!!"
@@ -163,14 +171,14 @@
echo
if [ "`echo $pager`" ]; then
(echo "*** showing difference between $1 and $2" && echo && \
- `echo $diff_command | sed \
- -e s@%file1@$1@g \
- -e s@%file2@$2@g` ) | $pager
+ eval `echo $diff_command | sed \
+ -e "s@%file1@\"$1\"@g" \
+ -e "s@%file2@\"$2\"@g"` ) | $pager
else
echo "*** showing difference between $1 and $2" && echo
- `echo $diff_command | sed \
- -e s@%file1@$1@g \
- -e s@%file2@$2@g`
+ eval `echo $diff_command | sed \
+ -e "s@%file1@\"$1\"@g" \
+ -e "s@%file2@\"$2\"@g"`
fi
}
@@ -178,9 +186,9 @@
# Merge two files
#
merge_files() {
- old=$1
- merged=$1.merged
- new=$2
+ old="$1"
+ merged="$1.merged"
+ new="$2"
echo
echo "*** merging $old with $new ..."
@@ -189,30 +197,44 @@
echo
echo "*** an (old?) merged file already exists. It will be removed ..."
echo
- rm $rm_opts $merged
+ rm "$rm_opts" "$merged"
fi
# echo the help message for the merge command if it's defined
if [ "`echo $merge_helpmessage`" ]; then
echo
- echo $merge_helpmessage
+ echo "$merge_helpmessage"
fi
# execute the merge command
echo
- `echo $merge_command |sed \
- -e s@%merged@$merged@g \
- -e s@%orig@$old@g \
- -e s@%new@$new@g`
+ eval `echo $merge_command |sed \
+ -e "s@%merged@\"$merged\"@g" \
+ -e "s@%orig@\"$old\"@g" \
+ -e "s@%new@\"$new\"@g"`
}
#
# Run the script
#
-for new_full_path in $cfg_files; do
- file=${new_full_path##*/}
- old_full_path=${new_full_path%/*}/${file%.rpmnew}
-
- rm_extra_file ${old_full_path} ${new_full_path}
-done
+find $configdirs -iname '*.rpmnew' -o -iname '*.rpmsave' > $runtimedir/$myname.$$ 2>/dev/null
+trap "rm -f $runtimedir/$myname.$$" KILL INT QUIT EXIT
+while read -u 10 new_full_path; do
+ file="${new_full_path##*/}"
+ if [ "`echo "$new_full_path" | grep rpmnew 2>&1`" ]; then
+ old_full_path="${new_full_path%/*}/${file%.rpmnew}"
+ elif [ "`echo "$new_full_path" | grep rpmsave 2>&1`" ]; then
+ old_full_path="${new_full_path%/*}/${file%.rpmsave}"
+ fi
+ if [ -e "$old_full_path" -a -e "$new_full_path" ]; then
+ if cmp "$old_full_path" "$new_full_path"; then
+ touch -r "$new_full_path" "$old_full_path"
+ chmod --reference="$new_full_path" "$old_full_path"
+ mv -f "$new_full_path" "$old_full_path"
+ else
+ rm_extra_file "$old_full_path" "$new_full_path"
+ fi
+ fi
+done 10< $runtimedir/$myname.$$
+rm -f $runtimedir/$myname.$$
echo "*** script finished ..."