v_add_db_base 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. encoding=${7-UTF8}
  14. # Importing variables
  15. source $VESTA/conf/vars.conf
  16. source $V_CONF/vesta.conf
  17. source $V_FUNC/shared.func
  18. source $V_FUNC/db.func
  19. #----------------------------------------------------------#
  20. # Verifications #
  21. #----------------------------------------------------------#
  22. # Checking arg number
  23. check_args '5' "$#" 'user db db_user db_password type [host] [encoding]'
  24. # Checking argument format
  25. format_validation 'user' 'database' 'db_user' 'db_password' 'encoding'
  26. # Checking db system is enabled
  27. is_system_enabled 'db'
  28. # Checking db type
  29. is_type_valid 'db' "$type"
  30. # Checking user
  31. is_user_valid
  32. # Checking user is active
  33. is_user_suspended
  34. # Checking db existance
  35. is_db_new
  36. # Checking db host
  37. if [ -z "$host" ]; then
  38. host=$(get_next_db_host)
  39. fi
  40. is_db_host_valid
  41. # Checking package
  42. is_package_full 'db_base'
  43. #----------------------------------------------------------#
  44. # Action #
  45. #----------------------------------------------------------#
  46. # Switching on db type
  47. case $type in
  48. mysql) create_db_mysql ;;
  49. pgsql) create_db_pgsql ;;
  50. esac
  51. #----------------------------------------------------------#
  52. # Vesta #
  53. #----------------------------------------------------------#
  54. # Increasing db value
  55. increase_db_value
  56. # Increasing domain value
  57. increase_user_value "$user" '$U_DATABASES'
  58. # Adding db to db conf
  59. v_str="DB='$database' USER='$db_user' HOST='$host' TYPE='$type'"
  60. v_str="$v_str U_DISK='0' SUSPEND='no' DATE='$V_DATE'"
  61. echo "$v_str">>$V_USERS/$user/db.conf
  62. # Hiding password
  63. V_EVENT="$V_DATE $V_SCRIPT $user $database $db_user ***** $type $host"
  64. # Logging
  65. log_history "$V_EVENT" "v_del_db_base $user $database"
  66. log_event 'system' "$V_EVENT"
  67. exit