-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathddb.sh
More file actions
executable file
·70 lines (60 loc) · 1.58 KB
/
ddb.sh
File metadata and controls
executable file
·70 lines (60 loc) · 1.58 KB
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
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
function mysql() {
docker run -d -p 3306:3306 \
-e MYSQL_ROOT_PASSWORD=${password} \
-e MYSQL_USER=${username} \
-e MYSQL_PASSWORD=${password} \
-e MYSQL_DATABASE=${schema} \
--name ${container} \
mysql
}
function psql() {
docker run -d -p 5432:5432 \
-e POSTGRES_USER=${username} \
-e POSTGRES_PASSWORD=${password} \
-e POSTGRES_DB=${schema} \
--name ${container} \
postgres
}
function redis() {
docker run -d -p 6379:6379 \
--name ${container} \
dockerfile/redis
}
function mongo() {
docker run -d -p 27017:27017 \
--name ${container} \
dockerfile/mongodb
}
function_exists() {
declare -f -F $1 > /dev/null
return $?
}
if [ $# -lt 1 ]
then
echo "Usage : $0 mysql|psql|redis|mongo "
exit
fi
if [ $1 = "mysql" ] || [ $1 = "psql" ]
then
read -p "Please enter db username [default: root]: " username
read -p "Please enter db password [default: password]: " password
read -p "Please enter db name [default: test]: " schema
fi
read -p "Please enter docker container name [default: ${1}]": container
username=${username:-root}
password=${password:-password}
schema=${schema:-test}
container=${container:-$1}
case "$1" in
mysql) function_exists mysql && mysql
;;
psql) function_exists psql && psql
;;
redis) function_exists redis && redis
;;
mongo) function_exists mongo && mongo
;;
*) echo "Invalid database"
;;
esac