diff --git a/include/functions.DB b/include/functions.DB new file mode 100644 index 0000000..f146438 --- /dev/null +++ b/include/functions.DB @@ -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 +} diff --git a/makedb b/makedb index 7a97b55..2779f71 100755 --- a/makedb +++ b/makedb @@ -1,15 +1,15 @@ #!/bin/bash -USER=$1 -PASSWORD=`pwgen -1B 24` CONFIG=./setenv . $CONFIG +. include/functions.DB -sudo mysql -u root << _EOF -CREATE DATABASE $USER; -GRANT ALL PRIVILEGES ON $USER.* TO '$USER'@'localhost' IDENTIFIED BY '$PASSWORD'; -FLUSH PRIVILEGES; -_EOF +USER=$1 +DATABASE=$1 +PASSWORD=`pwgen -1B 24` + +#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" $ADMIN_EMAIL