#!/bin/bash # info: add database # options: user db db_user db_password type [host] [encoding] # # The function creates the database concatenating username and user_db. # Supported yypes of databases you can get using v_list_sys_config script. # If the host isn't stated and there are few hosts configured on the server, # then the host will be defined by one of three algorithms. "First" will choose # the first host in the list. "Random" will chose the host by a chance. # "Weight" will distribute new database through hosts evenly. Algorithm and # types of supported databases is designated in the main configuration file. #----------------------------------------------------------# # Variable&Function # #----------------------------------------------------------# # Argument defenition user=$1 database="$user"_"$2" db_user="$user"_"$3" db_password=$4 type=$5 host=$6 encoding=${7-UTF8} encoding=$(echo "$encoding" |tr '[:lower:]' '[:upper:]') # Importing variables source $VESTA/conf/vars.conf source $V_CONF/vesta.conf source $V_FUNC/shared.func source $V_FUNC/db.func #----------------------------------------------------------# # Verifications # #----------------------------------------------------------# # Checking arg number check_args '5' "$#" 'user db db_user db_password type [host] [encoding]' # Checking argument format format_validation 'user' 'database' 'db_user' 'db_password' 'encoding' # Checking db system is enabled is_system_enabled 'db' # Checking db type is_type_valid 'db' "$type" # Checking user is_user_valid # Checking user is active is_user_suspended # Checking db existance is_db_new # Checking db host if [ -z "$host" ]; then host=$(get_next_db_host) fi is_db_host_valid # Checking package is_package_full 'db_base' #----------------------------------------------------------# # Action # #----------------------------------------------------------# # Switching on db type case $type in mysql) create_db_mysql ;; pgsql) create_db_pgsql ;; esac #----------------------------------------------------------# # Vesta # #----------------------------------------------------------# # Increasing db value increase_db_value # Increasing domain value increase_user_value "$user" '$U_DATABASES' # Adding db to db conf v_str="DB='$database' USER='$db_user' HOST='$host' TYPE='$type'" v_str="$v_str CHARSET='$encoding' U_DISK='0' SUSPEND='no' DATE='$V_DATE'" echo "$v_str">>$V_USERS/$user/db.conf # Hiding password V_EVENT="$V_DATE $V_SCRIPT $user $database $db_user ***** $type $host" V_EVENT="$V_EVENT $encoding" # Logging log_history "$V_EVENT" "v_delete_db_base $user $database" log_event 'system' "$V_EVENT" exit