docs/manual/examples/gforce/index.md
A Layer 3 example that forces a directory tree to be read/writeable by a group.
-- This example regards more the handcraft of bash scripting than lsyncd. -- An alternative to this would be to load a Lua-Posix library and do the -- permission changes right within the onAction handlers.
fgroup = "staff"
command =
-- checks if the group is the one enforced and sets them if not
'[[
perm=stat -c %A ^sourcePathname
if test stat -c %G ^sourcePathname != ]]..fgroup..'[[; then
/bin/chgrp ]]..fgroup..'[[ ^sourcePathname || /bin/true;
fi
]] ..
-- checks if the group permissions are rw and sets them
'[[
if test expr match $perm "....rw" = 0; then
/bin/chmod g+rw ^sourcePathname || /bin/true;
fi
]] ..
-- and forces the executable bit for directories.
'[[
if test -d ^sourcePathname; then
if test expr match $perm "......x" -eq 0; then
/bin/chmod g+x ^^sourcePathname || /bin/true;
fi
fi
]]
startup = '[[# /bin/chgrp -R ]]..fgroup..'[[ ^source || /bin/true && /bin/chmod -R g+rw ^source || /bin/true && /usr/bin/find ^source -type d | xargs chmod g+x ]]
gforce = { maxProcesses = 99, delay = 1, onStartup = startup, onAttrib = command, onCreate = command, onModify = command, -- does nothing on moves, they won't change permissions onMove = true, }
sync{gforce, source="/path/to/share"} {% endhighlight %}