crudini is a utility to simplify reading and updating ini files from shell scripts, so named as it provides CRUD functionality.
Many programs in UNIX now use ini files for configuration, like systemd, yum, OpenStack and mysql, ..., and I've needed to programmatically manipulate them many times and was surprised that such a tool didn't already exist. There is augeas, though it's awkward to use. Also git config -f inifile is an option, though also a little awkward, quite git specific, and bundled in a 13MB git-core package on my distro.
crudini is robust in its file update implementation, applying ACID prinicples as detailed in my robust file replacement discussion.Download
- github for source and issues
- latest crudini script (requires iniparse installed)
- pypi packge and release archive
- Fedora and EPEL packages
- debian packages
INI formats supported
In general ini files are quite varied and non standard, though the format supported by crudini should handle the vast majority of situations. The best way to see the details of the supported ini format, is to look at the crudini example.ini used both for documentation and testing.Interface synopsis
crudini --set [--existing] config_file section [param] [value] --get [--format=sh|ini|lines] config_file [section] [param] --del [--existing] config_file section [param] [list value] --merge [--existing] config_file [section]
Examples
- Add/Update a var
crudini --set config_file section parameter value - Update an existing var
crudini --set --existing config_file section parameter value - Add/Append a value to a space or comma separated list
crudini --set --list config_file section parameter a_value - update an ini file from shell variable(s)
echo name="$name" | crudini --merge config_file section - merge an ini file from another ini
crudini --merge config_file < another.ini
- Delete a var
crudini --del config_file section parameter - Delete a section
crudini --del config_file section
- output a value
crudini --get config_file section parameter - output a global value not in a section
crudini --get config_file '' parameter - output a section
crudini --get config_file section - output a section, parseable by shell
eval $(crudini --get --format=sh config_file section) - output an ini processable by text utils
crudini --get --format=lines config_file
idiff <(crudini --get --format=lines fedora1.repo|sort) \ <(crudini --get --format=lines fedora2.repo|sort) --- /dev/fd/63 2013-05-16 01:11:22.012934833 +0100 +++ /dev/fd/62 2013-05-16 01:11:22.012934833 +0100 @@ -9,12 +9,11 @@µ [ fedora ] failovermethod = priority [ fedora ] gpgcheck = 1 [ fedora ] gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch -[ fedora ] metadata_expire = 7d [ fedora ] name = Fedora $releasever - $basearch [ fedora-source ] enabled = 0 [ fedora-source ] failovermethod = priority -[ fedora-source ] gpgcheck = 1 +[ fedora-source ] gpgcheck = 0 [ fedora-source ] gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch [ fedora-source ] metadata_expire = 7dFor example, one can improve the git diff experience using the pattern above.
© May 16 2013