forked from ungleich-public/cdist
		
	Shorten option for both useradd and usermod.
We need to shorten options for both usermod and useradd since on some systems (such as *BSD, Darwin) those commands do not handle GNU style long options. Signed-off-by: Sébastien Gross <seb•ɑƬ•chezwam•ɖɵʈ•org>
This commit is contained in:
		
					parent
					
						
							
								f23e869277
							
						
					
				
			
			
				commit
				
					
						2a20b01a3f
					
				
			
		
					 1 changed files with 20 additions and 2 deletions
				
			
		|  | @ -24,6 +24,22 @@ | |||
| 
 | ||||
| name="$__object_id" | ||||
| 
 | ||||
| # We need to shorten options for both usermod and useradd since on some | ||||
| # systems (such as *BSD, Darwin) those commands do not handle GNU style long | ||||
| # options. | ||||
| shorten_property() { | ||||
|    RET= | ||||
|    case "$1" in | ||||
|        comment) RET="-c";; | ||||
|        home) RET="-d";; | ||||
|        gid) RET="-g";; | ||||
|        groups) RET="-G";; | ||||
|        password) RET="-p";; | ||||
|        shell) RET="-s";; | ||||
|        uid) RET="-u";; | ||||
|    esac | ||||
| } | ||||
| 
 | ||||
| cd "$__object/parameter" | ||||
| if grep -q "^${name}:" "$__object/explorer/passwd"; then | ||||
|    for property in $(ls .); do | ||||
|  | @ -67,7 +83,8 @@ if grep -q "^${name}:" "$__object/explorer/passwd"; then | |||
|       fi | ||||
| 
 | ||||
|       if [ "$new_value" != "$current_value" ]; then | ||||
|          set -- "$@" "--$property" \'$new_value\' | ||||
| 	  shorten_property $property | ||||
|           set -- "$@" "$RET" \'$new_value\' | ||||
|       fi | ||||
|    done | ||||
| 
 | ||||
|  | @ -79,7 +96,8 @@ if grep -q "^${name}:" "$__object/explorer/passwd"; then | |||
| else | ||||
|    for property in $(ls .); do | ||||
|       new_value="$(cat "$property")" | ||||
|       set -- "$@" "--$property" \'$new_value\' | ||||
|       shorten_property $property | ||||
|       set -- "$@" "$RET" \'$new_value\' | ||||
|    done | ||||
| 
 | ||||
|    echo useradd "$@" "$name" | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue