A simple Bash wrapper script for Unison and Inotifywait, in order to syncronize LDAP user roaming home files with the local machine for offline use; while keeping some files and folders on local storage, according to configuration.
Consider the directory stucture below. The server server.domain.tld
provides two NFS shares that are mounted on login via AutoFS.
-
/ldap
contains your user's roaming home directory -
/share
contains your user's personal directories like Documents, Images, Music, Videos, etc. -
/home/ldap
contains your user's local home directory. Here lie all files and directories that are machine-specific (e.g..bash_history
,.cache
) -
/storage
is the user's primary computer local file storage
Note: Dotted lines represent symbolic links.
Homesync works in 2 stages:
Login:
-
The script will start by syncronizing
/ldap/bob
with the underlying directory that has been mounted over; -
Home directory
/ldap/bob
symbolic links will point to either/share/users/bob
(if mounted), or the local/storage
; -
An
inotifywait
watcher will start to monitorcreate
,delete
,modify
andattrib
events on/share
to continuously sync files with/storage
, throughout the session, withunison
.
Logout:
-
Home directory
/ldap/bob
is synchronized one last time; -
All homesync processes started by the current user session are killed (SIGTERM)
homesync -arg
-a Online: Sync roaming home with local home, and network share with local storage
Offline: Change symlinks to local storage
-d Setup local home directory structure
-h Show this help message and exit
-k Kill all homesync processes started by the current user session
-l Setup home directory symlinks according to mount status
-r Only sync network share with local storage
-s Only sync roaming home with the underlying directory
Name | Type | Description |
---|---|---|
DEBUG |
Boolean | If events should be logged in LOG_FILE . |
LOG_FILE |
String | Where DEBUG will log events. By default it's ~/.log/homesync.log . |
LDAP_URL |
String | Can be configured with an FQDN or IP address (e.g. ldap://domain.tld ). |
LDAP_DN |
String | Your domain's full distinguished name (e.g. dc=domain,dc=tld ). |
LDAP_BIND |
String | Optional user that will bind to the LDAP server (e.g. cn=username,dc=domain,dc=tld ). Can be set to false .Since LDAP_BIND_PW is stored in plaintext, it's recommended to create a read-only user. |
LDAP_BIND_PW |
String | Plaintext LDAP_BIND user password. |
LDAP_MACHINE_ATTRIBUTE |
String | Any field in your LDAP user entry where you can define its own primary computer hostname for local storage syncronization. By default it's inetOrgPerson homePostalAddress . |
BIND_PATH |
String | Location where / will be bind mounted on homesync -s (e.g. /mnt/bind ).This is used to sync the user's roaming home with the underlying directory which has been mounted over. |
UNISON_ARGS |
String | Space-separated list of options to use during syncs (e.g. -batch -silent -log=false -owner -group -prefer=newer ).For more options, refer to the unison repository. |
STORAGE_REMOTE |
String | Path of the mounted network share which contains your users' personal files (e.g. /share/users ). |
STORAGE_LOCAL |
String | Path of the local directory which contains the user's personal files (e.g. /storage ).This directory is synchronized with STORAGE_REMOTE only if the current machine that is running homesync is the user's primary computer defined in LDAP_MACHINE_ATTRIBUTE . |
STORAGE_LOCAL_NAME |
String | Name of the symbolic link that will be created in the user's home, and point to either STORAGE_REMOTE or STORAGE_LOCAL , depending on if the user is logged on with a roaming or local directory. |
STORAGE_DIRS_SYNC |
String | Space-separated list of directories to be synchronized between STORAGE_REMOTE and STORAGE_LOCAL , and symlinked in $HOME (e.g. Documents Images ). |
STORAGE_DIRS_NOSYNC |
String | Optional space-separated list of directories to be kept locally in STORAGE_LOCAL and symlinked in $HOME (e.g. Music Videos ).Can be set to false . |
HOME_LOCAL |
String | Local diretory path which will store users' machine-specific files and folders (e.g. /home/ldap ). |
HOME_DIRS |
String | Space-separated list of directories to be created locally in HOME_LOCAL and symlinked in $HOME with homesync -d (e.g. .cache .local Desktop ). |
HOME_FILES |
String | Space-separated list of files to be created locally in HOME_LOCAL and symlinked in $HOME with homesync -d (e.g. .viminfo file.txt ).The user's shell history dotfile is created automatically. |
-
Install dependencies:
sudo apt install inotify-tools ldap-utils unison
-
Download the script and its configuration file to their respective destination:
sudo wget https://raw.githubusercontent.com/RicardoJeronimo/homesync/master/homesync -O /usr/bin/homesync; sudo wget https://raw.githubusercontent.com/RicardoJeronimo/homesync/master/homesync.conf -O /etc/homesync.conf; sudo chmod +x /usr/bin/homesync
-
Allow your users to mount
BIND_PATH
without sudo on/etc/fstab
:/ /mnt/bind none bind,user,noauto 0 0
-
Setup
homesync
to run at logon (e.g. on.profile
):homesync -a
-
Setup
homesync
to run at logoff (e.g. on.bash_logout
):homesync -d && homesync -k