You can run this before running etc-update to save yourself some work.
NB.
1. This needs gentoolkit to work
2. You need to do this before the old package that installed the config file is cleaned (either through an emerge clean or autoclean)
3. Please make sure that copy/cut-and-paste to the script text file does not remove spaces or modify line-ends.
Code: Select all
#!/bin/bash
# This script checks config files in directories with config files and
# checks whether their checksum matches known checksums in /var/db.
# If a checksum matches, the file has not been modified since the emerge
# and can be overwritten safely. These files are presented and queried
# for update individually or in one shot
#
# You can run this prior to running etc-update to save some work in updating
# files that you have not touched
strip_config()
{
echo ${1//._cfg????_/}
}
# check for root
if [ $UID != 0 ]; then
echo "Got root?"
exit 1
fi
# check for gentoolkit
needed=gentoolkit
if [ ! -f /usr/bin/qpkg ]; then
echo "You need to emerge $needed to run this"
exit 2
fi
# get dir list from config
sourcefiles="/etc/make.globals /etc/profile"
for sourcefile in $sourcefiles; do
source $sourcefile
for dir in $CONFIG_PROTECT; do
[ -d $dir ] && dirs="$dirs $dir"
done
done
# check for config files with matching checksums
for nf in `find $dirs -iname '._cfg*'`; do
of=`strip_config $nf`
for eb in `qpkg -v -nc -f $of`; do
if grep $of /var/db/pkg/$eb/CONTENTS |
grep -v ^sym |
sed 's/obj \([^ ]*\) \([^ ]*\) .*$/\2 \1/g' |
md5sum -c --status; then
can_update="$can_update $nf"
fi
done
done
# exit if nothing to do
[ -z "$can_update" ] && echo "No files found" && exit 0
# make sure files are listed only once in the update
can_update=`echo $can_update | sed 's/ /\n/g' | sort -u`
# blurb
can_update="`echo $can_update | sort -u`"
echo "The following files have not been modified by you:"
echo
echo `strip_config "$can_update"` | tr ' ' '\n'
echo
echo "You can update the files one by one by typing \"y/n\" or update"
echo "all the remaining by typing \"a\""
# update one by one or all
for nf in $can_update; do
of=`strip_config $nf`
[ -z "$all" ] && echo -n "Update ${of}? [Y|n|q|a] " && read ans
case $ans in
n|N)
;;
q|Q)break
;;
a|A)echo Moving $nf to $of
mv -f $nf $of
all=y
ans=y
;;
y|Y|*)echo Moving $nf to $of
mv -f $nf $of
;;
esac
done
exit 0
EDIT(Naan Yaar):03/12/04: Updated to include Yak's suggestion and previous fix for missing pkglist.





