fix for changing a user's group by name

This commit is contained in:
Matt Coddington 2012-02-07 10:27:28 -05:00
parent 229c4f6c37
commit 4d845b3fea

View file

@ -28,6 +28,7 @@ cd "$__object/parameter"
if grep -q "^${name}:" "$__object/explorer/passwd"; then if grep -q "^${name}:" "$__object/explorer/passwd"; then
for property in $(ls .); do for property in $(ls .); do
new_value="$(cat "$property")" new_value="$(cat "$property")"
unset current_value
file="$__object/explorer/passwd" file="$__object/explorer/passwd"
@ -36,9 +37,15 @@ if grep -q "^${name}:" "$__object/explorer/passwd"; then
if $(echo "$new_value" | grep -q '^[0-9][0-9]*$'); then if $(echo "$new_value" | grep -q '^[0-9][0-9]*$'); then
field=4 field=4
else else
# group name # we were passed a group name. compare to current gid and
file="$__object/explorer/group" # set $current_value to $oldgid if it needs changing.
field=1 newgid=$(awk -F: '{ print $3 }' "$__object/explorer/group")
oldgid=$(awk -F: '{ print $4 }' "$file")
if [ "$newgid" != "$oldgid" ]; then
current_value="$oldgid"
else
current_value=$new_value
fi
fi fi
;; ;;
password) password)
@ -51,8 +58,10 @@ if grep -q "^${name}:" "$__object/explorer/passwd"; then
uid) field=3 ;; uid) field=3 ;;
esac esac
if [ -z "$current_value" ]; then
export field export field
current_value="$(awk -F: '{ print $ENVIRON["field"] }' < "$file")" current_value="$(awk -F: '{ print $ENVIRON["field"] }' < "$file")"
fi
if [ "$new_value" != "$current_value" ]; then if [ "$new_value" != "$current_value" ]; then
set -- "$@" "--$property" \'$new_value\' set -- "$@" "--$property" \'$new_value\'