v-delete-user-notification 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/bin/bash
  2. # info: delete user notification
  3. # options: USER NOTIFICATION
  4. #
  5. # The function deletes user notification.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument definition
  10. user=$1
  11. nid=$2
  12. # Includes
  13. source $VESTA/func/main.sh
  14. source $VESTA/conf/vesta.conf
  15. #----------------------------------------------------------#
  16. # Verifications #
  17. #----------------------------------------------------------#
  18. check_args '2' "$#" 'USER NOTIFICATION'
  19. is_format_valid 'user' 'nid'
  20. is_object_valid 'user' 'USER' "$user"
  21. #----------------------------------------------------------#
  22. # Action #
  23. #----------------------------------------------------------#
  24. # Deleting notification
  25. sed -i "/NID='$nid' /d" $USER_DATA/notifications.conf 2>/dev/null
  26. # Checking last notification
  27. if [ -e "$USER_DATA/notifications.conf" ]; then
  28. if [ -z "$(grep NID= $USER_DATA/notifications.conf)" ]; then
  29. notice='no'
  30. fi
  31. if [ -z "$(grep "ACK='no'" $USER_DATA/notifications.conf)" ]; then
  32. notice='no'
  33. fi
  34. else
  35. notice='no'
  36. fi
  37. #----------------------------------------------------------#
  38. # Vesta #
  39. #----------------------------------------------------------#
  40. # Updating notification counter
  41. if [ "$notice" = 'no' ]; then
  42. if [ -z "$(grep NOTIFICATIONS $USER_DATA/user.conf)" ]; then
  43. sed -i "s/^TIME/NOTIFICATIONS='no'\nTIME/g" $USER_DATA/user.conf
  44. else
  45. update_user_value "$user" '$NOTIFICATIONS' "no"
  46. fi
  47. fi
  48. # Logging
  49. log_event "$OK" "$ARGUMENTS"
  50. exit