4

I've got a directory called "secure" that I mount on my laptop via sshfs whenever the server is in reach.

While this server is in reach I want to keep it in two-way sync with a directory called "sync".

The "secure" directory is mounted with pam_mount at login and unmounted at logout. I have setup pam_script to create a symbolic link to "sync" when the mount fails and to remove the link on unmount.

In my first attempt was to run unison with pam_script:

#!/bin/bash

#pam_script_ses_open (runs at the start of a session)

home=eval echo ~$PAM_USER secure=$home/secure sync=$home/sync

if mount|grep "$secure"; then echo Synchronizing with server $sync : $secure unison "file://$sync" "file://$secure" else ln -s "$sync" "$secure" fi

And for end of session:

#!/bin/bash

userid=$PAM_USER home=eval echo ~$userid secure=$home/secure sync=$home/sync

if mount|grep "$secure"; then echo Synchronizing with server unison "file://$sync" "file://$secure" else rm "$secure" fi

Both these scripts run under root.

At logout the two directories synchronize just fine.

At login however I get the following error message:

Synchronizing with server /home/users/user/sync : /home/users/user/secure

Contacting server...

Fatal error: Wrong number of roots: 2 expected, but 4 provided (ssh://user@server/, /home/users/user, file:///home/users/user/secure, file:///home/users/user/sync)

(Maybe you specified roots both on the command line and in the profile?)

I have verified that no ".unison" directory exists in any users home directory and did apt-get purge unison followed by an apt-get install unison.

I am not entirely happy about using unison in this way (even if it did work) because it would only synchronize at login and logout. It would not be a live synchronization.

How can I get sshfs or fstab to start a live synchronization whenever the directory is mounted or if that is not possible, why is unison failing in my current setup?

I am looking for a clean and robust solution.

d_inevitable
  • 1,922

0 Answers0