v_delete_db_base 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/bin/bash
  2. # info: delete database
  3. # options: user database
  4. #
  5. # The function for deleting the database. If database user have access to
  6. # another database, he will not be deleted.
  7. #----------------------------------------------------------#
  8. # Variable&Function #
  9. #----------------------------------------------------------#
  10. # Argument defenition
  11. user=$1
  12. database=$2
  13. # Importing variables
  14. source $VESTA/conf/vars.conf
  15. source $V_CONF/vesta.conf
  16. source $V_FUNC/shared.func
  17. source $V_FUNC/db.func
  18. #----------------------------------------------------------#
  19. # Verifications #
  20. #----------------------------------------------------------#
  21. # Checking arg number
  22. check_args '2' "$#" 'user db_name'
  23. # Checking argument format
  24. format_validation 'user' 'database'
  25. # Checking db system is enabled
  26. is_system_enabled 'db'
  27. # Checking user
  28. is_user_valid
  29. # Checking user is active
  30. is_user_suspended
  31. # Checking db existance
  32. is_db_valid
  33. # Checking db is active
  34. is_db_suspended
  35. #----------------------------------------------------------#
  36. # Action #
  37. #----------------------------------------------------------#
  38. # Get some variables we do not have now
  39. db_user=$(get_db_value '$USER')
  40. host=$(get_db_value '$HOST')
  41. type=$(get_db_value '$TYPE')
  42. # Switching on db type
  43. case $type in
  44. mysql) del_db_mysql ;;
  45. pgsql) del_db_pgsql ;;
  46. esac
  47. #----------------------------------------------------------#
  48. # Vesta #
  49. #----------------------------------------------------------#
  50. # Decreasing db value
  51. decrease_db_value
  52. # Decreasing domain value
  53. decrease_user_value "$user" '$U_DATABASES'
  54. # Deleting vesta db record
  55. del_db_vesta
  56. # Logging
  57. log_event 'system' "$V_EVENT"
  58. exit