Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
md5-update proof of concept
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Unsupported Software
View previous topic :: View next topic  
Author Message
Gherald
Veteran
Veteran


Joined: 23 Aug 2004
Posts: 1399
Location: CLUAConsole

PostPosted: Mon Apr 04, 2005 7:32 am    Post subject: md5-update proof of concept Reply with quote

It has always irked me how portage and etc-update do not have a good mechanism for dealing with config files that have not been changed since they were last installed.

For instance, if I'm upgrading X.org from version-A to version-B, what do I care if some obscure file in /etc/X11 is different between them? As long as the file version-A installed was never altered, I couldn't care less whether version-B replaces it with something newer.

md5-update is my solution to this annoyance.

Be sure to place it in your $PATH somewhere -- like /usr/local/bin -- because it will viraly propagate a call to itself from etc-update.

Code:
#!/bin/bash
source /sbin/functions.sh

if [[ $1 == -h || $1 == -help || $1 == --help ]]; then echo -e \
'md5-update 0.0.1, proof of concept by Freeix Gherald

This script sets your system up to maintain hardlinks of /var/db/pkg
entries, which do not go away after a package is updated.

This allows md5 checks of old config files and eliminates
part of the drudge work of running etc-update.'
   exit 0
fi

WRAPPER="/usr/local/bin/emerge"
if [ ! -x ${WRAPPER} ]; then
   ewarn "Creating emerge wrapper ${WRAPPER}"
   echo '#!/bin/bash
/usr/bin/emerge ${@}
EXIT_CODE=$?
source /sbin/functions.sh
PKG_DIR=`/usr/lib/portage/bin/portageq vdb_path`
PKG_HIST_DIR="${PKG_DIR}hist"
if [ ! -d ${PKG_HIST_DIR} ]; then
   ewarn "Creating package history repository ${PKG_HIST_DIR}..."
   mkdir ${PKG_HIST_DIR}
fi
cp -Rlf ${PKG_DIR}/* ${PKG_HIST_DIR}
exit $EXIT_CODE' >| ${WRAPPER}
   chmod 755 ${WRAPPER}
fi

if [ ! -d ${PKG_HIST_DIR} ]; then
   ${WRAPPER} >/dev/null
   ewarn "Run md5-update after you've updated some packages!"
   exit 1
fi

ETC_PATH=`which etc-update`
if grep '^scan$' ${ETC_PATH} >/dev/null; then
   ewarn "Patching etc-update..."
   perl -pi -e 's/^scan$/scan\; md5-update/' ${ETC_PATH}
fi

ETC_PID=`pgrep etc-upd`
if [ -z ${ETC_PID} ]; then
   etc-update; exit
fi

PKG_DIR=`/usr/lib/portage/bin/portageq vdb_path`
PKG_HIST_DIR="${PKG_DIR}hist"
MD5_TMP="/dev/shm/$$-md5-update"
ETC_FILES="/tmp/${ETC_PID}/files"

# Make sure etc-update actually found some files to update
[[ $(ls -A ${ETC_FILES} | while read line; do echo $line; done | wc -l) == 0 ]] && exit 0

# Phew, setup is done.  Now the actual fun begins.
for etc in ${ETC_FILES}/*; do
   # Use a temp file and fd 3 instead of just piping the grep directly
   # to "while read line", so as to not interfere with "mv -i ..." later.
   grep -R " $(head -n1 ${etc}) " ${PKG_HIST_DIR}/*/*/CONTENTS >| ${MD5_TMP}
   exec 3<${MD5_TMP}; while read -u 3 line; do
#      echo $line
      prev_md5=`echo ${line} | awk '{print $3}'`
      fname=`echo ${line} | awk '{print $2}'`
      cur_md5=`md5sum "${fname}" | awk '{print $1}'`
      pkg_name=`echo $line | awk '{print $1}'`
      pkg_name=${pkg_name#/*/*/*/}
      pkg_name=${pkg_name%/*}

      if [[ ${cur_md5} == ${prev_md5} ]]; then
         [ ! -e ${etc} ] && continue
         einfo "$fname ;-) $pkg_name"
         for rfile in $(tail -n +2 "${etc}"); do
            echo -n "${rfile} -> ${fname} [y|N] "
            /bin/mv -i ${rfile} ${fname} 2> /dev/null
            [ -e ${rfile} ] || /bin/rm -f ${etc}
         done #looping over ._cfg????_* files
      else
#         If you want to see failed md5 checks, uncomment the next line.
#         eerror "$fname :-( $pkg_name"
         true
      fi
   done
done
/bin/rm -f ${MD5_TMP}


If you have any ideas for getting around using /usr/local/bin to wrap emerge, let me know.

Also using /dev/shm/$$-md5-update as temp storage for information being piped between grep and "while read line" so as to not interfere with the nested "mv -i" feels kind of hackish... but it works.
Back to top
View user's profile Send private message
moocha
Watchman
Watchman


Joined: 21 Oct 2003
Posts: 5722

PostPosted: Mon Apr 04, 2005 8:03 am    Post subject: Re: md5-update proof of concept Reply with quote

freeix wrote:
It has always irked me how portage and etc-update do not have a good mechanism for dealing with config files that have not been changed since they were last installed.
Which is why most of the Gentoo'ers (including yours truly) no longer use etc-update but have switched to dispatch-conf, which does.
_________________
Military Commissions Act of 2006: http://tinyurl.com/jrcto

"Those who would give up essential liberty to purchase a little temporary safety deserve neither liberty nor safety."
-- attributed to Benjamin Franklin
Back to top
View user's profile Send private message
Gherald
Veteran
Veteran


Joined: 23 Aug 2004
Posts: 1399
Location: CLUAConsole

PostPosted: Mon Apr 04, 2005 8:05 am    Post subject: Reply with quote

Maybe if it supported vimdiff. There's a patch at bug #73129, but it didn't work for me.

All in all I wasn't thrilled with any of dispatch-conf's other "features", either, so I'm sticking with etc-update seeing as this md5-update script fixes the only beef I ever had with it.

It's nice to see that dispatch-conf is included in the default portage install now... one less thing to worry about, asuming it ever starts meeting my needs.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Unsupported Software All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum