v_add_db_host 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/bin/bash
  2. # info: adding data base server
  3. #----------------------------------------------------------#
  4. # Variable&Function #
  5. #----------------------------------------------------------#
  6. # Argument defenition
  7. type=$1
  8. host=$2
  9. port=$3
  10. db_user=$4
  11. db_password=$5
  12. max_usr=${6-300}
  13. max_db=${7-300}
  14. template=${8-template1}
  15. # Importing variables
  16. source $VESTA/conf/vars.conf
  17. source $V_CONF/vesta.conf
  18. source $V_FUNC/shared.func
  19. source $V_FUNC/db.func
  20. #----------------------------------------------------------#
  21. # Verifications #
  22. #----------------------------------------------------------#
  23. # Checking arg number
  24. args_usage='type host port db_user db_password [max_usr] [max_db] [tpl]'
  25. check_args '5' "$#" "$args_usage"
  26. # Checking argument format
  27. format_validation 'host' 'port' 'db_user' 'db_password' 'max_usr' 'max_db'
  28. format_validation 'template'
  29. # Checking db system is enabled
  30. is_system_enabled 'db'
  31. # Checking db type
  32. is_type_valid 'db' "$type"
  33. # Checking host existance
  34. is_db_host_new
  35. # Checking host connection
  36. case $type in
  37. mysql) is_mysql_host_alive ;;
  38. pgsql) is_pgsql_host_alive ;;
  39. esac
  40. #----------------------------------------------------------#
  41. # Action #
  42. #----------------------------------------------------------#
  43. # Concatentating db host string
  44. case $type in
  45. mysql) new_str="HOST='$host' USER='$db_user' PASSWORD='$db_password'";
  46. new_str="$new_str PORT='$port' MAX_USERS='$max_usr'";
  47. new_str="$new_str MAX_DB='$max_db' U_SYS_USERS=''";
  48. new_str="$new_str U_DB_BASES='0' ACTIVE='yes' DATE='$V_DATE'";;
  49. pgsql) new_str="HOST='$host' USER='$db_user' PASSWORD='$db_password'";
  50. new_str="$new_str PORT='$port' TPL='$template'";
  51. new_str="$new_str MAX_USERS='$max_usr' MAX_DB='$max_db'";
  52. new_str="$new_str U_SYS_USERS=''";
  53. new_str="$new_str U_DB_BASES='0' ACTIVE='yes' DATE='$V_DATE'";;
  54. esac
  55. # Adding host to conf
  56. echo "$new_str" >> $V_DB/$type.conf
  57. chmod 650 $V_DB/$type.conf
  58. #----------------------------------------------------------#
  59. # Vesta #
  60. #----------------------------------------------------------#
  61. # Hidding db pass
  62. V_EVENT=$(echo $V_EVENT | sed -e "s/$db_password/xxxxxx/g")
  63. # Logging
  64. log_event 'system' "$V_EVENT"
  65. exit