User:David Hedlund/Generation of configuration files

From Free Software Directory
Jump to: navigation, search

Conventional approach

A widely adopted method for generating and modifying configuration files using bash scripts involves the following steps:

  1. Delete the existing default configuration file.
  2. Temporarily launch the software to create a new default configuration file.
  3. Edit the generated configuration file as needed.

Example

For instance, consider a software application named "foo" that produces a configuration file called `configure.xml`:

# Delete the existing default configuration file.
rm ~/.configure/foo/configure.xml

# Temporarily launch the software to create a new default configuration file.[1]
timeout 1 foo

# Edit the generated configuration file as needed.
sed -i "
s|<setting3>true</setting3>|<setting3>false</setting3>|;
s|<setting8>true</setting8>|<setting8>false</setting8>|;
s|<setting9>true</setting9>|<setting9>false</setting9>|;
" ~/.configure/foo/configure.xml

1: Default configure.xml:

<?xml version="1.0" encoding="UTF-8"?>
<content>
    <setting1>true</setting1>
    <setting2>true</setting2>
    <setting3>false</setting3>
    <setting4>true</setting4>
    <setting5>true</setting5>
    <setting6>true</setting6>
    <setting7>true</setting7>
    <setting8>false</setting8>
    <setting9>false</setting9>
    <setting10>true</setting10>
</content>

Improved approach

An enhanced method simplifies the process by directly creating a configuration file that includes only the desired settings. This approach not only streamlines the configuration process but also:

  • Provides a clearer overview of the settings being applied, as compared to applying patches (`patch "config.xml" < "config-patch.xml"`) to an existing configuration file.
  • May be required by some software. For example, LibreOffice does not generate all default settings in ~/.config/libreoffice/4/user/registrymodifications.xcu. After you have figured out the settings[1] can add them with a script.

By generating a fresh configuration file with only the necessary parameters, users can easily understand and manage their configurations without the clutter of irrelevant settings.

Example

# Create a new configuration file that contains only the specified lines.
tee ~/.config/foo/configure.xml > /dev/null << EOF
<?xml version="1.0" encoding="UTF-8"?>
<content>
    <setting3>false</setting3>
    <setting8>false</setting8>
    <setting9>false</setting9>
</content>
EOF


Start the program, it add the default settings:

<?xml version="1.0" encoding="UTF-8"?>
<content>
    <setting1>true</setting1>
    <setting2>true</setting2>
    <setting3>false</setting3>
    <setting4>true</setting4>
    <setting5>true</setting5>
    <setting6>true</setting6>
    <setting7>true</setting7>
    <setting8>false</setting8>
    <setting9>false</setting9>
    <setting10>true</setting10>
</content>

This streamlined approach is more efficient and reduces unnecessary steps, resulting in a cleaner configuration process.

1:

  • Run: rm ~/.config/libreoffice/4/user/registrymodifications.xcu; timeout 5 soffice && cd ~/.config/libreoffice/4/user/ && cp -a registrymodifications.xcu registrymodifications.xcu.default
  • Open any libreoffice application and configure it which will modify registrymodifications.xcu
  • Run: diff -u registrymodifications.xcu registrymodifications.xcu.default


Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the page “GNU Free Documentation License”.

The copyright and license notices on this page only apply to the text on this page. Any software or copyright-licenses or other similar notices described in this text has its own copyright notice and license, which can usually be found in the distribution or license text itself.