diff --git a/cdist/conf/type/__sed/explorer/file b/cdist/conf/type/__sed/explorer/file new file mode 100755 index 00000000..a40f71b3 --- /dev/null +++ b/cdist/conf/type/__sed/explorer/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 diff --git a/cdist/conf/type/__sed/gencode-remote b/cdist/conf/type/__sed/gencode-remote new file mode 100755 index 00000000..391e3bc1 --- /dev/null +++ b/cdist/conf/type/__sed/gencode-remote @@ -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 diff --git a/cdist/conf/type/__sed/man.rst b/cdist/conf/type/__sed/man.rst new file mode 100644 index 00000000..fbac212d --- /dev/null +++ b/cdist/conf/type/__sed/man.rst @@ -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 + + +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. diff --git a/cdist/conf/type/__sed/parameter/boolean b/cdist/conf/type/__sed/parameter/boolean new file mode 100644 index 00000000..1ad75c5d --- /dev/null +++ b/cdist/conf/type/__sed/parameter/boolean @@ -0,0 +1 @@ +regexp-extended diff --git a/cdist/conf/type/__sed/parameter/optional b/cdist/conf/type/__sed/parameter/optional new file mode 100644 index 00000000..f73f3093 --- /dev/null +++ b/cdist/conf/type/__sed/parameter/optional @@ -0,0 +1 @@ +file diff --git a/cdist/conf/type/__sed/parameter/required_multiple b/cdist/conf/type/__sed/parameter/required_multiple new file mode 100644 index 00000000..84f7e31d --- /dev/null +++ b/cdist/conf/type/__sed/parameter/required_multiple @@ -0,0 +1 @@ +script