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_FUNC/shared_func.sh
  17. source $V_FUNC/db_func.sh
  18. #----------------------------------------------------------#
  19. # Verifications #
  20. #----------------------------------------------------------#
  21. # Checking arg number
  22. check_args '5' "$#" 'user db db_user db_password type [host] [encoding]'
  23. # Checking argument format
  24. format_validation 'user' 'database' 'db_user' 'db_password' 'encoding'
  25. # Checking db system is enabled
  26. is_system_enabled 'db'
  27. # Checking db type
  28. is_type_valid 'db' "$type"
  29. # Checking user
  30. is_user_valid
  31. # Checking user is active
  32. is_user_suspended
  33. # Checking db existance
  34. is_db_new
  35. # Checking db host
  36. if [ -z "$host" ]; then
  37. host=$(get_next_db_host)
  38. fi
  39. is_db_host_valid
  40. # Checking package
  41. is_package_full 'db_base'
  42. #----------------------------------------------------------#
  43. # Action #
  44. #----------------------------------------------------------#
  45. # Switching on db type
  46. case $type in
  47. mysql) create_db_mysql ;;
  48. pgsql) create_db_pgsql ;;
  49. esac
  50. #----------------------------------------------------------#
  51. # Vesta #
  52. #----------------------------------------------------------#
  53. # Increasing db value
  54. increase_db_value
  55. # Increasing domain value
  56. increase_user_value "$user" '$U_DATABASES'
  57. # Adding db to db conf
  58. v_str="DB='$database' USER='$db_user' HOST='$host' TYPE='$type'"
  59. v_str="$v_str U_DISK='0' SUSPEND='no' DATE='$V_DATE'"
  60. echo "$v_str">>$V_USERS/$user/db.conf
  61. # Hiding password
  62. dt="$(date +%m-%d-%y" "%H:%m:%S)"
  63. V_EVENT="$dt $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 $OK