lsyncd/examples/lgforce.lua

81 lines
2.2 KiB
Lua
Raw Normal View History

2010-11-16 12:03:33 +00:00
-----
-- User configuration file for lsyncd.
--
-- This example refers to one common challenge in multiuser unix systems.
--
2010-11-16 12:03:33 +00:00
-- You have a shared directory for a set of users and you want
-- to ensure all users have read and write permissions on all
-- files in there. Unfortunally sometimes users mess with their
2010-11-16 12:03:33 +00:00
-- umask, and create files in there that are not read/write/deleteable
-- by others. Usually this involves frequent handfixes by a sysadmin,
-- or a cron job that recursively chmods/chowns the whole directory.
--
-- This is another approach to use lsyncd to continously fix permissions.
--
-- One second after a file is created/modified it checks for its permissions
2010-11-16 12:03:33 +00:00
-- and forces group permissions on it.
--
2010-11-16 12:10:27 +00:00
-- 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
2010-11-16 12:03:33 +00:00
-- permission changes right within the onAction handlers.
2010-11-16 12:10:27 +00:00
----
-- forces this group.
--
fgroup = "staff"
2010-11-16 12:03:33 +00:00
2010-11-16 12:10:27 +00:00
-----
-- script for all changes.
--
command =
-- checks if the group is the one enforced and sets them if not
2010-11-16 12:03:33 +00:00
[[
perm=`stat -c %A ^sourcePathname`
if [ `stat -c %G ^sourcePathname` != ]]..fgroup..[[ ]; then
/bin/chgrp ]]..fgroup..[[ ^sourcePathname || /bin/true;
fi
2010-11-16 12:03:33 +00:00
]] ..
-- checks if the group permissions are rw and sets them
2010-11-16 12:03:33 +00:00
[[
if [ `expr match $perm "....rw"` == 0 ]; then
/bin/chmod g+rw ^sourcePathname || /bin/true;
fi
2010-11-16 12:03:33 +00:00
]] ..
-- and forces the executable bit for directories.
[[
if [ -d ^sourcePathname ]; then
if [ `expr match $perm "......x"` == 0 ]; then
2010-11-16 12:03:33 +00:00
/bin/chmod g+x ^^sourcePathname || /bin/true;
fi
fi
2010-11-16 12:03:33 +00:00
]]
-- on startup recursevily sets all group ownerships
2010-11-16 12:10:27 +00:00
-- all group permissions are set to rw
-- and to executable flag for directories
2010-11-16 12:03:33 +00:00
--
-- the carret as first char tells Lsycnd to call a shell altough it
-- starts with a slash otherwisw
--
startup =
[[^/bin/chgrp -R ]]..fgroup..[[ ^source || /bin/true &&
2010-11-16 12:03:33 +00:00
/bin/chmod -R g+rw ^source || /bin/true &&
/usr/bin/find ^source -type d | xargs chmod g+x
2010-11-16 12:03:33 +00:00
]]
gforce = {
maxProcesses = 99,
2010-11-16 12:10:27 +00:00
delay = 1,
onStartup = startup,
onAttrib = command,
onCreate = command,
onModify = command,
-- does nothing on moves, they won't change permissions
onMove = true,
2010-11-16 12:03:33 +00:00
}
sync{gforce, source="/path/to/share"}