forked from ungleich-public/cdist
		
	[__line] Ensure the line is only added once
This commit is contained in:
		
					parent
					
						
							
								3258fc98e1
							
						
					
				
			
			
				commit
				
					
						93ec4b46aa
					
				
			
		
					 2 changed files with 14 additions and 11 deletions
				
			
		| 
						 | 
				
			
			@ -18,6 +18,17 @@
 | 
			
		|||
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
if [ -f "$__object/parameter/file" ]; then
 | 
			
		||||
   file="$(cat "$__object/parameter/file")"
 | 
			
		||||
else
 | 
			
		||||
   file="/$__object_id"
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
if [ ! -f "$file" ]; then
 | 
			
		||||
  echo "file_missing"
 | 
			
		||||
  exit 0
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
if [ -f "$__object/parameter/before" ]; then
 | 
			
		||||
   position="before"
 | 
			
		||||
elif [ -f "$__object/parameter/after" ]; then
 | 
			
		||||
| 
						 | 
				
			
			@ -33,17 +44,6 @@ else
 | 
			
		|||
   needle="line"
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
if [ -f "$__object/parameter/file" ]; then
 | 
			
		||||
   file="$(cat "$__object/parameter/file")"
 | 
			
		||||
else
 | 
			
		||||
   file="/$__object_id"
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
if [ ! -f "$file" ]; then
 | 
			
		||||
  echo "file_missing"
 | 
			
		||||
  exit 0
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
awk -v position="$position" -v needle="$needle" '
 | 
			
		||||
function _find(_text, _pattern) {
 | 
			
		||||
   if (needle == "regex") {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,7 @@
 | 
			
		|||
#!/bin/sh -e
 | 
			
		||||
#
 | 
			
		||||
# 2018 Steven Armstrong (steven-cdist at armstrong.cc)
 | 
			
		||||
# 2020 Dennis Camera (dennis.camera at ssrq-sds-fds.ch)
 | 
			
		||||
#
 | 
			
		||||
# This file is part of cdist.
 | 
			
		||||
#
 | 
			
		||||
| 
						 | 
				
			
			@ -104,10 +105,12 @@ BEGIN {
 | 
			
		|||
      if (anchor && match(\$0, anchor)) {
 | 
			
		||||
         if (position == "before") {
 | 
			
		||||
            print line
 | 
			
		||||
            add = 0
 | 
			
		||||
            print
 | 
			
		||||
         } else if (position == "after") {
 | 
			
		||||
            print
 | 
			
		||||
            print line
 | 
			
		||||
            add = 0
 | 
			
		||||
         }
 | 
			
		||||
         next
 | 
			
		||||
      }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue