v_add_db_base 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/bin/bash
  2. # info: adding data base
  3. #----------------------------------------------------------#
  4. # Variable&Function #
  5. #----------------------------------------------------------#
  6. # Argument defenition
  7. user="$1"
  8. database="$user"_"$2"
  9. db_user="$user"_"$3"
  10. db_password="$4"
  11. type="$5"
  12. host=$6
  13. # Importing variables
  14. source $VESTA/conf/vars.conf
  15. source $V_FUNC/shared_func.sh
  16. source $V_FUNC/db_func.sh
  17. #----------------------------------------------------------#
  18. # Verifications #
  19. #----------------------------------------------------------#
  20. # Checking arg number
  21. check_args '5' "$#" 'user db db_user db_password type [host]'
  22. # Checking argument format
  23. format_validation 'user' 'database' 'db_user' 'db_password'
  24. # Checking db system is enabled
  25. is_system_enabled 'db'
  26. # Checking db type
  27. is_type_valid 'db' "$type"
  28. # Checking user
  29. is_user_valid
  30. # Checking user is active
  31. is_user_suspended
  32. # Checking db existance
  33. is_db_new
  34. # Checking db host
  35. if [ -z "$host" ]; then
  36. host=$(get_next_db_host)
  37. fi
  38. is_db_host_valid
  39. # Checking package
  40. is_package_full 'db_base'
  41. #----------------------------------------------------------#
  42. # Action #
  43. #----------------------------------------------------------#
  44. # Switching on db type
  45. case $type in
  46. mysql) create_db_mysql ;;
  47. pgsql) create_db_pgsql ;;
  48. esac
  49. #----------------------------------------------------------#
  50. # Vesta #
  51. #----------------------------------------------------------#
  52. # Increasing db value
  53. increase_db_value
  54. # Increasing domain value
  55. increase_user_value "$user" '$U_DATABASES'
  56. # Adding db to db conf
  57. v_str="DB='$database' USER='$db_user' HOST='$host' TYPE='$type'"
  58. v_str="$v_str U_DISK='0' SUSPEND='no' DATE='$V_DATE'"
  59. echo "$v_str">>$V_USERS/$user/db.conf
  60. # Hiding password
  61. V_EVENT=$(echo $V_EVENT | sed -e "s/$db_password/xxxxxx/g")
  62. # Logging
  63. log_history "$V_EVENT" "v_del_db_base $user $database"
  64. log_event 'system' "$V_EVENT"
  65. exit $OK