Question

I've seen people suggest /var/lib but that doesn't work on my system. Every sub-directory of /var is read-only except for /var/lock and /var/log.

Do I just need to write a Linux shell script to grant superuser access? Or is there a Java based solution?

/bin and /usr are both system file directories, so I don't want (nor can I) store files there.

As long as the application needs only to operate within the user I can use:

System.getProperty("user.home") + File.separator + ".appname"'

for the data directory.

But what about persistent system-wide data? Where does that go?

Extra Note: I have this problem with MacOS too. I can use /user/Library/Application Support for user-specific data but I have no way to access global directories.

Second Note: I am aware of and have used the Preferences API. I'm looking for a way to store data excluding that.

Was it helpful?

Solution

What is normally done is the application is installed using the system's packaging tools. But you could write your own installer script as well. During the installation process, run as root, a new group may be created, and a new directory under /var/lib is created owned by that group. For example, the locate command does this:

$ ls -l /usr/bin/locate
-rwx--s--x 1 root locate 42032 Nov 17 19:33 /usr/bin/locate

And it's data dir:

drwxr-x--- 2 root locate 4096 Nov 15  2010 /var/lib/slocate

The locate command uses setgid feature to set its own process group ID to locate, that gives it permission to read the /var/lib/slocate subdirectory.

In your case you (your installer) would set write permissions as well so the app can write data there on the users behalf.

OTHER TIPS

From what I gather the /var/lib/ directory is the correct place to put things. You need to be root when accessing those directories.

You could try using the http://www.freedesktop.org/wiki/Software/polkit toolkit to elevate privileges in linux. (it's free software.)

Something like http://www.amug.org/~glguerin/sw/#authkit might help on a mac.

On Linux you could also have a routine that runs the installation part with gksudo. Or uses the commands mentioned here. https://stackoverflow.com/a/690491/1790338

Hope this helps somewhat.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top