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.
#!/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
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.
#!/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
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.
An option to 'diff -u' the two files would be very handy... Looking forward to a completed version :)
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
included in gentoolkit, closing the bug