forked from ungleich-public/cdist
		
	new type: __sed
This commit is contained in:
		
					parent
					
						
							
								853e5cf7b4
							
						
					
				
			
			
				commit
				
					
						485283f2e5
					
				
			
		
					 6 changed files with 120 additions and 0 deletions
				
			
		
							
								
								
									
										22
									
								
								cdist/conf/type/__sed/explorer/file
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										22
									
								
								cdist/conf/type/__sed/explorer/file
									
										
									
									
									
										Executable 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
 | 
			
		||||
							
								
								
									
										46
									
								
								cdist/conf/type/__sed/gencode-remote
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										46
									
								
								cdist/conf/type/__sed/gencode-remote
									
										
									
									
									
										Executable 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
 | 
			
		||||
							
								
								
									
										49
									
								
								cdist/conf/type/__sed/man.rst
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								cdist/conf/type/__sed/man.rst
									
										
									
									
									
										Normal 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.
 | 
			
		||||
							
								
								
									
										1
									
								
								cdist/conf/type/__sed/parameter/boolean
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								cdist/conf/type/__sed/parameter/boolean
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
regexp-extended
 | 
			
		||||
							
								
								
									
										1
									
								
								cdist/conf/type/__sed/parameter/optional
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								cdist/conf/type/__sed/parameter/optional
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
file
 | 
			
		||||
							
								
								
									
										1
									
								
								cdist/conf/type/__sed/parameter/required_multiple
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								cdist/conf/type/__sed/parameter/required_multiple
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
script
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue