forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv_add_db_base
More file actions
executable file
·102 lines (76 loc) · 2.69 KB
/
v_add_db_base
File metadata and controls
executable file
·102 lines (76 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/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}
# 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 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"
# Logging
log_history "$V_EVENT" "v_delete_db_base $user $database"
log_event 'system' "$V_EVENT"
exit