Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 194 - nifty script to make short work of editing ._cfg????_* in /etc
Summary: nifty script to make short work of editing ._cfg????_* in /etc
Status: RESOLVED FIXED
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Unclassified (show other bugs)
Hardware: All Linux
: High enhancement (vote)
Assignee: Geert Bevin
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-01-15 23:15 UTC by aeoo
Modified: 2011-10-30 22:19 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description aeoo 2002-01-15 23:15:19 UTC
What does it do?  It's very simple.

First vi this script and config the first 3 variables there.  For example, if 
you feel like you know what you're doing, take out '-i' options for rm and mv 
and if your $EDITOR is other than vim, change editor_opts to use a proper 
option for your editor's diff mode.

It will cycle over each ._cfg????_* and its respective file pair and if your 
$EDITOR in /etc/profile is set to vim will display both old and new file side 
by side using vim's awesome diff mode.  Take a look at both files and it will 
be obvious very fast what was changed.  Jump to the proper window and edit as 
nessecary.  Type ':w' then ':qall' to quit all files and you will see a short 
menu like this:

  Delete (type 1 or 2):
1) /etc/init.d/shutdown.sh
2) /etc/init.d/._cfg0000_shutdown.sh
  OR
3) edit this file pair again

If you hit '1' (only one keystroke is accepted, so watch out!), you will 
remove your old file and move the new ._cfg????_* file into its place.

If you hit '2', you will keep your old file.

Hitting '3' will allow you to look at both of these files again, just in case 
you realized suddenly that you've made a mistake and need to go back to 
editing.

Once you pick either 1 or 2, you will move onto the next file pair, or quit if 
there aren't any left.
Comment 1 aeoo 2002-01-15 23:23:28 UTC
#!/bin/bash
# Copyright 2002 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License, v2 or later
# Author: Leo Lipelis

# uses $EDITOR value for editor
# edit three lines below to your liking
rm_opts="-i"
mv_opts="-i"
editor_opts="-d" # vim diff mode

cnf_files=`find /etc -iname '._cfg????_*'`

# returns 1 if the file pair still needs to be looked at
# or 0 if one of the two files was chosen for deletion and
# everything is fine
rm_extra_file() {
        old=$1
        new=$2
        echo
        echo "  Delete (type 1 or 2):"
        echo "1) $old"
        echo "2) $new"
        echo "  OR"
        echo "3) edit this file pair again"
        # silently read 1 char from stdin
        read -sn 1 input
        case $input in
        1)
                echo
                echo "deleting $old ..."
                rm $rm_opts $old
                echo "moving $new to $old ..."
                mv $mv_opts $new $old
                ;;
        2)
                echo
                echo "deleting $new ..."
                rm $rm_opts $new
                ;;
        3)
                echo
                echo "looking at $old and $new again ..."
                return 1
                ;;
        *)
                echo
                echo "Please pick a valid choice next time..."
                rm_extra_file $old $new
                ;;
        esac
}
 
for new_full_path in $cnf_files; do
        file=${new_full_path##*/}
        old_full_path=${new_full_path%/*}/${file:10}
        $EDITOR $editor_opts ${old_full_path} ${new_full_path}
        until rm_extra_file ${old_full_path} ${new_full_path}; do
                $EDITOR $editor_opts ${old_full_path} ${new_full_path}
        done
done
Comment 2 aeoo 2002-01-15 23:24:19 UTC
For some reason I couldn't attach this file :(.  Bugzilla complains that no file
was provided.  I tried with konqi and moz.  Oh well, I've pasted it into comment.
Comment 3 aeoo 2002-01-16 02:03:10 UTC
#!/bin/bash
# Copyright 2002 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License, v2 or later
# Author: Leo Lipelis

# uses $EDITOR value for editor
# edit three lines below to your liking
rm_opts="-i"
mv_opts="-i"
editor_opts="-d" # vim diff mode

cfg_files=`find /etc -iname '._cfg????_*'`

# returns 1 if the file pair still needs to be looked at
# or 0 if one of the two files was chosen for deletion and
# everything is fine
rm_extra_file() {
        old=$1
        new=$2
        echo
        echo "1) Upgrade to new $new"
        echo "2) Keep existing $old"
        echo "  OR"
        echo "3) Edit this file pair again"
        echo -n "Type (1, 2 or 3): "
        # read and echo 1 char from stdin
        read -n 1 input
        echo
        case $input in
        1)
                echo
                echo "deleting $old ..."
                rm $rm_opts $old
                echo "moving $new to $old ..."
                mv $mv_opts $new $old
                ;;
        2)
                echo
                echo "deleting $new ..."
                rm $rm_opts $new
                ;;
        3)
                echo
                echo "looking at $old and $new again ..."
                return 1
                ;;
        *)
                echo
                echo "!!! Please pick a valid choice next time"
                rm_extra_file $old $new
                ;;
        esac
}

for new_full_path in $cfg_files; do
        file=${new_full_path##*/}
        old_full_path=${new_full_path%/*}/${file:10}
        $EDITOR $editor_opts ${old_full_path} ${new_full_path}
        until rm_extra_file ${old_full_path} ${new_full_path}; do
                $EDITOR $editor_opts ${old_full_path} ${new_full_path}
        done
done

Comment 4 aeoo 2002-01-16 02:06:32 UTC
Second version of the script is slightly tweaked for improved code and 
end-user readability.  cnf_files variable was renamed to cfg_files.  User 
prompt has been made more readable and it now echoes your choice.
Comment 5 Bruce A. Locke 2002-01-26 03:36:37 UTC
An option to 'diff -u' the two files would be very handy...

Looking forward to a completed version :)
Comment 6 Daniel Robbins (RETIRED) gentoo-dev 2002-01-28 12:42:34 UTC
proof of concept for a script updating program from aeoo.  these should be
allowed to mature and then we should include a polished one in gentoo linux 1.0
Comment 7 Geert Bevin 2002-01-31 14:55:51 UTC
included in gentoolkit, closing the bug