WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Configuration files that are user-modifiable  (Read 2456 times)

Offline samedirection

  • Jr. Member
  • **
  • Posts: 64
Configuration files that are user-modifiable
« on: July 02, 2009, 08:52:25 AM »
This may be obvious, but I can't think my way through it. 

Is it possible to have your extension (TCE or TCZ) include configuration files which:

1.  Work out of the box, without manual "copying to your home directory"
2.  Are changeable---even deletable---by the user
3.  The user's modifications persist and aren't clobbered by the next boot?
4.  bonus if package updates don't clobber user config changes, but do update things that aren't changed by the user.

I'd like to package up some Emacs extensions, along with some elisp files that load these extension and configure them sensibly.  So I want the user to have the experience I've set up---unless they see otherwise.  In this case they should be able to tweak my settings, or erase the config files (so that the extensions are not loaded automatically into Emacs), and get what they want.

I'd be fine to put the config files in some "system" place (/usr/local/share/emacs/local-extensions/config/) as opposed to a user's home directory and tell these experienced users to "copy the configs to somewhere in your home directory and change this variable to point to the directory where you put your versions".  Does this sound like the best way?

But even that leaves me with the problem of the main config file for the program.  How do you get a sensible config file into the user's home directory on the first load, which isn't clobbered by subsequent loads?

I suppose other extensions have solved this.  Can anyone point me to one that does it cleverly, so that i can hack it's install script? 
Many thanks.

By the way, it's hard to find documentation on what the 'user.tar.gz' part of an extension is for.  Perhaps that could be added to the wiki page on Creating Extensions, so people know (1) when to use it (2) when not to use it (3) what problems or limitations it has (why to avoid it when you can).  I did a search of the forums and got a few shreds, but not the whole picture.  There seems to be some problem with converting TCE's with a user.tar.gz to TCZs. True? 
 

Offline ^thehatsrule^

  • Retired Admins
  • Hero Member
  • *****
  • Posts: 1726
Re: Configuration files that are user-modifiable
« Reply #1 on: July 02, 2009, 02:47:59 PM »
1. depends on the app.  Some typically scenarios: use system files (ie /etc), or user files (usually ~/.app*) which may be copied from a system default if it doesn't exist (ie from /usr/.../share/myapp/)

2. If it's in the users' home dir they are user changeable

3. See #1.  If you are talking about a manual setup kind of thing, you could just check if the config directory/file exists before copying a default over.

4. There may be possible solutions for this, but it depends on the setup


Creating the optional user.tar.gz is described on that page as well.  Note that they are only specified for tcz's.

Offline Jason W

  • Retired Admins
  • Hero Member
  • *****
  • Posts: 9730
Re: Configuration files that are user-modifiable
« Reply #2 on: July 02, 2009, 03:23:53 PM »
If a config file in /home is in your backup, it will get restored on the next boot after the extension is loaded, so it will overwrite the copy someone may have put in the extension.

I do not like putting files in /home at all in extensions for the reason of not clobbering in the first place.  If I want to  put a default config file in /home, I simply put the file under /usr/local in the extension and copy it over with the startup script like this:

Code: [Select]
[ -f /home/$USER/configfile ] || cp /usr/local/share/appname/configfile /home/$USER/configfile

That provides a default config file without overwriting a users existing one if they are using persistent home.

Also, config files in a tcz extension should always be placed in the user.tar.gz so they are writable by the user or the app itself. 

Offline samedirection

  • Jr. Member
  • **
  • Posts: 64
Re: Configuration files that are user-modifiable
« Reply #3 on: July 03, 2009, 04:57:09 AM »
Thanks for the replies.  And thanks Jason for that line of code.  That'll work fine for me.

As to config files belonging in user.tar.gz for tcz's.  I'm a little confused.  That lets them be writable, but I assume that means writable for the current session only.  Any changes are not rezipped up back into the tcz are they?  [edit to myself: no they can't be since you can't guarantee that the tcz is writable]  So if you want a config file that is copied to the user's home directory (to be saved there by the user's normal persistence setup, whatever that is), then I gather you should probably NOT put them in user.tar.gz but copy them over, as above, with an install script.

Or do I have that wrong?

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14815
Re: Configuration files that are user-modifiable
« Reply #4 on: July 03, 2009, 05:48:42 AM »
You have a good point there - a couple of times I've put /usr/local/etc/xxx.conf.orig in the tcz to allow users to copy xxx.conf.orig -> xxx.conf and then add xxx.conf to their backup

Offline Jason W

  • Retired Admins
  • Hero Member
  • *****
  • Posts: 9730
Re: Configuration files that are user-modifiable
« Reply #5 on: July 03, 2009, 08:51:39 AM »
As for tcz's one would make the config file into a user.tar.gz and also be copied to home.  If you just copy them over from, say, /usr/local/etc you are copying over a symlink that is not writable.

A way around that though is to copy the config directly from the mounted tcz directory like this:

[ -f /home/$USER/.config ] || cp /tmp/tcloop/appname/usr/local/etc/config /home/$USER/.config