1-----
2-- User configuration file for lsyncd.
3--
4-- This example refers to one common challenge in multiuser unix systems.
5--
6-- You have a shared directory for a set of users and you want
7-- to ensure all users have read and write permissions on all
8-- files in there. Unfortunally sometimes users mess with their
9-- umask, and create files in there that are not read/write/deleteable
10-- by others. Usually this involves frequent handfixes by a sysadmin,
11-- or a cron job that recursively chmods/chowns the whole directory.
12--
13-- This is another approach to use lsyncd to continously fix permissions.
14--
15-- One second after a file is created/modified it checks for its permissions
16-- and forces group permissions on it.
17--
18-- This example regards more the handcraft of bash scripting than lsyncd.
19-- An alternative to this would be to load a Lua-Posix library and do the
20-- permission changes right within the onAction handlers.
21
22----
23-- forces this group.
24--
25fgroup = "staff"
26
27-----
28-- script for all changes.
29--
30command =
31-- checks if the group is the one enforced and sets them if not
32[[
33perm=`stat -c %A ^sourcePathname`
34if [ `stat -c %G ^sourcePathname` != ]]..fgroup..[[ ]; then
35	/bin/chgrp ]]..fgroup..[[ ^sourcePathname || /bin/true;
36fi
37]] ..
38
39-- checks if the group permissions are rw and sets them
40[[
41if [ `expr match $perm "....rw"` == 0 ]; then
42	/bin/chmod g+rw ^sourcePathname || /bin/true;
43fi
44]] ..
45
46-- and forces the executable bit for directories.
47[[
48if [ -d ^sourcePathname ]; then
49	if [ `expr match $perm "......x"` == 0 ]; then
50		/bin/chmod g+x ^^sourcePathname || /bin/true;
51	fi
52fi
53]]
54
55-- on startup recursevily sets all group ownerships
56-- all group permissions are set to rw
57-- and to executable flag for directories
58--
59-- the carret as first char tells Lsycnd to call a shell altough it
60-- starts with a slash otherwisw
61--
62startup =
63[[^/bin/chgrp -R ]]..fgroup..[[ ^source || /bin/true &&
64/bin/chmod -R g+rw ^source || /bin/true &&
65/usr/bin/find ^source -type d | xargs chmod g+x
66]]
67
68gforce = {
69	maxProcesses = 99,
70	delay        = 1,
71	onStartup    = startup,
72	onAttrib     = command,
73	onCreate     = command,
74	onModify     = command,
75	-- does nothing on moves, they won't change permissions
76	onMove       = true,
77}
78
79sync{gforce, source="/path/to/share"}
80
81