-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmprov.sh
executable file
·50 lines (40 loc) · 1.23 KB
/
mprov.sh
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
#!/bin/bash
set -e
USER=$1
DATABASE=$2
PASSWORD=$3
FORCESSL=${4:-yes}
MARIADB_TAG=11.5
if [ -z "$USER" ]
then
echo "Error: Please pass the desired user as first paramter"
exit 1
fi
if [ -z "$DATABASE" ]
then
echo "Error:lease pass the desired database as second paramter"
exit 1
fi
if [ -z "$PASSWORD" ]
then
echo "Generating password (since not set as 3rd parameter)"
PASSWORD=`tr -cd '[:alnum:]' < /dev/urandom | fold -w40 | head -n1`
fi
source .env
NETWORK=docker-database-cluster_dbs
CMD="docker run --rm --link mariadb:$MYSQL_DOMAIN -e MYSQL_PWD="${MARIADB_ROOT_PASSWORD}" -it --network $NETWORK bitnami/mariadb:$MARIADB_TAG mariadb -h $MYSQL_DOMAIN -u root --ssl --ssl-verify-server-cert -e"
if [ "${FORCESSL}" = "yes" ]; then
echo "forcing ssl for user $USER"
REQUIRESSL=" REQUIRE SSL"
else
echo "ssl not enforced for user $USER"
REQUIRESSL=""
fi
$CMD "CREATE USER IF NOT EXISTS ${USER} IDENTIFIED BY '${PASSWORD}'${REQUIRESSL}"
$CMD "CREATE DATABASE IF NOT EXISTS ${DATABASE}"
$CMD "GRANT ALL PRIVILEGES ON ${DATABASE} . * TO ${USER}@'%'"
$CMD "FLUSH PRIVILEGES;"
echo "- Created user $USER"
echo "- Created database $DATABASE"
echo "- Your Password is: $PASSWORD"
echo "- Enforce sSL: $FORCESSL"