I forgot to mention I'm on lubuntu oneiric with unison version 2.32.52
Anyhow I did some tests:
Added in myUser's .bashrc
export UNISONLOCALHOSTNAME=my-pc-foo-bashrc
Added in myUser's .profile
export UNISONLOCALHOSTNAME=my-pc-foo-profile
Added in root's .bashrc
export UNISONLOCALHOSTNAME=my-pc-bashrc
Added in root's .profile
export UNISONLOCALHOSTNAME=my-pc-profile
Then I opened a terminal and typed
Code:
foo@my-pc:~$ printenv | grep UNI
UNISONLOCALHOSTNAME=my-pc-foo-bashrc
foo@my-pc:~$ sudo printenv | grep UNI
[sudo] password for foo:
(no output!!!)
foo@my-pc:~$ sudo su
[sudo] password for foo:
root@my-pc:/home/foo# printenv | grep UNI
UNISONLOCALHOSTNAME=my-pc-bashrc
So:
1. put export in .profile doesn't matter (in fact unison's guide only mentions to add UNISONLOCALHOSTNAME to .bashrc
2. the command 'sudo printenv' cannot access to any exported env variable.
3. It seems I need to first login as root with sudo su to be able to access an env var exported in root's bashrc.
Then I carried on my tests:
TEST A
Code:
sudo su
(login as root)
unison-gtk profile
Connected [//my-pc-bashrc//mypath -> //my-pc-bashrc//mypath-sync]
It accesses to root's bashrc exported env and try to store info under /root/.unison
TEST B
Code:
sudo unison profile
or
sudo unison-gtk profile
Connected [//my-pc-bashrc//mypath -> //my-pc-bashrc//mypath-sync]
It accesses to root's bashrc exported env but try to store info under /home/myuser/.unison
I tried to copy the files unison created under /root/.unison into /home/myuser/.unison but unison doesn't recognize them and try to create new ones.
I tried to rename the first ones with the names unison creates the new ones but unison locks them and refuses to use them.
So unison wants to create different files for different users who fired it.
Finally unison creates a unison.log owned by root:root under /home/myuser/.unison
So this is definitely NOT a recommendable way.
TEST C
Using
Code:
gksu unison-gtk profile
or
gksu unison profile
I don't have any string printed like the above 'Connected ..'
so I cannot be sure it accesses to env variables exported in root's bashrc.
Unison tries to create new files under /root/.unison with different names of the test A, but with the same names of the test B
The fact the names are the same suggests me unison can recognizes the env exported and stores this information togheter with the username who fires it.
Renaming the files produced with test A with the names of this new created files produces the same error then in test B (unison locks the archives)
So it seems not possible to start unison from different sudoers and share archives with the last two methods.
CONCLUSIONS:
So at the end of my tests I would say:
1. An application can access to an env exported in root's .bashrc for sure when started with:
Code:
sudo su
(login as root)
applcation
or
sudo application
and I think also with even if I couldn't found how to be 100% sure of that.
2. In particular if one needs to use unison with root privileges I would recommend to use
Code:
sudo su
(login as root)
unison-gtk profile
and to backup /root/.unison folder, in this way archives can be shared within different sudoers if ever needed.
LAST NOTE:
If my first conclusion is right, I cannot understand why 'sudo printenv | grep UNI' prints nothing as I said at the start of this post
It would be nice to have your opinion on this too.
Bookmarks