mirror of
https://github.com/serghey-rodin/vesta.git
synced 2025-08-14 18:49:17 -07:00
inproved -1counter function
This commit is contained in:
parent
6894bb2b27
commit
64def78645
1 changed files with 11 additions and 18 deletions
|
@ -730,29 +730,22 @@ is_type_valid() {
|
|||
|
||||
decrease_user_value() {
|
||||
USER="$1"
|
||||
key="$2"
|
||||
conf="$V_USERS/$USER/user.conf"
|
||||
|
||||
# Deleting $
|
||||
key=$(echo "${key//$/}")
|
||||
key="${2//$}"
|
||||
|
||||
# Parsing current value
|
||||
current_value=$(grep "$key=" $conf |cut -f 2 -d \')
|
||||
|
||||
# Checking result
|
||||
if [ -z "$current_value" ]; then
|
||||
echo "Error: Parsing error"
|
||||
log_event 'debug' "$E_PARSING $V_EVENT"
|
||||
exit $E_PARSING
|
||||
conf="$V_USERS/$USER/user.conf"
|
||||
old=$(grep "$key=" $conf | cut -f 2 -d \')
|
||||
if [ -z "$old" ]; then
|
||||
old=0
|
||||
fi
|
||||
|
||||
# Checking zero val
|
||||
if [ "$current_value" -gt 0 ]; then
|
||||
# Minus one
|
||||
new_value=$(expr $current_value - 1 )
|
||||
# Changing config
|
||||
sed -i "s/$key='$current_value'/$key='$new_value'/g" $conf
|
||||
# Decreasing
|
||||
if [ "$old" -le 1 ]; then
|
||||
new=0
|
||||
else
|
||||
new=$((old - 1 ))
|
||||
fi
|
||||
sed -i "s/$key='$old'/$key='$new'/g" $conf
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue