import corrected __group from nico/nico
Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
This commit is contained in:
		
					parent
					
						
							
								21aacd44b4
							
						
					
				
			
			
				commit
				
					
						18e433dd85
					
				
			
		
					 1 changed files with 22 additions and 23 deletions
				
			
		| 
						 | 
				
			
			@ -1,6 +1,7 @@
 | 
			
		|||
#!/bin/sh
 | 
			
		||||
#
 | 
			
		||||
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
 | 
			
		||||
# 2011 Nico Schottelius (nico-cdist at schottelius.org)
 | 
			
		||||
#
 | 
			
		||||
# This file is part of cdist.
 | 
			
		||||
#
 | 
			
		||||
| 
						 | 
				
			
			@ -23,16 +24,6 @@
 | 
			
		|||
 | 
			
		||||
name="$__object_id"
 | 
			
		||||
 | 
			
		||||
command=
 | 
			
		||||
if grep -q "^$name" "$__object/explorer/group"; then
 | 
			
		||||
   # group exists
 | 
			
		||||
   command="groupmod"
 | 
			
		||||
else
 | 
			
		||||
   # group does not exist
 | 
			
		||||
   command="groupadd"
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
get_current_value() {
 | 
			
		||||
   local key="$1"
 | 
			
		||||
   local index
 | 
			
		||||
| 
						 | 
				
			
			@ -46,21 +37,29 @@ get_current_value() {
 | 
			
		|||
   cut -d':' -f $index "$__object/explorer/group"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
set -- "$@"
 | 
			
		||||
cd "$__object/parameter"
 | 
			
		||||
for property in $(ls .); do
 | 
			
		||||
   current_value=$(get_current_value "$property")
 | 
			
		||||
   new_value="$(cat "$property")"
 | 
			
		||||
   if [ "$new_value" != "$current_value" ]; then
 | 
			
		||||
      # Shedule changed properties for update
 | 
			
		||||
      set -- "$@" "--$property" \"$new_value\"
 | 
			
		||||
 | 
			
		||||
if grep -q "^$name" "$__object/explorer/group"; then
 | 
			
		||||
   # group exists, only change changed values
 | 
			
		||||
   for property in $(ls .); do
 | 
			
		||||
      current_value=$(get_current_value "$property")
 | 
			
		||||
      new_value="$(cat "$property")"
 | 
			
		||||
      if [ "$new_value" != "$current_value" ]; then
 | 
			
		||||
         # Shedule changed properties for update
 | 
			
		||||
         set -- "$@" "--$property" \"$new_value\"
 | 
			
		||||
      fi
 | 
			
		||||
   done
 | 
			
		||||
 | 
			
		||||
   if [ $# -gt 0 ]; then
 | 
			
		||||
      # Update changed properties
 | 
			
		||||
      echo groupmod $@ $name
 | 
			
		||||
   fi
 | 
			
		||||
done
 | 
			
		||||
else
 | 
			
		||||
   for property in $(ls .); do
 | 
			
		||||
      new_value="$(cat "$property")"
 | 
			
		||||
      set -- "$@" "--$property" \"$new_value\"
 | 
			
		||||
   done
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if [ $# -gt 0 ]; then
 | 
			
		||||
   # Update changed properties
 | 
			
		||||
   echo $command $@ $name
 | 
			
		||||
   echo groupadd "$@" "$name"
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue