forked from CroissanceCommune/autonomie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tools
59 lines (57 loc) · 1.34 KB
/
Tools
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
#!/bin/bash
# Useful function used to manage databases installation
having_root_pwd() {
log "Have you got the root password"
if [ "x$BDD_ROOT_PWD" == "x" ]
then
echo "Missing the sql password for ${BDD_ROOT_USER}, please provide one and press [ENTER]:"
read BDD_ROOT_PWD
fi
}
mysql_set_db() {
DB=$1
FILENAME=$2
if [ "x$NOPASSWORD" == "x1" ]
then
mysql -u${BDD_ROOT_USER} $DB < $FILENAME
else
mysql -u${BDD_ROOT_USER} -p${BDD_ROOT_PWD} $DB < $FILENAME
fi
}
mysql_cmd() {
if [ "x$NOPASSWORD" == "x1" ]
then
echo "$@" | mysql -u${BDD_ROOT_USER}
else
having_root_pwd
echo "$@" | mysql -u${BDD_ROOT_USER} -p${BDD_ROOT_PWD}
fi
}
my_adddb() {
DB=$1
echo "Creating database : \"${DB}\""
mysql_cmd "CREATE DATABASE IF NOT EXISTS ${DB} character set utf8;"
}
my_adduser() {
UNAME=$@
echo "Creating mysql user : \"${UNAME}\""
# mysql_cmd "CREATE USER IF NOT EXISTS ${UNAME}@localhost;"
}
my_add() {
# my_add dbname dbuser dbpass
DB=$1
UNAME=$2
UPASS=$3
my_adddb $DB
my_adduser $UNAME
mysql_cmd "GRANT ALL PRIVILEGES ON ${DB}.* TO ${UNAME}@localhost IDENTIFIED BY '${UPASS}';"
mysql_cmd "FLUSH PRIVILEGES;"
}
mysql_filedump() {
DB=$1
FILENAME=$2
mysql_set_db ${DB} ${FILENAME}
}
log() {
echo $@
}