__user: remove =~, cleanup and beautify, replace cut with awk
Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
This commit is contained in:
parent
674e1f58f8
commit
4b76d8a7e0
1 changed files with 43 additions and 53 deletions
|
@ -23,60 +23,50 @@
|
||||||
|
|
||||||
name="$__object_id"
|
name="$__object_id"
|
||||||
|
|
||||||
command=
|
cd "$__object/parameter"
|
||||||
if grep -q "^$name" "$__object/explorer/passwd"; then
|
if grep -q "^${name}:" "$__object/explorer/passwd"; then
|
||||||
# user exists
|
for property in $(ls .); do
|
||||||
command="usermod"
|
new_value="$(cat "$property")"
|
||||||
else
|
|
||||||
# user does not exist
|
|
||||||
command="useradd"
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
file="$__object/explorer/passwd"
|
||||||
|
|
||||||
get_current_value() {
|
|
||||||
local key="$1"
|
|
||||||
local new_value="$2"
|
|
||||||
|
|
||||||
local explorer="$__object/explorer/passwd"
|
|
||||||
local index
|
|
||||||
case "$key" in
|
case "$key" in
|
||||||
password)
|
password)
|
||||||
explorer="$__object/explorer/shadow"
|
field=3
|
||||||
index=2
|
file="$__object/explorer/shadow"
|
||||||
;;
|
;;
|
||||||
uid) index=3;;
|
|
||||||
gid)
|
gid)
|
||||||
if [[ $new_value =~ ^[0-9]+$ ]]; then
|
if $(echo "$new_value" | grep -q '^[0-9][0-9]*$'); then
|
||||||
# numeric gid
|
field=4
|
||||||
index=4
|
|
||||||
else
|
else
|
||||||
# group name
|
# group name
|
||||||
explorer="$__object/explorer/group"
|
file="$__object/explorer/group"
|
||||||
index=1
|
field=1
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
comment) index=5;;
|
uid) field=3 ;;
|
||||||
home) index=6;;
|
comment) field=5 ;;
|
||||||
shell) index=7;;
|
home) field=6 ;;
|
||||||
|
shell) field=7 ;;
|
||||||
esac
|
esac
|
||||||
cut -d':' -f $index "$explorer"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
current_value="$(awk -F: '{ print $ENVIRON["field"] }' < "$file")"
|
||||||
|
|
||||||
set -- "$@"
|
|
||||||
cd "$__object/parameter"
|
|
||||||
for property in $(ls .); do
|
|
||||||
new_value="$(cat "$property")"
|
|
||||||
current_value=$(get_current_value "$property" "$new_value")
|
|
||||||
if [ "$new_value" != "$current_value" ]; then
|
if [ "$new_value" != "$current_value" ]; then
|
||||||
# Shedule changed properties for update
|
# Shedule changed properties for update
|
||||||
set -- "$@" "--$property" \"$new_value\"
|
set -- "$@" "--$property" \"$new_value\"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if [ $# -gt 0 ]; then
|
||||||
if [ $# -gt 0 ]; then
|
|
||||||
# Update changed properties
|
# Update changed properties
|
||||||
echo $command $@ $name
|
echo usermod "$@" "$name"
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
for property in $(ls .); do
|
||||||
|
new_value="$(cat "$property")"
|
||||||
|
set -- "$@" "--$property" \"$new_value\"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo useradd "$@" "$name"
|
||||||
|
fi
|
||||||
|
|
Loading…
Reference in a new issue