Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
i've written a script to handle /etc config merges
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Gentoo Chat
View previous topic :: View next topic  
Author Message
glenc
n00b
n00b


Joined: 24 Jun 2002
Posts: 13
Location: Syd, Oz

PostPosted: Sat Jun 29, 2002 12:17 pm    Post subject: i've written a script to handle /etc config merges Reply with quote

Hi,

I've been using Gentoo for about a week and I got sick of manually merging configs in the /etc tree after every `emerge -u`, so I wrote a script that does some of the legwork for you.

Called with no args, it prints a list of all the configs that need merging.

Called with a ._cfgXXXX_cfgfile file as an arg, it prints the `diff`s between that file and the one it intends to replace, prints the two files side-by-side using `pr` for comparison, and then asks the user whether to rm the ._cfgXXXX file, mv the ._cfgXXXX file over the existing one, or do nothing.

It makes those config updates much less of a pain in the arse. The code is posted below if anyone is interested, apologies for it's general arsy-ness, it's very much a quick hack job, but it works :) If the Gentoo maintainers think it's worthwhile and want to merge it into Gentoo, I'll write code that allows the merging of the lines which `diff`er from one file to the other.

Code:

#!/bin/bash

# source the gentoo colours
. /etc/init.d/functions.sh

case $# in

    0)
        echo "${WARN}Configs in need of update:${NORMAL}"
        find /etc -name '._cfg*'
        exit
        ;;

    1)
        NEWCFG=$1
        ;;

    *)
        echo "${BAD}Usage: ${NORMAL}$0 [new-config-file]"
        exit
        ;;
esac

WIDTH=$[`tput cols`/2*2] # force output width to be even
HALFWIDTH=$[$WIDTH/2-1]
[ ! -f $NEWCFG ] && { echo "${BAD}$NEWCFG: file not found${NORMAL}"; exit; }
OLDCFG=`echo $NEWCFG | perl -ne "s/\._cfg\d{4}_//; print;"`

horzline() {
    for i in `seq $HALFWIDTH`; do echo -n -; done
    echo -n +
    for i in `seq $HALFWIDTH`; do echo -n -; done
    echo
}

if cmp -s $OLDCFG $NEWCFG;then
    echo ${GOOD} $OLDCFG is identical to $NEWCFG
else
    echo "${WARN}*** ${GOOD}diff output ${WARN}***${NORMAL}"
    diff $OLDCFG $NEWCFG
    echo
    echo "${WARN}*** ${GOOD}actual file contents ${WARN}***${NORMAL}"
    horzline
    printf "%-${HALFWIDTH}s|%-${HALFWIDTH}s\n" $OLDCFG $NEWCFG
    horzline
    pr -w$WIDTH -m -t -s'|' $OLDCFG $NEWCFG
    horzline
fi

echo -n "[c]lobber old file, [i]gnore new file, or do [n]othing? "
read CHOICE

case $CHOICE in

    c) mv $NEWCFG $OLDCFG ;;
    i) rm $NEWCFG ;;
    n) ;;
    *) echo "Invalid choice: $CHOICE ... bailing out!"; exit 1; ;;

esac
[/code]
Back to top
View user's profile Send private message
d4h0od
Tux's lil' helper
Tux's lil' helper


Joined: 27 Jun 2002
Posts: 80
Location: Europe => Sweden => Blekinge => Karlskrona => h0odet

PostPosted: Sat Jun 29, 2002 1:10 pm    Post subject: tnx Reply with quote

just wanted to say thanx for the script... ive been using gentoo for a week too and i just sat and wondered if there was any program/script that could help one with updating config files
_________________
// d4h0od
Back to top
View user's profile Send private message
glenc
n00b
n00b


Joined: 24 Jun 2002
Posts: 13
Location: Syd, Oz

PostPosted: Sat Jun 29, 2002 1:21 pm    Post subject: Reply with quote

Thanks ... it's nice to know that my late night sleep deprivation code is making someone's life easier :)

On an aside, you'll notice the script has a completely unnecessary dependence on Perl, because I like Perl regex's and I hate the nuances of sed's regex handling :) Also, the script only works for the /etc tree at the moment, not the entire $CONFIG_MASK set, although that's about a 10 second fix when I can be bothered :)
Back to top
View user's profile Send private message
Damasz
Tux's lil' helper
Tux's lil' helper


Joined: 24 Apr 2002
Posts: 91
Location: Groningen, the Netherlands

PostPosted: Sat Jun 29, 2002 2:35 pm    Post subject: Reply with quote

Did you know about the etc-update script from the gentoolkit package?

Try it out!
Back to top
View user's profile Send private message
glenc
n00b
n00b


Joined: 24 Jun 2002
Posts: 13
Location: Syd, Oz

PostPosted: Sat Jun 29, 2002 2:52 pm    Post subject: Reply with quote

Ahh thanks ... haven't checked the source yet but it seems to be substantially more fully fledged than my script :)

Also, shouldn't gentoolkit stop providing /usr/sbin/epm, since the epm package itself provides /usr/bin/epm and this could lead to confusion ...
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Gentoo Chat 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