Files
ofbiz-framework/debian/ofbiz-framework.config
T
Adam Heath 46a201affd The admin port, and admin key, are now saved in a config file, and
no longer passed on the ofbiz command line.  Additionally, the port
can be changed during install.  Plus, the admin key is randomized to
something different, if it isn't already set during an install or an
upgrade.

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@766249 13f79535-47bb-0310-9956-ffa450edef68
2009-04-18 06:39:34 +00:00

125 lines
3.1 KiB
Bash

#!/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
)
}
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
ofb_dc_admin_user() {
db_input high ofbiz/admin-user || true
}
ofb_dc_admin_port() {
db_input low ofbiz/admin-port || true
}
declare -a ofb_dc_list
ofb_dc_list=(
ofb_dc_admin_user
ofb_dc_admin_port
)
cmd="$1"
shift
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
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