From 1518bf19353294c6b0b95e35f838b2a27a59daa3 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 15 Mar 2011 23:11:01 +0100 Subject: [PATCH] __user: only run commands if value has changed Signed-off-by: Steven Armstrong --- conf/type/__user/TODO | 1 - conf/type/__user/gencode | 28 +++++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/conf/type/__user/TODO b/conf/type/__user/TODO index 5c2eec7d..fa6aeee7 100644 --- a/conf/type/__user/TODO +++ b/conf/type/__user/TODO @@ -1,3 +1,2 @@ -- gencode: compair new value with existing one in $__object/explorer/passwd, only change if nessecary - delete users diff --git a/conf/type/__user/gencode b/conf/type/__user/gencode index 7445d6f8..ca31f7d3 100755 --- a/conf/type/__user/gencode +++ b/conf/type/__user/gencode @@ -33,12 +33,34 @@ else fi +get_current_value() { + local key="$1" + local index + case "$key" in + uid) index=3;; + gid) index=4;; + comment) index=5;; + home) index=6;; + shell) index=7;; + esac + cut -d':' -f $index "$__object/explorer/passwd" +} + + set -- "$@" cd "$__object/parameter" for property in $(ls .); do - # TODO: compair new value with existing one in $__object/explorer/passwd, only change if nessecary - set -- "$@" "--$property" "$(cat "$property")" + 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 -echo $command $@ $name + +if [ $# -gt 0 ]; then + # Update changed properties + echo $command $@ $name +fi