# Graphical etc-update

## BradB

OK, until recently I was very, very slack at keeping my /etc files up todate - mainly because I didn't know about 

```
etc-update
```

  I started using etc-update, but found the console diffs hard to follow.  A bit of scrounging around found the file 

```
/etc/etc-update.conf
```

  If you take a look at it you'll find there are some provisions for changing the commands for diff and merge, there are event lines you can uncomment to enable vim diffing.

I'm not all that great with vim, so I thought I'd try to use a graphical diff - namely gtkdiff.

You'll need to emerge it  :Smile: 

```

emerge gtkdiff

```

I think xxdiff would probably do, but I haven't had more than a cursory look - so I won't comment.

The first change is the line

```
pager="less"
```

 it needs to go to

```

#pager="less"

pager=""

```

Then you need to change the diff_command, mine looks like

```

diff_command="gtkdiff -g 1600x1000 %file1 %file2"

```

I like to use my whole resolution for width, so I specify the geometry with

```
 -g 1600x1000 
```

Change these values so gtkdiff looks nice on the screen.

For the merge command I have

```

merge_command="gtkdiff -g 1600x1000 -o %merged %orig %new"

```

The merge command displays 3 panes, with the merged pane displayed in the top half - the program is simple to control so I won't go over it.  The only gotcha is that after you are happy with the merge, you must save the merged file - simply right-click on the top pane and select output file.

This works fine for me - my only problem is that gtkdiff will display 3 panes after it has been used in merge mode, even when it is in diff mode.  If anybody knows how to force 2 panes only in diff mode (via commandline, not via the GUI) please let me know.

If I get motivated enough I may trawl through the code & add options to force 2 pane and auto-save.

Oh, if you're like me & su to root from a console, you will probably need to run 

```
 xhost +
```

 with your regular user.  There are security issues here I'd expect, but I don't know about them - help here would be good.

Any feedback would be great.

Cheers

BradLast edited by BradB on Tue Jan 07, 2003 7:52 pm; edited 1 time in total

----------

## DArtagnan

going to try it  :Smile: 

----------

## cvk

Looks good, thank you.

cvk

----------

## elzbal

 *BradB wrote:*   

> 
> 
> Oh, if you're like me & su to root from a console, you will probably need to run 
> 
> ```
> ...

 

One issue is that remote users can throw up their own windows on your box or (I think) randomly change your X settings. It would be better to use

```
xhost +machinename

i.e.

xhost +bigbox
```

 so that only people logged in to your box can connect to it.

Thanks for the tip! That's what makes this forum so great!

----------

## pjp

 *elzbal wrote:*   

> It would be better to use
> 
> ```
> xhost +machinename
> 
> ...

 

```
xhost +localhost
```

Also works.

----------

## steelrose

BradB:i like your idea a lot so i followed your instructions.when i run etc-update i get the output in no-gui.when i run gtkdiff i get nothing.how do i run this?

----------

## woodm

Hey, is there a good package to install/reinstall to test out the new merging?

I don't want anything big or important.

This is a GREAT idea.  And I'm really glad you published it.  I happen to be deeply in love with vim, so I will go that way, but that doesn't detract from my thank you in anyway.

----------

## BradB

SteelRose - how do you mean you geet no output in gtkdiff?  Does the app even start when you run it from the console?  You need to modify the file /etc/etc-update.conf to tell etc-update to use gtkdiff

Woodm - I don't know, I hadn't updated for ages and had about 30 files that needed doing  :Smile:   It's good motivation for finding a better way, thanks for the positive feedback.

Cheers

Brad

----------

## Houdini

 *elzbal wrote:*   

>  *BradB wrote:*   
> 
> Oh, if you're like me & su to root from a console, you will probably need to run 
> 
> ```
> ...

 

Actually, the worry is that remote users can read your keypresses, doing things like grabbing passwords.  A program to do such a thing is trivial to write.

```
xhost +localhost
```

Is the right thing to do. (As KanusPlusPlus said)

----------

## eyevee99

gtkdiff corrupted my make.conf.

it's gone.  How can I get the default one back?

Cheers

Ryan

----------

## zojas

a program called kompare was just pointed out to me. it lets you interactively (&graphically) merge the two files. now someone needs to figure out how to use it with etc-update. kompare is in kde-base/kdesdk

----------

## ksclarke

This is a GREAT idea... THANKS!  The terminal etc-update has been my least favorite thing about Gentoo so far (though I like the concept of protecting them it's been a bit of a pain for some).  Now I have nothing to complain about... just need to find something to test it out on.  Suggestions anyone for a package to test it on?

Thanks, Kevin

----------

## zojas

another way would be to use gvim for the diff_command in /etc/etc-update.conf:

```
diff_command="gvim -d %file1 %file2"
```

----------

## TGL

I would like to add a test to know if the commande has been launch from a linux console or from an X terminal, something like that:

```
if [ i dont know what ] then gvimdiff %file1 %file2 ; else vimdiff %file1 %file2 
```

But I'm really hopeless at bashing... Any idea ?

----------

## zojas

well, etc-update.conf isn't a bash script. it's just sourced by the etc-update bash script. so you would need to hack that. I think you can only set variables in /etc/etc-update.conf.

but you should be able to just use gvimdiff. if it can't open your X display, it will fall back to vimdiff. Isn't there a note in the etc-update.conf file that says not to use vimdiff?

if it were a script though, here's the syntax you're looking for:

```
if [ -n "$DISPLAY" ]; then

  gvimdiff %file1 %file2

else

  vimdiff %file1 %file2

fi

```

----------

## tod

 *elzbal wrote:*   

>  *BradB wrote:*   
> 
> Oh, if you're like me & su to root from a console, you will probably need to run 
> 
> ```
> ...

 

A better way than xhost is detailed in the Remote X Apps Mini-Howto at http://www.tldp.org/HOWTO/mini/Remote-X-Apps-7.html#ss7.2

----------

## rtn

 *TGL wrote:*   

> I would like to add a test to know if the commande has been launch from a linux console or from an X terminal, something like that:
> 
> ```
> if [ i dont know what ] then gvimdiff %file1 %file2 ; else vimdiff %file1 %file2 
> ```
> ...

 

You could check the output from `tty` and go from there.  I use it in my

.bash_profile to find out if I'm on the first virtual console to automagically

fire up X for me.  Just need to take this example one step further...

```
if [ `tty` = "/dev/vc/1" ]; then

        echo ""

        echo "Starting X in 2 seconds (type Control-C to interrupt)"

        sleep 2

        echo ""

        startx > .Xoutput 2> .Xerrorlog

        clear           # get rid of annoying cursor rectangle

        logout          # logout after leaving windows system

fi

```

--rtn

----------

## JoeGreensticks

I just wanted to say that these types of ideas and discussions are why Gentoo is now my Linux of choice.  This is a great tip that I used very successfully this morning with 25+ files.

----------

## tecknojunky

Thanks for this great tip.

I was a little at lost first, with gvimdiff, but this showed me all I needed to do.

As for controling file names and such, I simply import the diffs into the original file and save as is, overwriting the old one.

The dialog menu if kind of nice but it's only half done.  Not much gain from it, but it will be nice when they complete it.

----------

## krogoth

Zojas:

```
kompare file1 file2
```

btw, anyone who hasn't tried kompare should - I really like the way it displays changes.

----------

## Xenarion

what is diff?

----------

## zojas

if you run konqueror, try this:

```
man:diff
```

or 

```
info:diff
```

or on the command line:

```
man diff
```

that describes it much better than I could.

----------

## Uranus

screenshot anyone?

----------

## zojas

I have a screenshot of running gvimdiff through etc-update over ssh to my pentium II from my ibook in Mac OS X (it dual boots with gentoo I just happened to be running OS X when I took the screenshot)

http://www.desertsol.com/~kevin/screens/030117_etc-update.jpg

----------

## [UK]Superdude

 *zojas wrote:*   

> if you run konqueror, try this:
> 
> ```
> man:diff
> ```
> ...

 

I never knew you could do that in konq.

I guess if you can learn something new each day its been a good day  :Smile: 

----------

## puddpunk

I have to say, I don't really understand the concept of DIFF_COMMAND and MERGE_COMMAND. I can put kompare in the DIFF_COMMAND ok, but then what? What do I have to do to make it write the changes, write some of the changes or discard the whole file?

Can somebody please explain?

----------

## zojas

the original idea was that the diff_command would just run diff and show you the changes. then the merge_command would be some sort of interactive program to merge the changes together.

I just use gvim -d as the diff command then I can see the diff and perform the merge at the same time in my favorite text editing environment. then I never invoke the merge command from the etc-update command. I just write whatever tweaks I want to one of the files and then use options 1 and 2 from the etc-update menu.

----------

## puddpunk

Ah! Brilliant!

Thanks alot zojas

----------

## metal

KDE users might want to use kdiff3, which have a -m (merge) and a -o (output file) command line option, but I haven't tried it yet.

----------

## idiotprogrammer

Well, the idea of using a diff gui sounds awfully appealing. 

But ...

even after trying the etc-update changes to tell it to use gtkdiff, it causes a seg fault. (I am just using X, not a fancy window manager though).

Also, I noticed that gtkdiff doesn't allow you to see files starting with a period, which by the way, is how almost all of the config files are. 

So unless there's a command line that allows gtkdiff to make . files visible, then the gui is mostly useless. 

rj

----------

## Bemke

I dont like etc-updates UI, it takes to much time... I use a simple script instead  :Smile: 

$ cat etc-diff 

if [ "$1" == "" ]

then

        echo etc-diff file1 [file2]

        exit

fi

f1=$1

f2=$2

if [ "$2" == "" ]

then

        f1=$1

        f2=`echo $f1 | awk '{print gensub("._cfg0000_", "", "g", $1)}'`

fi

diff -b -B "$f1" "$f2" |grep '[<>]'|grep -v '< #'|grep -v '> #'

echo "Overwrite $f2 with $f1?";read i

if [ "$i" = "y" ]

then

        mv "$f1" "$f2"

        echo $f2 is overwritten with $f1

else

        echo "Delete $f1?";read i

        if [ "$i" = "y" ]

        then

                rm -f "$f1"

                echo "$f1 deleted!"

        fi

fi

----------

## fbreuer

Another nice program for graphical diff'ing (for use with Gnome 2 for example) is meld. See http://meld.sourceforge.net and try 

```
emerge -p meld
```

----------

## Belgabor

meld looks sweet but unfortunately its useless for merges or diffs that include a lot of whitespace change (it lacks the option to ignore whitespace).

I currently use xxdiff for etc-update using the following lines:

diff_command="xxdiff --style keramik %file1 %file2"

merge_command="xxdiff -m --resource 'Show.PaneMergedView:true' --style keramik -O -M %merged %orig %new"

----------

## Jimbow

I've been using xxdiff too.  Works great.

----------

## rjtupas

I've made the changes discussed in the first post. Do I need to edit the "using_editor=0" line in /etc/etc-config if I am using gtkdiff?

TIA,

Randy

----------

## meowsqueak

Tkdiffb, which is part of the tkcvs package, makes a nice graphical merge tool, and it integrates well with etc-update.

Although I have to say, I like the way meld works - a bit confusing at first, but the linked scrolling is pure magic!  :Smile: 

----------

## Lasitus

Great idea!  I have been wanting this but didn't looked into it personally.  I got it to open etc-update as my user, but I don't have rights to write the file.  (BTW, I am using kompare)

```
xhost +localhost
```

doesn't work for me.  I have tried various things from setting the XAUTHORITY variable to the DISPLAY variable.  From what it sounds like on this post, xhost +localhost should work.  (No matter what I have tried, root cannot use the display)

I am using:

```
sudo su -
```

to switch to root before running etc-update.  I have also tried

```
DISPLAY=":0.0" sudo etc-update
```

What am I missing?

----------

## Lasitus

Hmm, didn't notice this post was from 2003...  Well I got it display kompare by not using sudo.  I got a whole mess of errors though it seemed to work.

----------

## xentric

The user who started X should run "xhost +localhost" and that user should

also belong to the wheel group, otherwise he/she cannot su to root.

You could also try sux (emerge sux) instead of su! I've heard from lot's of

people that sux just works when su fails under X.

----------

## xentric

double...

----------

## Lasitus

Yeah, I wasn't in the wheel group.  I was using:

```
sudo su -
```

to change over to root.  After joining the wheel group and just doing this instead:

```
su -
```

I was able to get it to work.  The only thing is kompare gave some gui related errors as root.  It did seem to work ok though.

----------

## j-m

Why don´t you use dispatch-conf? If you emerge app-text/rcs you will have a complete history of your config files at your hand...   :Question:   :Confused: 

----------

## FreeManAtomic

Hi,

I done the changes, but don't work.

When start the etc-update command i always see a text-version  :Rolling Eyes: 

Sorry for my english  :Smile: 

----------

## Tinitus

Hello,

I tried the things from the 1st Posting ...

but I always get :

eg. /usr/sbin/etc-update: line 242: "gtkdiff: command not found

Why

R R

----------

## its1louder

 *Tinitus wrote:*   

> 
> 
> but I always get :
> 
> eg. /usr/sbin/etc-update: line 242: "gtkdiff: command not found
> ...

 

I have this problem too.  I can't figure it out.  I tried using meld and gtkdiff.  I also tried copying meld and gtkdiff to the /usr/sbin/ directory and also putting in line 242 /usr/bin/meld instead of just meld.  Neither worked.  Sure wish they did.

----------

## badgers

 *j-m wrote:*   

> Why don´t you use dispatch-conf? If you emerge app-text/rcs you will have a complete history of your config files at your hand...   

 

could you expand a little about what you use?

I have used dispatch -conf but it is also a command line utility.

I am really all for a GUI interface to make config file updating much more intuitive.

----------

## xentric

 *Quote:*   

> I am really all for a GUI interface to make config file updating much more intuitive.

 

You can try app-portage/cfg-update for GUI updating of your config files...

Just read the install instructions and don't forget to run "cfg-update --fix" if you

have problems starting the GUI tools as root.

The next version (1.8) will also support 3-way merging with GUI tools, so it

can auto-update a lot more.

----------

## badgers

thank you

----------

