blob: 7eb301de5bf8d0326565715dbbca3eaa3d662a53 [file] [log] [blame]
#!/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
}
# 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 [ "${cookie}" != "monster" ]; then
db_set couchdb/cookie "${cookie}"
fi
if [ "${nodename}" != "couchdb@127.0.0.1" ]; 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
db_fset couchdb/cookie seen false
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
db_input high couchdb/cookie || true
db_go
# do not allow binding to loopback in clustered mode
promptbind 127.0.0.1
promptpass
;;
esac