v-update-user-quota 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/bin/bash
  2. # info: update user disk quota
  3. # options: USER
  4. #
  5. # The functions upates disk quota for specific user
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument definition
  10. user=$1
  11. # Includes
  12. source $VESTA/func/main.sh
  13. source $VESTA/conf/vesta.conf
  14. #----------------------------------------------------------#
  15. # Verifications #
  16. #----------------------------------------------------------#
  17. check_args '1' "$#" 'USER'
  18. is_format_valid 'user'
  19. is_object_valid 'user' 'USER' "$user"
  20. #----------------------------------------------------------#
  21. # Action #
  22. #----------------------------------------------------------#
  23. # Updating disk quota
  24. # Had quota equals package value. Soft quota equals 90% of package value for warnings.
  25. quota=$(get_user_value '$DISK_QUOTA')
  26. soft=$(echo "$quota * 1024 * 0.90"|bc |cut -f 1 -d .)
  27. hard=$(echo "$quota * 1024"|bc |cut -f 1 -d .)
  28. # Searching home mount point
  29. mnt=$(df -P /home |awk '{print $6}' |tail -n1)
  30. # Checking unlinmited quota
  31. if [ "$quota" = 'unlimited' ]; then
  32. setquota $user 0 0 0 0 $mnt 2>/dev/null
  33. else
  34. setquota $user $soft $hard 0 0 $mnt 2>/dev/null
  35. fi
  36. #----------------------------------------------------------#
  37. # Vesta #
  38. #----------------------------------------------------------#
  39. # Logging
  40. log_event "$OK" "$ARGUMENTS"
  41. exit