-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdb.sh
executable file
·54 lines (54 loc) · 1.24 KB
/
db.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
#!/bin/bash
## db
## version 0.0.4 - template declare condition
##################################################
# requires sh2/aliases/commands
shopt -s expand_aliases
alias bind-variables='
{
local MYSQL_TEST_LOGIN_FILE
}
'
template-mysql-defaults-extra-file() { { local block_name ; block_name="${1}" ; }
cat << EOF
[${block_name}]
host = ${dbhost}
port = 3306
user = ${dbuser}
password = ${dbpasswd}
EOF
}
declare -f template &>/dev/null || {
template() {
commands
}
}
setup-db-defaults-extra-file() { { local block_name ; block_name="${1}" ; }
MYSQL_TEST_LOGIN_FILE=$( mktemp )
touch ${MYSQL_TEST_LOGIN_FILE}
chmod 600 ${_}
template-mysql-defaults-extra-file ${block_name} > ${MYSQL_TEST_LOGIN_FILE}
}
cleanup-db-defaults-extra-file() {
rm ${MYSQL_TEST_LOGIN_FILE}
}
db-mysql() {
_ mysql
}
db-mysqldump() {
_ mysqldump
}
db() {
_() {
bind-variables
setup-db-defaults-extra-file ${1}
command ${1} --defaults-extra-file=${MYSQL_TEST_LOGIN_FILE} ${dbname}
cleanup-db-defaults-extra-file
}
commands
}
##################################################
## generated by create-stub2.sh v0.1.2
## on Mon, 17 Feb 2020 10:22:29 +0900
## see <https://github.com/temptemp3/sh2>
##################################################