Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option for versioning and updating config files #176

Open
Licenser opened this issue Nov 27, 2014 · 2 comments
Open

Option for versioning and updating config files #176

Licenser opened this issue Nov 27, 2014 · 2 comments

Comments

@Licenser
Copy link
Contributor

I am not sure if this is a concern for anyone else so I wanted to discuss this before storming off and and creating a pull request ;)

If a config file changes between version 1 and 2 it is quite a pain for the end user to update that file, it means manually transferring every value they changes in the new file.

Usually updates do not change much a option gets added or removed, sometimes something gets renamed.

The simplest idea would be:

  1. have cuttlefish reads the old data ignoring missing options and tossing away unknown ones
  2. write a new config based on the supplied values or defaults from the new schema files

This would probably cover 90% of all cases, it would fail for cases where the type caged but it would give a good starting approach I think.

This could possibly be handled by a simple bash script? Not sure.

A more complex approach would be versioning the config files, allowing to provide versions of the schema files and additional translations form V1 to V2 to V3 etc. This is a lot more complex but would allow for covering every possible aspect.

@seancribbs
Copy link

@Licenser Yes, we need to have a plan to deprecate, rename, and remove settings gracefully. Any ideas are appreciated, let's open the discussion.

@Licenser
Copy link
Contributor Author

Licenser commented Dec 9, 2014

This is a rather dirty hack bit it's a start. Basically the way I handle the variables right now is that the 'package' that installs only provides a conf.example and not the actual conf file so I'd call this like:

./update_conf.sh sniffle.conf sniffle.conf.example > sniffle.conf.new && mv sniffle.conf sniffle.conf.old && mv sniffle.conf.new sniffle.conf

#!/usr/bin/env bash

example=$1
old=$2
get() {
        var=$2
        conf=$1

        res=$(grep "^\\s*${var}\\s*=" $conf | sed "s/^\\s*${var}\\s*=\\s*//")
        if [ -z "${res}" ]
        then
                exit 1
        fi
        echo "${res}"
}


while read line
do
        if echo "${line}" | grep -v '^#' | grep -v '^$' > /dev/null
        then
                key=$(echo "${line}" | sed 's/\s*=.*//')
                if val=$(get ${old} ${key})
                then
                        echo "${key} = ${val}"

                else
                        echo "${line}"
                fi
        else
                echo "${line}"

        fi
done < "${example}"

(edited to remove debug prints in the bash script)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants