forked from heygrady/docker-wordpress-starterkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb-open.sh
123 lines (111 loc) · 3.01 KB
/
db-open.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/bash
# Thanks be to https://gist.github.com/helderco/e9d8d072a362ad818f6a, directly copped
set -e
show_help() {
cat << EOF
Usage: ${0##*/} [-u USER] [-p PASS] [-P PORT] [-H HOST] [DATABASE]
${0##*/} -h
Open a standard connection in Sequel PRO.
-h display this help and exit
-u USER database user (defaults to root)
-p PASS database password (defaults to root)
-P PORT database port (defaults to published port for 3306
in db service with docker-compose)
-H HOST database host (defaults to your docker-machine host)
DATABASE database name (defaults to none)
EOF
}
while getopts :u:p:P:H:h opt; do
case $opt in
u) DB_USER="$OPTARG"
;;
p) DB_PASS="$OPTARG"
;;
P) DB_PORT="$OPTARG"
;;
H) DB_HOST="$OPTARG"
;;
h)
show_help
exit 0
;;
\?)
show_help >&2
exit 1
;;
:)
show_help >&2
exit 1
;;
esac
done
shift "$((OPTIND-1))"
: ${DB_USER:=root}
: ${DB_PASS:=root}
: ${DB_PORT:=$(docker-compose port db 3306 | cut -d: -f2)}
: ${DB_HOST:=$(docker-machine ip $DOCKER_MACHINE_NAME)}
: ${DB_NAME:=$1}
TMP_SPF='/tmp/docker.spf'
cat > $TMP_SPF <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ContentFilters</key>
<dict/>
<key>auto_connect</key>
<true/>
<key>data</key>
<dict>
<key>connection</key>
<dict>
<key>database</key>
<string>${DB_NAME}</string>
<key>host</key>
<string>${DB_HOST}</string>
<key>name</key>
<string>docker.${DOCKER_MACHINE_NAME}</string>
<key>password</key>
<string>${DB_PASS}</string>
<key>port</key>
<integer>${DB_PORT}</integer>
<key>rdbms_type</key>
<string>mysql</string>
<key>sslCACertFileLocation</key>
<string></string>
<key>sslCACertFileLocationEnabled</key>
<integer>0</integer>
<key>sslCertificateFileLocation</key>
<string></string>
<key>sslCertificateFileLocationEnabled</key>
<integer>0</integer>
<key>sslKeyFileLocation</key>
<string></string>
<key>sslKeyFileLocationEnabled</key>
<integer>0</integer>
<key>type</key>
<string>SPTCPIPConnection</string>
<key>useSSL</key>
<integer>0</integer>
<key>user</key>
<string>${DB_USER}</string>
</dict>
</dict>
<key>encrypted</key>
<false/>
<key>format</key>
<string>connection</string>
<key>queryFavorites</key>
<array/>
<key>queryHistory</key>
<array/>
<key>rdbms_type</key>
<string>mysql</string>
<key>rdbms_version</key>
<string>5.5.44</string>
<key>version</key>
<integer>1</integer>
</dict>
</plist>
EOF
exec open $TMP_SPF