remove parameter changing code in __key_value (fixes #114,#36)
Signed-off-by: Nico Schottelius <nico@brief.schottelius.org>
This commit is contained in:
		
					parent
					
						
							
								344e08ddda
							
						
					
				
			
			
				commit
				
					
						0eda57986f
					
				
			
		
					 2 changed files with 35 additions and 36 deletions
				
			
		| 
						 | 
					@ -1,6 +1,7 @@
 | 
				
			||||||
#!/bin/sh
 | 
					#!/bin/sh
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
 | 
					# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
 | 
				
			||||||
 | 
					# 2012 Nico Schottelius (nico-cdist at schottelius.org)
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
# This file is part of cdist.
 | 
					# This file is part of cdist.
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
| 
						 | 
					@ -18,42 +19,42 @@
 | 
				
			||||||
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
 | 
					# along with cdist. If not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
 | 
					
 | 
				
			||||||
key="$(cat "$__object/parameter/key")"
 | 
					key="$__object_id"
 | 
				
			||||||
 | 
					[ -f "$__object/parameter/key" ] && key="$(cat "$__object/parameter/key")"
 | 
				
			||||||
 | 
					state_should=present
 | 
				
			||||||
 | 
					[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
file="$(cat "$__object/parameter/file")"
 | 
					file="$(cat "$__object/parameter/file")"
 | 
				
			||||||
delimiter="$(cat "$__object/parameter/delimiter")"
 | 
					delimiter="$(cat "$__object/parameter/delimiter")"
 | 
				
			||||||
value="$(cat "$__object/parameter/value")"
 | 
					value="$(cat "$__object/parameter/value")"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
state_is="$(cat "$__object/explorer/state")"
 | 
					state_is="$(cat "$__object/explorer/state")"
 | 
				
			||||||
state_should="$(cat "$__object/parameter/state")"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
if [ "$state_is" = "$state_should" ]; then
 | 
					[ "$state_is" = "$state_should" ] && exit 0
 | 
				
			||||||
   # nothing to do
 | 
					 | 
				
			||||||
   exit 0
 | 
					 | 
				
			||||||
fi
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
case "$state_should" in
 | 
					case "$state_should" in
 | 
				
			||||||
   absent)
 | 
					    absent)
 | 
				
			||||||
      # remove lines starting with key
 | 
					        # remove lines starting with key
 | 
				
			||||||
      echo "sed '/^$key\($delimiter\+\)/d' \"$file\" > \"$file.cdist-tmp\""
 | 
					        echo "sed '/^$key\($delimiter\+\)/d' \"$file\" > \"$file.cdist-tmp\""
 | 
				
			||||||
      echo "mv \"$file.cdist-tmp\" \"$file\""
 | 
					        echo "mv \"$file.cdist-tmp\" \"$file\""
 | 
				
			||||||
   ;;
 | 
					    ;;
 | 
				
			||||||
   present)
 | 
					    present)
 | 
				
			||||||
      case "$state_is" in
 | 
					        case "$state_is" in
 | 
				
			||||||
         absent)
 | 
					            absent)
 | 
				
			||||||
            # add new key and value
 | 
					                # add new key and value
 | 
				
			||||||
            echo "echo \"${key}${delimiter}${value}\" >> \"$file\""
 | 
					                echo "echo \"${key}${delimiter}${value}\" >> \"$file\""
 | 
				
			||||||
         ;;
 | 
					            ;;
 | 
				
			||||||
         wrongvalue)
 | 
					            wrongvalue)
 | 
				
			||||||
            # change exisiting value
 | 
					                # change exisiting value
 | 
				
			||||||
            echo "sed \"s|^$key\($delimiter\+\).*|$key\1$value|\" \"$file\" > \"$file.cdist-tmp\""
 | 
					                echo "sed \"s|^$key\($delimiter\+\).*|$key\1$value|\" \"$file\" > \"$file.cdist-tmp\""
 | 
				
			||||||
            echo "mv \"$file.cdist-tmp\" \"$file\""
 | 
					                echo "mv \"$file.cdist-tmp\" \"$file\""
 | 
				
			||||||
         ;;
 | 
					            ;;
 | 
				
			||||||
         *)
 | 
					            *)
 | 
				
			||||||
            echo "Unknown explorer state: $state_is" >&2
 | 
					                echo "Unknown explorer state: $state_is" >&2
 | 
				
			||||||
            exit 1
 | 
					                exit 1
 | 
				
			||||||
      esac
 | 
					        esac
 | 
				
			||||||
   ;;
 | 
					    ;;
 | 
				
			||||||
   *)
 | 
					    *)
 | 
				
			||||||
      echo "Unknown state: $state_should" >&2
 | 
					       echo "Unknown state: $state_should" >&2
 | 
				
			||||||
      exit 1
 | 
					       exit 1
 | 
				
			||||||
esac 
 | 
					esac 
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,7 @@
 | 
				
			||||||
#!/bin/sh
 | 
					#!/bin/sh
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
 | 
					# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
 | 
				
			||||||
 | 
					# 2012 Nico Schottelius (nico-cdist at schottelius.org)
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
# This file is part of cdist.
 | 
					# This file is part of cdist.
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
| 
						 | 
					@ -18,13 +19,10 @@
 | 
				
			||||||
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
 | 
					# along with cdist. If not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# set defaults
 | 
					state_should=present
 | 
				
			||||||
key="$(cat "$__object/parameter/key" 2>/dev/null \
 | 
					[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")"
 | 
				
			||||||
   || echo "$__object_id" | tee "$__object/parameter/key")"
 | 
					 | 
				
			||||||
state="$(cat "$__object/parameter/state" 2>/dev/null \
 | 
					 | 
				
			||||||
   || echo "present" | tee "$__object/parameter/state")"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
if [ "$state" = "present" -a ! -f "$__object/parameter/value" ]; then
 | 
					if [ "$state_should" = "present" -a ! -f "$__object/parameter/value" ]; then
 | 
				
			||||||
   echo "Missing required parameter 'value'" >&2
 | 
					   echo "Missing required parameter 'value'" >&2
 | 
				
			||||||
   exit 1
 | 
					   exit 1
 | 
				
			||||||
fi 
 | 
					fi 
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue