cfghelper.py

About

cfghelper.py is a Python script to help manage config files for Gentoo Linux. cfghelper.py is based on a script I wrote called "confighelper.py". When installing a new package using portage, config files are automatically replaced. Instead the new config file, which I refer to as a cfg file will be created. It is the user's responsibility to take care of replacing the existing file with the new one, merging the two, or deleting the new one.

This process can be a bit of a nuisance especially for some packages list postfix, which has a whole pile, most of which I am happy to have automatically replaced. This script will search for config files with cfg files and iterate through them allowing you to view difference between the two, replace the current with the new one, or remove the new one.

How it Works

cfghelper.py does the following:

  1. Searches for cfg files in directories listed in SEARCH_PATH. The following pattern is used to find cfg files:

    \._cfg(\d+)_(.+)
    
  2. Automatically replace any existing config files with the most recent cfg file if the config file matches any pattern in AUTO_REPLACE_PATTERNS.

  3. Allow the user to specify what to do with each of the remaining cfg files. See Commands for a description of what commands are available for each cfg file.

Usage

NOTE: You must run cfghelper.py as root, otherwise you won't have permission to write system configuration files.

Installation

  1. Download cfghelper.py
  2. chmod +x cfghelper.py
  3. to run, ./cfghelper.py

Configuration

Currently the only way to modify cfghelper.py's configuration is to edit the script. I'd like to change this in the future, so configuration is read from a file, but that hasn't happened yet. Below are the main variables you might want to modify:

SEARCH_PATH

A list of directories cfghelper.py should search for cfg files in. By default, the following directories are searched:

  • /etc
  • /var/qmail/control
  • /usr/share/config
  • /usr/kde/2/share/config
  • /usr/kde/3/share/config
  • /opt/jakarta/tomcat/conf
AUTO_REPLACE_PATTERNS
A list of regular expressions which are matched against config files. If a config file matches any of the patterns, it is automatically replaced with the most recent cfg file.

Commands

D
View differences between config file and current cfg file.
E
Edit current config file and cfg file using Vim.
L
Replace current config file with most recent cfg file and continue with the next config or cfg file.
N
Move to the next cfg or config file.
Q
Quit script.
R
Replace current config file with current cfg file and continue with the next config or cfg file.
S
Show all config and cfg files found by cfghelper.py
X
Delete current cfg file and continue with the next config or cfg file.

Note

Before any config file is replaced with a cfg file it is backed up to $HOME/.cfghelper/backups/ using a scheme similar to the naming scheme for cfg files. Backups are sequentially number and have the same path to the original file, but under the backup directory. For example, the first time:

/etc/conf.d/net

was replaced, it would first be backed up to:

$HOME/.cfghelper/backups/etc/conf.d/net-0001

Todo

  • read configuration from an rc file
  • create a distutils package
  • create an ebuild
  • better error handling (if not run by root)
  • add ability to remove cfg files whose only changes are in the header comment. For example, #$Id ... $.

Screen Shot

Here's a screen shot of cfghelper.

Screen Shot of cfghelper

view larger image (823x493)

Version History

  • Version 0.1.1, 2002-11-14
    • Fixed a bug in the prompt display. When moving the next cfg file for a config file, the cfg file number in the prompt was updated.
  • Version 0.1, 2002-11-13
    • Initial Release