3

This is a problem that crops up from time to time and annoys me greatly.

Sometimes I need to provide an absolute path, normally in a configuration file, that should refer to the current user's home directory, but where the configuration file does not understand bash's tilde or variable expansion (so ~/foobar, $HOME/foobar, and /home/$USER/foobar are all out).

My ideal solution would be if there were some 'active' symbolic link within /proc or similar that always expands to the current user's home directory. For example, we have /proc/self, which is a symbolic link with a value that depends upon the process accessing it. Does a similar link exist that always refers to the current user's home directory?

This often crops up when writing re-usable configurations that will be shared with others within an organisation, or with myself across computers (where my username may be different between computers). It can also crop up as an obstacle in making configuration files relocatable. For example, ideally creating a tarball of my $HOME and extracting it to another user's $HOME would immediately setup the other user with an environment identical to my own, but if all my symlinks and/or configuration files are hardcoded with /home/cdfh/..., then clearly this won't work.

In all cases, there have always been workarounds, but having the ability to refer to $HOME with /proc/home would be phenomenally useful.

So, after years of unsatisfactory workarounds, I'm asking: does anyone else suffer from this problem? What workarounds have you found? Are there any solutions?

Edits:

My platform is Linux, although I would ask this question on behalf of any/all Unix-derived systems.

Regarding the "active" approach, these questions are relevant, and the outcome is that I would use scriptfs to create a filesystem where reading a file no longer reads the data of the file, but rather executes a process whose standard output substitutes as the file data. The process would thus output data that acts as a symbolic link to the reading user's home directory. I sadly haven't had a chance to implement this yet.

Rephrasing the question using what I now understand to be the proper terminology, I want to create a variable symlink that produces a link on the basis of the HOME environment variable. Unfortunately, variable symlinks are not natively supported by Linux, but can be implementing using FUSE-based approaches, such as above. Curiously, they are supported in various BSDs, and some are advocating bringing support to Linux.

  • 1
    Some software do allow for placeholder symbols denoting things like the user's home directory (I'm thinking of %d in ~/.ssh/config for example). Are you working with the configuration of a particular program that maybe does something similar? Also, please mention exactly what kind of system you are using (/proc is available on a few non-Linux systems as well). Oh, and did you consider writing some form of installation script for your config files, with placeholders? – Kusalananda Aug 28 '19 at 18:24
  • @Kusalananda Good point on platform, I've edited. Very valid point on %d and similar placeholders, but while I welcome the discussion, I'm keen for workarounds/solutions that are agnostic to the particular program in question, as this has cropped up over the years in many many different contexts. Installation scripts have been my favoured workaround to date (echo "configuration text with $HOME" > .config-file), but they create additional barriers; e.g., if deploying a configuration with git, then the user needs to remember to setup hooks, etc. – sircolinton Aug 28 '19 at 19:12
  • /proc is a view into the kernel. The kernel doesn't know anything about a "home directory" -- that's purely a userspace thing. – Andy Dalton Mar 25 '20 at 03:14

0 Answers0