The forum

Best practice for modifying config file

Author Replies
gotsanity Monday 3 March 2014 at 1:30
gotsanityAnonymous

I am trying to figure out the best practice for modifying a config file during script execution.

I have a script that installs everything fine, however in order to work properly a config file needs to be edited. A single variable in a config needs to be switched from true to false. As far as I can figure out I have the following options:

  1. keep a modified copy online. Download and replace it during script execution.
  2. Do something hacky and use some commandline-fu to modify the file.
  3. Launch the file in a text editor and give the user instruction to modify it.

Option #1 seems to be the best and less prone to failure option but makes updates to the software more difficult to manage and some people may not trust it.

Option #2 could work but I dont know much about modifying files via script/command line

Option #3 Seems like it would work fine but will run into issues with cross-platform compatibility (which is a requirement) and user error (modifying the wrong variable, etc)

What would you guys suggest?
petch Monday 3 March 2014 at 11:02
petch

I can add a 4th option just for completeness:

4. keep a modified copy in the script.

This can be done if the configuration file is small, it can even be base64 encoded if it's binary or requires specific end-of-lines, such things.

I'd personally avoid the 3rd solution, that's both not user friendly and error-prone.
Any other 3 solutions are fine, depending on the context.
For the 2nd solution you can use sed, perl, awk,... There's plenty of tools for the job under Unix, since text processing was the first usage for this platform ;)
If you can tell a bit more about the file format, I probably can help with that.

gotsanity Monday 3 March 2014 at 12:49
gotsanityAnonymous

The file really only needs to be replaced with this:

{ UseHardwareAcceleration: false }

The original can be completely overwritten with the previous text. The contents of the file will be generated/updated back to what they need to be on the next launch. I am curious how you would go about using option 4 as that seems to be the best/simplest way to accomplish whats needs to be done.

Edited by gotsanity

petch Tuesday 4 March 2014 at 17:16
petch

If that's really sufficient,

echo '{ UseHardwareAcceleration: false }' > .../configfile

This site allows content generated by members, and we promptly remove any content that infringes copyright according to our Terms of Service. To report copyright infringement, please send a notice to dmcayonlinux.com