blob: 858f992b049204710b0b24815add9d4f53d5491d [file] [log] [blame]
#!/bin/bash
#Licensed to the Apache Software Foundation (ASF) under one
#or more contributor license agreements. See the NOTICE file
#distributed with this work for additional information
#regarding copyright ownership. The ASF licenses this file
#to you 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
db_title OFBiz
db_version 2.0
db_capb backup
#DEBHELPER#
if [ -f /usr/share/dbconfig-common/dpkg/config ]; then
dbc_dbuser="ofbiz"
dbc_dbname="ofbiz"
dbc_dbtype="pgsql"
dbc_dbtypes="pgsql, mysql, derby, hsql"
#dbc_authmethod_admin="ident"
dbc_authmethod_user="password"
. /usr/share/dbconfig-common/dpkg/config
dbc_go ofbiz $@
fi
if [ -r "/etc/ofbiz/dbc-debconf.cfg" ]; then
. "/etc/ofbiz/dbc-debconf.cfg"
fi
set_if() {
if [ "$2" ]; then
db_set "$1" "$2"
return 0
fi
return 1;
}
get_random_chars() {
(
LANG=C
LC_ALL=C
length="$1"
chars=""
while :; do
needed_length=$((${length} - ${#chars}))
chars="$chars$(dd if=/dev/urandom count="${needed_length}" bs=1 2>/dev/null | sed -n -e 's/[^[:alnum:]]//g;p;q')"
if [ "${#chars}" -ge "$length" ]; then
break
fi
done
echo $chars
)
}
get() {
var_name="$1"
debconf_name="$2"
shift 2
if db_get "$debconf_name"; then
if eval ! [ "\"\$$var_name\" = \"\$RET\"" ]; then
while [ $# -gt 0 ]; do
eval $1=1
shift
done
eval $var_name=\"\$RET\"
fi
else
echo "Couldn't fetch '$debconf_name' from debconf!"
exit 1
fi
}
if [ -r "/etc/ofbiz/debconf.cfg" ]; then
eval `sed -n 's/^ofbiz\.admin\.\(port\|key\)=\(.*\)/ofbiz_admin_\1=\2;/p' "/etc/ofbiz/debconf.cfg" `
fi
if [ "z" = "z$ofbiz_admin_port" ]; then
ofbiz_admin_port="10523"
fi
#env LANG=C LC_ALL=C sed -n -e 's/[^[:alnum:]]//g;p;q' < /dev/urandom | cut -b1-12
#db_set ofbiz/admin-password ofbiz || true
set_if ofbiz/admin-user "$ofbiz_admin_user" || true
set_if ofbiz/admin-port "$ofbiz_admin_port" || true
cmd="$1"
shift
version="$2"
shift || true
ofb_dc_admin_user() {
db_input high ofbiz/admin-user || true
}
ofb_dc_admin_port() {
db_input low ofbiz/admin-port || true
}
ofb_dc_get_dbcc() {
. /etc/dbconfig-common/ofbiz.conf
}
ofb_dc_postgresql_fieldtype() {
if [ "$dbc_dbtype" = "pgsql" ]; then
db_input low ofbiz/fieldtype/postgres || true
fi
}
declare -a ofb_dc_list
ofb_dc_list=(
ofb_dc_admin_user
ofb_dc_admin_port
# ofb_dc_get_dbcc
ofb_dc_postgresql_fieldtype
)
case "$cmd" in
(configure|reconfigure)
STATE=0
while :; do
[[ $STATE = -1 ]] && exit 10
[[ $STATE = ${#ofb_dc_list[*]} ]] && break
${ofb_dc_list[$STATE]}
if db_go; then
STATE=$(($STATE + 1))
else
STATE=$(($STATE - 1))
fi
done
;;
esac
get ofbiz_admin_port ofbiz/admin-port
db_stop
if [ "z" = "z$ofbiz_admin_port" ]; then
ofbiz_admin_port="10523"
fi
if [ "z" = "z$ofbiz_admin_key" ]; then
ofbiz_admin_key="$(get_random_chars 32)"
fi
if [ -e "/etc/ofbiz/debconf.cfg" ]; then
sed -i \
-e "s/^ofbiz.admin.port=\".*\"\$/ofbiz.admin.port=\"$ofbiz_admin_port\"/" \
-e "s/^ofbiz.admin.key=\".*\"\$/ofbiz.admin.key=\"$ofbiz_admin_key\"/" \
"/etc/ofbiz/debconf.cfg"
else
cat > "/etc/ofbiz/debconf.cfg.new" << _EOF_
ofbiz.admin.port=$ofbiz_admin_port
ofbiz.admin.key=$ofbiz_admin_key
_EOF_
chmod 640 "/etc/ofbiz/debconf.cfg.new"
mv "/etc/ofbiz/debconf.cfg.new" "/etc/ofbiz/debconf.cfg"
fi