-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathcouchdb.config
executable file
·139 lines (130 loc) · 3.91 KB
/
couchdb.config
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/sh
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
set -e
. /usr/share/debconf/confmodule
alias stripwhitespace="sed -e 's/^[[:blank:]]*//' -e 's/[[:blank:]]*$//'"
if [ -n "$DEBIAN_SCRIPT_DEBUG" ]; then set -v -x; DEBIAN_SCRIPT_TRACE=1; fi
${DEBIAN_SCRIPT_TRACE:+ echo "#42#DEBUG# RUNNING $0 $*" 1>&2 }
# prompt for password + confirmation until we get matching entries
# or an empty password
promptpass() {
while :; do
RET=""
db_input high couchdb/adminpass || true
db_go
db_get couchdb/adminpass
# if password isn't empty we ask for password verification
if [ -z "$RET" ]; then
break
fi
ADMIN_PW="$RET"
db_input high couchdb/adminpass_again || true
db_go
db_get couchdb/adminpass_again
if [ "$RET" = "$ADMIN_PW" ]; then
ADMIN_PW=''
break
fi
db_fset couchdb/adminpass_mismatch seen false
db_input critical couchdb/adminpass_mismatch
db_set couchdb/adminpass ""
db_set couchdb/adminpass_again ""
db_go
done
}
promptbind() {
while :; do
RET=""
db_input high couchdb/bindaddress || true
db_go
db_get couchdb/bindaddress
# don't allow whatever is passed in
if [ "$RET" != "$1" ]; then
break
fi
db_fset couchdb/bindaddress seen false
done
}
promptcookie() {
while :; do
RET=""
db_input high couchdb/cookie || true
db_go
db_get couchdb/cookie
if [ -z "$RET" ]; then
db_input critical couchdb/no_cookie
db_fset couchdb/cookie seen false
elif [ "$RET" = "monster" ]; then
db_input critical couchdb/no_cookie_monsters
db_fset couchdb/cookie seen false
else
break
fi
done
}
# if they exist, make current settings debconf's defaults
if [ -e /opt/couchdb/etc/vm.args ] ; then
cookie="$(grep '^-setcookie' /opt/couchdb/etc/vm.args | cut -d ' ' -f 2 | stripwhitespace)"
nodename="$(grep '^-name' /opt/couchdb/etc/vm.args | cut -d ' ' -f 2 | stripwhitespace)"
if [ -n "$cookie" ]; then
db_set couchdb/cookie "${cookie}"
fi
if [ "${nodename}" != "[email protected]" ]; then
db_set couchdb/nodename "${nodename}"
fi
fi
if [ -e /opt/couchdb/etc/local.ini ]; then
if grep -q '^bind_address =' /opt/couchdb/etc/local.ini; then
bindaddress="$(grep '^bind_address' /opt/couchdb/etc/local.ini | cut -d ' ' -f 3 | stripwhitespace)"
db_set couchdb/bindaddress "${bindaddress}"
fi
fi
# might be overridden by a local.d file
if [ -d /opt/couchdb/etc/local.d -a ls /opt/couchdb/etc/local.d/*.ini >/dev/null 2>&1 ]; then
for f in $(ls /opt/couchdb/etc/local.d/*.ini); do
if grep -q '^bind_address =' $f; then
bindaddress="$(grep '^bind_address' $f | cut -d ' ' -f 3 | stripwhitespace)"
db_set couchdb/bindaddress "${bindaddress}"
fi
done
fi
db_input high couchdb/mode || true
db_go
db_get couchdb/mode
case "$RET" in
none)
# Poor misguded one...
db_fset couchdb/nodename seen false
db_fset couchdb/cookie seen false
db_fset couchdb/adminpass seen false
db_fset couchdb/adminpass_again seen false
;;
standalone)
db_fset couchdb/nodename seen false
promptcookie
promptbind w.x.y.z
# still prompt for password
promptpass
;;
clustered)
if [ -z "$bindaddress" ]; then
db_set couchdb/bindaddress "0.0.0.0"
fi
db_input high couchdb/nodename || true
db_go
promptcookie
# do not allow binding to loopback in clustered mode
promptbind 127.0.0.1
promptpass
;;
esac