Files
ofbiz-framework/debian/ofbiz-framework.postinst
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

180 lines
4.4 KiB
Bash

#!/bin/sh
#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
: "$0" "$@"
JAVA_HOME=""
JAVA_HOMES="/usr/lib/jvm/java-6-openjdk"
OFBIZ_HOME="/usr/share/ofbiz"
for possible in $JAVA_HOMES; do
if [ -e "$possible/bin/java" ]; then
JAVA_HOME="$possible"
break
fi
done
if ! [ "$JAVA_HOME" ]; then
echo "Couldn't find a java."
echo "Tried $JAVA_HOMES"
exit 1
fi
JAVA="$JAVA_HOME/bin/java"
munge_conffile() {
tmp="$1"
source="$2"
case "$source" in
(framework/entity/config/entityengine.xml)
. /etc/dbconfig-common/ofbiz.conf
xalan \
-xsl "$OFBIZ_HOME/support/entityengine.xslt" \
-in "$OFBIZ_HOME/ucf/$source" \
-param dbtype "'$dbc_dbtype'" \
-param dbuser "'$dbc_dbuser'" \
-param dbpass "'$dbc_dbpass'" \
-param dbserver "'$dbc_dbserver'" \
-param dbport "'$dbc_dbport'" \
-param dbname "'$dbc_dbname'" > $tmp
;;
(*)
echo "Unknown file: $source"
exit 1
;;
esac
}
configure_ofbiz() {
extra="-readers=seed"
for file in "/var/lib/ofbiz/import/"*.xml; do
if [ -e "$file" ]; then
extra="$extra -file=\"$file\""
fi
done
eval /etc/init.d/ofbiz install $extra
rm -rf "/var/lib/ofbiz/import"
}
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
}
ofbiz_init_invoke() {
if [ -x "/etc/init.d/ofbiz" ]; then
if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
invoke-rc.d ofbiz $1 || exit $?
else
/etc/init.d/ofbiz $1 || exit $?
fi
fi
}
. /usr/share/debconf/confmodule
. /usr/share/dbconfig-common/dpkg/postinst
dbc_generate_include=sh:/etc/ofbiz/dbc-debconf.cfg
[ "$1" != "triggered" ] && dbc_go ofbiz "$@"
if [ -e /etc/ofbiz/dbc-debconf.cfg ]; then
ofbiz_admin_key=""
. /etc/ofbiz/dbc-debconf.cfg
else
ofbiz_admin_key="$(get_random_chars 32)"
ofbiz_readers=""
fi
if [ -r "/etc/ofbiz/debconf.cfg" ]; then
chown root:ofbiz "/etc/ofbiz/debconf.cfg"
eval `sed -n 's/^ofbiz\.admin\.\(port\|key\)=\(.*\)/ofbiz_admin_\1=\2;/p' "/etc/ofbiz/debconf.cfg" `
fi
if [ "$1" = "triggered" ]; then
run_seed=""
for trigger in $2; do
case "$trigger" in
(ofbiz-install)
run_seed=1
;;
esac
done
if [ "z" != "z$run_seed" ]; then
ofbiz_init_invoke stop
configure_ofbiz
dpkg-trigger --no-await ofbiz-start
fi
for trigger in $2; do
case "$trigger" in
(ofbiz-start)
ofbiz_init_invoke start
;;
esac
done
db_stop
exit 0
fi
case "$1" in
(configure|reconfigure)
ofbiz_init_invoke stop
dpkg-trigger --no-await ofbiz-install
if [ -z "$2" ]; then
db_input medium ofbiz/admin-user || true
get ofbiz_admin_user ofbiz/admin-user
if [ "z" = "z$ofbiz_admin_user" ]; then
ofbiz_admin_user="admin"
fi
mkdir -p "/var/lib/ofbiz/import/"
out="/var/lib/ofbiz/import/ofbiz-framework.xml"
sed "s/@userLoginId@/$ofbiz_admin_user/g" < "$OFBIZ_HOME/framework/resources/templates/AdminUserLoginData.xml" > "$out.new"
mv "$out.new" "$out"
if ! getent passwd ofbiz 2>/dev/null >/dev/null; then
adduser --quiet --group --no-create-home --system --shell /bin/sh --home /var/lib/ofbiz ofbiz
fi
if ! dpkg-statoverride --list "/var/lib/ofbiz" > /dev/null; then
dpkg-statoverride --update --add ofbiz ofbiz 755 /var/lib/ofbiz
fi
fi
;;
esac
#DEBHELPER#
db_stop
exit