v-delete-database 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. # Includes
  14. source $VESTA/conf/vesta.conf
  15. source $VESTA/func/main.sh
  16. source $VESTA/func/db.sh
  17. #----------------------------------------------------------#
  18. # Verifications #
  19. #----------------------------------------------------------#
  20. check_args '2' "$#" 'USER DATABASE'
  21. validate_format 'user' 'database'
  22. is_system_enabled "$DB_SYSTEM"
  23. is_object_valid 'user' 'USER' "$user"
  24. is_object_unsuspended 'user' 'USER' "$user"
  25. is_object_valid 'db' 'DB' "$database"
  26. is_object_unsuspended 'db' 'DB' "$database"
  27. #----------------------------------------------------------#
  28. # Action #
  29. #----------------------------------------------------------#
  30. # Get database values
  31. get_database_values
  32. # Switching on db type
  33. case $TYPE in
  34. mysql) delete_mysql_database ;;
  35. pgsql) delete_pgsql_database ;;
  36. esac
  37. #----------------------------------------------------------#
  38. # Vesta #
  39. #----------------------------------------------------------#
  40. # Deleting database
  41. sed -i "/DB='$database' /d" $USER_DATA/db.conf
  42. # Decreasing counters
  43. decrease_dbhost_values
  44. decrease_user_value "$user" '$U_DATABASES'
  45. # Logging
  46. log_history "deleted $database database"
  47. log_event "$OK" "$EVENT"
  48. exit