Merge branch '__find_exec' into 'master'
new type: __find_exec See merge request ungleich-public/cdist-contrib!1
This commit is contained in:
commit
63ebe87897
6 changed files with 186 additions and 0 deletions
41
type/__find_exec/explorer/find
Executable file
41
type/__find_exec/explorer/find
Executable file
|
@ -0,0 +1,41 @@
|
||||||
|
#!/bin/sh -e
|
||||||
|
#
|
||||||
|
# 2020 Ander Punnar (ander-at-kvlt-dot-ee)
|
||||||
|
#
|
||||||
|
# This file is part of cdist.
|
||||||
|
#
|
||||||
|
# cdist is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# cdist is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
if [ -f "$__object/parameter/path" ]
|
||||||
|
then
|
||||||
|
path="$( cat "$__object/parameter/path" )"
|
||||||
|
else
|
||||||
|
path="/$__object_id"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -e "$path" ]
|
||||||
|
then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
set -- find "$path"
|
||||||
|
|
||||||
|
while read -r l
|
||||||
|
do
|
||||||
|
set -- "$@" "$l"
|
||||||
|
done \
|
||||||
|
< "$__object/parameter/exp"
|
||||||
|
|
||||||
|
eval "$@"
|
66
type/__find_exec/gencode-remote
Executable file
66
type/__find_exec/gencode-remote
Executable file
|
@ -0,0 +1,66 @@
|
||||||
|
#!/bin/sh -e
|
||||||
|
#
|
||||||
|
# 2020 Ander Punnar (ander-at-kvlt-dot-ee)
|
||||||
|
#
|
||||||
|
# This file is part of cdist.
|
||||||
|
#
|
||||||
|
# cdist is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# cdist is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
if [ ! -s "$__object/explorer/find" ]
|
||||||
|
then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f "$__object/parameter/exec" ] \
|
||||||
|
&& [ ! -f "$__object/parameter/execdir" ]
|
||||||
|
then
|
||||||
|
echo '-exec or -execdir must be used' >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f "$__object/parameter/path" ]
|
||||||
|
then
|
||||||
|
path="$( cat "$__object/parameter/path" )"
|
||||||
|
else
|
||||||
|
path="/$__object_id"
|
||||||
|
fi
|
||||||
|
|
||||||
|
set -- find "$path"
|
||||||
|
|
||||||
|
while read -r l
|
||||||
|
do
|
||||||
|
set -- "$@" "$l"
|
||||||
|
done \
|
||||||
|
< "$__object/parameter/exp"
|
||||||
|
|
||||||
|
for p in exec execdir
|
||||||
|
do
|
||||||
|
if [ -f "$__object/parameter/$p" ]
|
||||||
|
then
|
||||||
|
while read -r l
|
||||||
|
do
|
||||||
|
set -- "$@" "-$p $l"
|
||||||
|
echo "$p: $l" >> "$__messages_out"
|
||||||
|
done \
|
||||||
|
< "$__object/parameter/$p"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "$@"
|
||||||
|
|
||||||
|
if [ -f "$__object/parameter/onchange" ]
|
||||||
|
then
|
||||||
|
cat "$__object/parameter/onchange"
|
||||||
|
fi
|
74
type/__find_exec/man.rst
Normal file
74
type/__find_exec/man.rst
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
cdist-type__find_exec(7)
|
||||||
|
========================
|
||||||
|
|
||||||
|
NAME
|
||||||
|
----
|
||||||
|
cdist-type__find_exec - Find files and execute commands on them
|
||||||
|
|
||||||
|
|
||||||
|
DESCRIPTION
|
||||||
|
-----------
|
||||||
|
``find`` in explorer will only run with expressions given with ``--exp`` parameter.
|
||||||
|
|
||||||
|
Code will be generated only, if explorer produces output.
|
||||||
|
|
||||||
|
For code generation ``--exec`` and/or ``--execdir`` parameters are used.
|
||||||
|
|
||||||
|
Please see your OS ``find`` manpage for details.
|
||||||
|
|
||||||
|
|
||||||
|
REQUIRED MULTIPLE PARAMETERS
|
||||||
|
----------------------------
|
||||||
|
exp
|
||||||
|
Expression to add to ``find`` command after starting point.
|
||||||
|
DO NOT add ``-exec`` or ``-execdir`` here.
|
||||||
|
|
||||||
|
|
||||||
|
OPTIONAL MULTIPLE PARAMETERS
|
||||||
|
----------------------------
|
||||||
|
exec
|
||||||
|
See ``find`` manpage about ``-exec``.
|
||||||
|
|
||||||
|
execdir
|
||||||
|
See ``find`` manpage about ``-execdir``.
|
||||||
|
|
||||||
|
|
||||||
|
OPTIONAL PARAMETERS
|
||||||
|
-------------------
|
||||||
|
path
|
||||||
|
Use this path instead of object id.
|
||||||
|
|
||||||
|
onchange
|
||||||
|
The code to run if something happens.
|
||||||
|
|
||||||
|
|
||||||
|
EXAMPLES
|
||||||
|
--------
|
||||||
|
|
||||||
|
.. code-block:: sh
|
||||||
|
|
||||||
|
# find *.list files under /etc/apt/sources.list.d, delete them and update apt cache
|
||||||
|
__find_exec /etc/apt/sources.list.d \
|
||||||
|
--exp '-name "*.list"' \
|
||||||
|
--exec 'rm "{}" \;' \
|
||||||
|
--onchange 'apt-get update || true'
|
||||||
|
|
||||||
|
# find files with execute bit under /some/path and remove execute bit
|
||||||
|
__find_exec remove-exec-bit \
|
||||||
|
--path /some/path \
|
||||||
|
--exp '-type f' \
|
||||||
|
--exp '-perm /111' \
|
||||||
|
--exec 'chmod -x "{}" \;'
|
||||||
|
|
||||||
|
|
||||||
|
AUTHORS
|
||||||
|
-------
|
||||||
|
Ander Punnar <ander-at-kvlt-dot-ee>
|
||||||
|
|
||||||
|
|
||||||
|
COPYING
|
||||||
|
-------
|
||||||
|
Copyright \(C) 2020 Ander Punnar. You can redistribute it
|
||||||
|
and/or modify it under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of the
|
||||||
|
License, or (at your option) any later version.
|
2
type/__find_exec/parameter/optional
Normal file
2
type/__find_exec/parameter/optional
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
path
|
||||||
|
onchange
|
2
type/__find_exec/parameter/optional_multiple
Normal file
2
type/__find_exec/parameter/optional_multiple
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
exec
|
||||||
|
execdir
|
1
type/__find_exec/parameter/required_multiple
Normal file
1
type/__find_exec/parameter/required_multiple
Normal file
|
@ -0,0 +1 @@
|
||||||
|
exp
|
Loading…
Reference in a new issue