mirror of
https://github.com/ThunixdotNet/makeuser.git
synced 2026-01-24 05:30:18 +00:00
Create DataBase management functions
This commit is contained in:
11
include/functions.DB
Normal file
11
include/functions.DB
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#Common functions used for Databases management scripts
|
||||||
|
|
||||||
|
create_database()
|
||||||
|
{
|
||||||
|
sudo mysql -u root << _EOF
|
||||||
|
CREATE DATABASE $DATABASE;
|
||||||
|
GRANT ALL PRIVILEGES ON $DATABASE.* TO '$USER'@'localhost' IDENTIFIED BY '$PASSWORD';
|
||||||
|
FLUSH PRIVILEGES;
|
||||||
|
_EOF
|
||||||
|
}
|
||||||
14
makedb
14
makedb
@@ -1,15 +1,15 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
USER=$1
|
|
||||||
PASSWORD=`pwgen -1B 24`
|
|
||||||
CONFIG=./setenv
|
CONFIG=./setenv
|
||||||
. $CONFIG
|
. $CONFIG
|
||||||
|
. include/functions.DB
|
||||||
|
|
||||||
sudo mysql -u root << _EOF
|
USER=$1
|
||||||
CREATE DATABASE $USER;
|
DATABASE=$1
|
||||||
GRANT ALL PRIVILEGES ON $USER.* TO '$USER'@'localhost' IDENTIFIED BY '$PASSWORD';
|
PASSWORD=`pwgen -1B 24`
|
||||||
FLUSH PRIVILEGES;
|
|
||||||
_EOF
|
#adding a new database
|
||||||
|
create_database
|
||||||
|
|
||||||
sed -e "s/_username_/$USER/g" -e "s/_password_/$PASSWORD/g" include/dbemail.tmpl | sudo mail -s "Your database has been provisioned" $USER@thunix.net
|
sed -e "s/_username_/$USER/g" -e "s/_password_/$PASSWORD/g" include/dbemail.tmpl | sudo mail -s "Your database has been provisioned" $USER@thunix.net
|
||||||
sed -e "s/_username_/$USER/g" -e "s/_password_/$PASSWORD/g" include/dbemail.tmpl | sudo mail -s "Your database has been provisioned" $ADMIN_EMAIL
|
sed -e "s/_username_/$USER/g" -e "s/_password_/$PASSWORD/g" include/dbemail.tmpl | sudo mail -s "Your database has been provisioned" $ADMIN_EMAIL
|
||||||
|
|||||||
Reference in New Issue
Block a user