Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

How can I make a variable symlink that would point to a different location according to the current user? Is it possible? Should I use something else instead? A mount point? How?

Here is the problem in case you come across a different solution:

Here at work we are a team developing on Unix with SVN. We all use the same development machine (remotely). So we have checkouts in different places (not /home but a specific dir mounted on another disk, let's say /svn/[userlogin]/).

We use scripts and tools. Some special tools have a complex configuration and project file that includes the path of the source files. This is error prone and we lose a lot of time because of bad config or 'projects' that need to be recreated all the time. I would like to share this complex configuration and the project files across all developers.

But for such files to be shared while working on different checkouts, I must either:

  • correct on-the-fly the paths stored in config/project to adapt them to the current user
  • make a "magic" fixed path that symlink/mount/point points to a different place according to the user (so same project file but pointing to different source)

Before that we used clearcase, which was mounting a view of the same path for everyone (let's say /vob), each developer seeing his or her own view. That was convenient.

How can I do a similar thing? Can you think of another solution? Thanks.

-- Edit --

I was thinking of Eclipse IDE. I want to share some workspace settings, the project and the run/debug configurations. Eclipse (+plugin) settings consist of 50+ small files, so editing them is out of question.

With clearcase it was easy thanks to the fixed "/vob" path which, for each terminal, was automatically pointing to the "view" we choose.

I would like something similar. I want a /svn/mysource which, for each terminal, point to the user current checkout, which is in a user-dependent path.

share|improve this question
1  
I'm unclear why every user needs to have the paths point to a different place. Can't they share the same files? If not, it should be possible to set things up so that the paths differ only in minor respects, i.e. /srv/username/.... They one could easily script the config paths user environment variables like the username USER. –  Faheem Mitha Jan 6 '12 at 12:22
    
@FaheemMitha edited the question to precise that we are using the same machine (remotely) –  Offirmo Jan 6 '12 at 14:53
    
You can't easily have a fixed path which points to a different place for each user. Can you elaborate on how Eclipse views this? Does it expect a fixed path, or can it be persuaded to look at some environment variable? If so, you could configure such an env variable accordingly. –  Faheem Mitha Jan 6 '12 at 16:30

5 Answers 5

This depends on whether the app config can process commands or interpolate shell variables.

The bash login shell sets the environment variable LOGNAME in a login shell.
You could use /svn/${LOGNAME}/ in the config, if the application interpolates shell variables in config. Then you can share common config with each user referring to her own path.

If the application does not interpolates shell variables in config, then you can create a symlink for each user making generic reference to /svn path and use the generic name in the shared config.

who will list the current username.
If you want to write a script that each user executes once upon setup to create a symlink.

ln -s /svn/$(who) /svn/anyuser

Then share common config referring to /svn/anyuser (pick a generic name that suits you)

Beware the noob user unaware of links use and removes it (you've just been promoted to admin :)

share|improve this answer
    
Thanks but I edited the question to precise that we are all using the same machine, hence the problem. –  Offirmo Jan 6 '12 at 14:55
    
without describing what type of scripts(bash, python, perl) and which applications you're using, you're making it difficult for someone to offer helpful advice. Regardless of how many machines are being used, it's a linux box and all users login using individual usernames, yes? –  bdowning Jan 6 '12 at 15:09

So you want each user to see different thing in the file system. Unix isn't really designed that way (VMS and Plan9 makes it easier).

The only method I know, is using chroot(), but then you mask everything not in the hierarchy where you switched, symbolic link will stay in your hierarchy, and hard one aren't helpful with directories. It should be possible to use a FUSE file system to mirror the true root while providing the view you want. You'd then chroot to that position. If you don't find an existing one suiting you, you could write one...

share|improve this answer

GFS or OCFS can be used to achieve your goal. Both file-systems can present the same mountpoint with different contents based on various things. Both are meant to be used as cluster file-systems and have that ability to present the same directory with different content for different architectures.

The question that arises to me if this is worth the effort. I am sure you can solve this with other tricks (maybe an executable automount-map?).

share|improve this answer

You can't make symbolic links with different contents for different users on Linux or most other unices. Or rather, you can, but only through unusual filesystems (likely based on FUSE) and the setup would be rather difficult.

Arrange to have all your settings relative to the user's home directory. It doesn't matter that some files are under /svn/$USER rather than /home/$USER: just have each user create a symbolic link /home/$USER/svn -> /svn/$USER (or create it for them).

If some applications insist on having an absolute path, write a script that performs the replacement of the checked-in path to the correct path for the user, e.g.

sed -i -e "s:/home/\$USER/:/home/$USER/:g" .eclipse/*

Make sure to convert /home/bob back into the literal string /home/$USER in a pre-commit hook.

share|improve this answer

You could probably hack amd (the automounter daemon) for that, since it already does something similar.

linux# df /home
Filesystem           1K-blocks Used Avail Capacity  Mounted on
pid174@repoman:/home         0    0     0   100%    /home
linux# ps 174
  PID  TT  STAT      TIME COMMAND
  174  ??  Ss     0:15.76 amd -p -a /.amd_mnt -l syslog /home /etc/amd.home

With the automounter, /home appears to be a directory, and doing a stat("/home/user") returns info implying that "user" is a symlink to some other directory. The automounter gets involved in creating these "symlinks" on the fly, and removing them after a period of disuse. If you use that as a base and modify the source code, you could have the process return different symlinks for different users.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.