blob: 3ea45d4c717e2471273aa0e18878cc03b8724dda [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/debconf.cfg" ]; then
. "/etc/ofbiz/debconf.cfg"
fi
set_if() {
if [ "$2" ]; then
db_set "$1" "$2"
return 0
fi
return 1;
}
ofbiz_admin_port="10523"
#env LANG=C LC_ALL=C sed -n -e 's/[^[:alnum:]]//g;p;q' < /dev/urandom | cut -b1-12
if set_if ofbiz/admin-password-encrypted "$ofbiz_admin_password_encrypted"; then
db_fset ofbiz/admin-password-encrypted seen true
fi
#db_set ofbiz/admin-password ofbiz || true
set_if ofbiz/admin-port "$ofbiz_admin_port" || true
cmd="$1"
shift
case "$cmd" in
(configure)
import_question=ofbiz/readers
;;
(reconfigure)
import_question=ofbiz/reimport-data
;;
(*)
echo "Invalid command($cmd)" 1>&2
exit 9
;;
esac
seen_admin_password_prompt="false"
db_fget ofbiz/admin-password seen && seen_admin_password_prompt="$RET"
ofb_dc_admin_password() {
db_input medium ofbiz/admin-password || true
}
ofb_dc_admin_password_check() {
password=""
db_get ofbiz/admin-password && password="$RET"
if [ "z" = "z$password" ]; then
if [ "$seen_admin_password_prompt" = "false" ]; then
db_set ofbiz/admin-password "ofbiz"
db_set ofbiz/password-confirmation "ofbiz"
password="ofbiz"
else
db_input high ofbiz/empty-password-not-allowed || true
NEXT=0
fi
else
seen_admin_password_prompt="true"
fi
}
ofb_dc_admin_password_confirm() {
if [ "$seen_admin_password_prompt" = "true" ]; then
db_input high ofbiz/password-confirmation || true
fi
}
ofb_dc_admin_password_compare() {
confirm=""
db_get ofbiz/password-confirmation && confirm="$RET"
if [ "$password" != "$confirm" ]; then
db_input high ofbiz/mismatched-passwords || true
NEXT=0
db_set ofbiz/admin-password ''
db_fset ofbiz/admin-password seen false
fi
}
ofb_dc_import_question() {
db_input low $import_question || true
}
ofb_dc_readers() {
db_get $import_question && do_import="$RET"
if [ "$do_import" = "true" ]; then
db_input medium ofbiz/readers || true
fi
}
ofb_dc_admin_port() {
db_input low ofbiz/admin-port || true
}
declare -a ofb_dc_list
ofb_dc_list=(
ofb_dc_admin_password
ofb_dc_admin_password_check
ofb_dc_admin_password_confirm
ofb_dc_admin_password_compare
ofb_dc_import_question
ofb_dc_readers
ofb_dc_admin_port
)
case "$cmd" in
(configure|reconfigure)
STATE=0
while :; do
[[ $STATE = -1 ]] && exit 10
[[ $STATE = ${#ofb_dc_list[*]} ]] && break
NEXT=$(($STATE + 1))
${ofb_dc_list[$STATE]}
if db_go; then
STATE=$NEXT
else
STATE=$(($STATE - 1))
fi
done
;;
esac
db_stop