v-delete-database 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/bin/bash
  2. # info: delete database
  3. # options: USER DATABASE
  4. # labels:
  5. #
  6. # example: v-delete-database admin wp_db
  7. #
  8. # The function for deleting the database. If database user have access to
  9. # another database, he will not be deleted.
  10. #----------------------------------------------------------#
  11. # Variable&Function #
  12. #----------------------------------------------------------#
  13. # Argument definition
  14. user=$1
  15. database=$2
  16. # Includes
  17. # shellcheck source=/usr/local/hestia/func/main.sh
  18. source $HESTIA/func/main.sh
  19. # shellcheck source=/usr/local/hestia/func/db.sh
  20. source $HESTIA/func/db.sh
  21. # shellcheck source=/usr/local/hestia/conf/hestia.conf
  22. source $HESTIA/conf/hestia.conf
  23. #----------------------------------------------------------#
  24. # Verifications #
  25. #----------------------------------------------------------#
  26. check_args '2' "$#" 'USER DATABASE'
  27. is_format_valid 'user' 'database'
  28. is_system_enabled "$DB_SYSTEM" 'DB_SYSTEM'
  29. is_object_valid 'user' 'USER' "$user"
  30. is_object_valid 'db' 'DB' "$database"
  31. # Perform verification if read-only mode is enabled
  32. check_hestia_demo_mode
  33. #----------------------------------------------------------#
  34. # Action #
  35. #----------------------------------------------------------#
  36. # Get database values
  37. get_database_values
  38. # Issues with $SUSPENDED overwritten when delete_mysql_database is called
  39. suspended=$SUSPENDED
  40. # Switching on db type
  41. case $TYPE in
  42. mysql) delete_mysql_database ;;
  43. pgsql) delete_pgsql_database ;;
  44. esac
  45. #----------------------------------------------------------#
  46. # Hestia #
  47. #----------------------------------------------------------#
  48. # Deleting database
  49. sed -i "/DB='$database' /d" $USER_DATA/db.conf
  50. # Decreasing counters
  51. decrease_dbhost_values
  52. decrease_user_value "$user" '$U_DATABASES'
  53. # Check if is suspended to decrease the suspended value
  54. if [ ! -z "$suspended" ]; then
  55. if [ "$suspended" == "yes" ]; then
  56. decrease_user_value "$user" '$SUSPENDED_DB'
  57. fi
  58. fi
  59. # Logging
  60. log_history "deleted $database database"
  61. log_event "$OK" "$ARGUMENTS"
  62. exit