mirror of
https://github.com/serghey-rodin/vesta.git
synced 2024-12-03 19:00:24 -08:00
66 lines
1.7 KiB
Bash
Executable File
66 lines
1.7 KiB
Bash
Executable File
#!/bin/bash
|
|
# info: delete database
|
|
# options: USER DATABASE
|
|
#
|
|
# The function for deleting the database. If database user have access to
|
|
# another database, he will not be deleted.
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
# Variable&Function #
|
|
#----------------------------------------------------------#
|
|
|
|
# Argument definition
|
|
user=$1
|
|
database=$2
|
|
|
|
# Includes
|
|
source $VESTA/func/main.sh
|
|
source $VESTA/func/db.sh
|
|
source $VESTA/conf/vesta.conf
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
# Verifications #
|
|
#----------------------------------------------------------#
|
|
|
|
check_args '2' "$#" 'USER DATABASE'
|
|
is_format_valid 'user' 'database'
|
|
is_system_enabled "$DB_SYSTEM" 'DB_SYSTEM'
|
|
is_object_valid 'user' 'USER' "$user"
|
|
is_object_unsuspended 'user' 'USER' "$user"
|
|
is_object_valid 'db' 'DB' "$database"
|
|
is_object_unsuspended 'db' 'DB' "$database"
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
# Action #
|
|
#----------------------------------------------------------#
|
|
|
|
# Get database values
|
|
get_database_values
|
|
|
|
# Switching on db type
|
|
case $TYPE in
|
|
mysql) delete_mysql_database ;;
|
|
pgsql) delete_pgsql_database ;;
|
|
esac
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
# Vesta #
|
|
#----------------------------------------------------------#
|
|
|
|
# Deleting database
|
|
sed -i "/DB='$database' /d" $USER_DATA/db.conf
|
|
|
|
# Decreasing counters
|
|
decrease_dbhost_values
|
|
decrease_user_value "$user" '$U_DATABASES'
|
|
|
|
# Logging
|
|
log_history "deleted $database database"
|
|
log_event "$OK" "$ARGUMENTS"
|
|
|
|
exit
|