new type: __sed

This commit is contained in:
ander 2021-07-07 20:47:22 +03:00
parent 853e5cf7b4
commit 485283f2e5
No known key found for this signature in database
GPG key ID: 0A2971E562D618F3
6 changed files with 120 additions and 0 deletions

View file

@ -0,0 +1,22 @@
#!/bin/sh -e
if [ -f "$__object/parameter/file" ]
then
file="$( cat "$__object/parameter/file" )"
else
file="/$__object_id"
fi
if [ -f "$file" ]
then
if [ -s "$file" ]
then
cat "$file"
else
echo "$file is empty" >&2
exit 1
fi
else
echo "$file do not exist" >&2
exit 1
fi

View file

@ -0,0 +1,46 @@
#!/bin/sh -e
if [ -f "$__object/parameter/file" ]
then
file="$( cat "$__object/parameter/file" )"
else
file="/$__object_id"
fi
script="$( cat "$__object/parameter/script" )"
if [ "$script" = '-' ]
then
script="$( cat "$__object/stdin" )"
elif
[ -f "$script" ]
then
script="$( cat "$script" )"
fi
file_from_target="$__object/explorer/file"
sed_cmd='sed'
if [ -f "$__object/parameter/regexp-extended" ]
then
sed_cmd="$sed_cmd --regexp-extended"
fi
if ! echo "$script" \
| "$sed_cmd" -f - "$file_from_target" \
| diff "$file_from_target" - \
> /dev/null
then
echo 'tmp="$( mktemp )"'
echo "$sed_cmd -f - '$file' > \"\$tmp\" << EOF"
echo "$script"
echo 'EOF'
echo "cp \"\$tmp\" '$file'"
echo 'rm -f "$tmp"'
fi

View file

@ -0,0 +1,49 @@
cdist-type__sed(7)
==================
NAME
----
cdist-type__sed - Transform text files with ``sed``
DESCRIPTION
-----------
TODO
REQUIRED MULTIPLE PARAMETERS
----------------------------
script
TODO
OPTIONAL PARAMETERS
-------------------
file
TODO
BOOLEAN PARAMETERS
------------------
regexp-extended
TODO
EXAMPLES
--------
.. code-block:: sh
true
AUTHORS
-------
Ander Punnar <ander-at-kvlt-dot-ee>
COPYING
-------
Copyright \(C) 2021 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.

View file

@ -0,0 +1 @@
regexp-extended

View file

@ -0,0 +1 @@
file

View file

@ -0,0 +1 @@
script