+# Helper for LUA.
+# split string separated by space into quoted list
+#
+# Author: Elan Ruusamäe <glen@pld-linux.org>
+#
+# %__lua_split /bin/sh /bin/pdksh -> "/bin/sh", "/bin/pdksh"
+%__lua_split() %(echo "%*" | awk '{for (i=1;i<=NF;i++) printf("\\"%%s\\"%%s", $i, i == NF ? "" : ", ")}')
+
+# adjust /etc/shells by adding and removing shells from there
+# Author: Elan Ruusamäe <glen@pld-linux.org>
+#
+# Usage:
+# %post -p <lua>
+# %lua_add_etc_shells /bin/sh /bin/pdksh
+#
+# %preun -p <lua>
+# if arg[2] == 0 then
+# %lua_remove_etc_shells /bin/bash /bin/rbash
+# end
+#
+# Requirements:
+# BuildRequires: rpmbuild(macros) >= 1.462
+#
+
+%lua_add_etc_shells() \
+t = {}\
+f = io.open("/etc/shells", "r")\
+if f then\
+ for l in f:lines() do t[l]=l; end\
+ f:close()\
+end\
+for _, s in ipairs({%{expand:%%__lua_split %*}}) do\
+ if not t[s] then\
+ print("Adding "..s.." to /etc/shells")\
+ f = io.open("/etc/shells", "a"); f:write(s.."\\n"); f:close()\
+ end\
+end\
+%{nil}
+
+%lua_remove_etc_shells() \
+t = {}\
+f = io.open("/etc/shells", "r")\
+if f then\
+ for l in f:lines() do t[l]=l; end\
+ f:close()\
+end\
+for _, l in pairs({%{expand:%%__lua_split %*}}) do\
+ print("Removing "..l.." from /etc/shells")\
+ t[l] = nil\
+end\
+s=""\
+for _, l in pairs(t) do\
+ s=s..l.."\\n"\
+end\
+io.open("/etc/shells", "w"):write(s)\
+%{nil}
+
+# Backwards compat. Use of %lua_ prefixed macros is preferred as these are cleaner to read.
+#
+# Author: Elan Ruusamäe <glen@pld-linux.org>
+#
+# Usage:
+# %post -p %add_etc_shells -p /bin/sh /bin/pdksh
+# %preun -p %remove_etc_shells -p /bin/sh /bin/pdksh
+#
+# -p (optional) -- specifies that result is embeded %post script (prepends <lua> as first line)
+#
+# Requirements:
+# BuildRequires: rpmbuild(macros) >= 1.429
+#
+%add_etc_shells(p) %{-p:<lua>}\
+%{expand:%%lua_add_etc_shells %*}\
+%{nil}
+
+%remove_etc_shells(p) %{-p:<lua>}\
+%{-p:if arg[2] == 0 then}\
+%{expand:%%lua_remove_etc_shells %*}\
+%{-p:end} \
+%{nil}
+
+# Check syntax for Python files
+#
+# Author: Elan Ruusamäe <glen@pld-linux.org>
+# Author: Arkadiusz Miśkiewicz <arekm@pld-linux.org>
+#
+# Usage:
+# %py_lint src
+#
+# Requirements:
+# BuildRequires: python
+# BuildRequires: rpmbuild(macros) >= 1.469
+
+%py_lint() \
+__py_lint() { \
+find "$@" -type f -name '*.py' | python -c ' \
+import sys \
+import compiler \
+\
+err = 0\
+for f in sys.stdin: \
+ fd = open(f.strip()) \
+ c = fd.read() \
+ fd.close() \
+ try: \
+ compiler.parse(c) \
+ except SyntaxError, e: \
+ print "py_lint: %s: %s" % (f.strip(), e) \
+ err = err + 1\
+\
+if err: \
+ print >> sys.stderr, "\\npy_lint: ERROR: Syntax errors in %d files.\\n" % err \
+ sys.exit(1) \
+else: \
+ print >> sys.stderr, "py_lint: Found no syntax errors." \
+' \
+}; __py_lint %* \
+%{nil}
+