inproved -1counter function

This commit is contained in:
Serghey Rodin 2012-02-16 17:28:19 +02:00
commit 64def78645

View file

@ -730,29 +730,22 @@ is_type_valid() {
decrease_user_value() { decrease_user_value() {
USER="$1" USER="$1"
key="$2" key="${2//$}"
conf="$V_USERS/$USER/user.conf"
# Deleting $
key=$(echo "${key//$/}")
# Parsing current value # Parsing current value
current_value=$(grep "$key=" $conf |cut -f 2 -d \') conf="$V_USERS/$USER/user.conf"
old=$(grep "$key=" $conf | cut -f 2 -d \')
# Checking result if [ -z "$old" ]; then
if [ -z "$current_value" ]; then old=0
echo "Error: Parsing error"
log_event 'debug' "$E_PARSING $V_EVENT"
exit $E_PARSING
fi fi
# Checking zero val # Decreasing
if [ "$current_value" -gt 0 ]; then if [ "$old" -le 1 ]; then
# Minus one new=0
new_value=$(expr $current_value - 1 ) else
# Changing config new=$((old - 1 ))
sed -i "s/$key='$current_value'/$key='$new_value'/g" $conf
fi fi
sed -i "s/$key='$old'/$key='$new'/g" $conf
} }