blob: 1ea13d58c052da8b84735eae6bce1d87571b29fe [file] [log] [blame]
#!/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-sun /usr/lib/j2sdk1.5"
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"
encrypt_password() {
(
cd /usr/share/ofbiz
"$JAVA" -classpath framework/base/build/lib/ofbiz-base.jar:framework/common/build/lib/ofbiz-common.jar:framework/base/config:framework/entity/build/lib/ofbiz-entity.jar:framework/base/lib/javolution.jar:framework/base/lib/commons/commons-collections.jar:framework/base/lib/jdbm.jar:framework/base/lib/log4j.jar:framework/security/config:support EncryptPassword "$1"
)
}
munge_conffile() {
tmp="$1"
source="$2"
case "$source" in
(framework/entity/config/entityengine.xml)
. /etc/dbconfig-common/ofbiz.conf
xalan \
-xsl "/usr/share/ofbiz/support/entityengine.xslt" \
-in "/usr/share/ofbiz/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=""
: ofbiz_readers "$ofbiz_readers"
: ofbiz_import_readers "$ofbiz_import_readers"
: ofbiz_override_data "$ofbiz_override_data"
if [ "$ofbiz_readers" ]; then
if [ "$ofbiz_import_readers" ]; then
extra="$extra -readers=\"$ofbiz_readers\""
fi
if [ "$ofbiz_override_data" ]; then
trap 'rm -f "$tempfile1" "$tempfile2"' EXIT
tempdir="$(mktemp -d)"
chown ofbiz:ofbiz "$tempdir"
trap 'rm -rf "$tempdir"' EXIT
files=""
{
IFS="," set -- $ofbiz_readers
while [ $# -gt 0 ]; do
if true; then
xalan -q \
-param reader "'$1'" \
-param fromemail "'$ofbiz_from_email'" \
-param password "'$ofbiz_password_encrypted'" \
-param ofbizhome "'/usr/share/ofbiz'" \
-xsl "/usr/share/ofbiz/support/override-data.xslt" \
-in "/usr/share/ofbiz/framework/base/config/component-load.xml" \
-out "$tempdir/reader-$1.xml"
chown ofbiz:ofbiz "$tempdir/reader-$1.xml"
fi
if [ "$files" ]; then
files="$files,$tempdir/reader-$1.xml"
else
files="$tempdir/reader-$1.xml"
fi
shift
done
}
trap '' EXIT
if [ "$files" ]; then
extra="$extra -file=\"$files\""
fi
fi
/etc/init.d/ofbiz install $extra
fi
#rm -f "$tempfile1" "$tempfile2"
}
fix_readers() {
IFS=", " set -- "$@"
while [ $# -gt 0 ]; do
echo -n "$1"
shift
if [ $# -gt 0 ]; then
echo ','
fi
done
}
get_random_chars() {
(
LANG=C
LC_ALL=C
length="$1"
chars=""
set -x
while :; do
needed_length=$((${length} - ${#chars}))
chars="$chars$(dd if=/dev/urandom count="${needed_length}" bs=1 | sed -n -e 's/[^[:alnum:]]//g;p;q')"
if [ "${#chars}" -ge "$length" ]; then
break
fi
done
echo $chars
set +x
)
}
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
}
. /usr/share/debconf/confmodule
. /usr/share/dbconfig-common/dpkg/postinst
dbc_go ofbiz "$@"
if [ -e /etc/ofbiz/debconf.cfg ]; then
ofbiz_admin_key=""
. /etc/ofbiz/debconf.cfg
else
ofbiz_admin_key="$(get_random_chars 32)"
ofbiz_readers=""
ofbiz_from_email=""
ofbiz_admin_port=""
fi
ofbiz_reseed=""
set -x
case "$1" in
(configure|reconfigure)
get ofbiz_readers ofbiz/readers ofbiz_import_readers ofbiz_reseed
ofbiz_readers="$(fix_readers "$ofbiz_readers")"
get ofbiz_from_email ofbiz/from-email ofbiz_override_data ofbiz_reseed
get ofbiz_admin_port ofbiz/admin-port
if ! [ "$2" ]; then
if ! getent passwd ofbiz 2>/dev/null >/dev/null; then
adduser --quiet --group --no-create-home --system --home /var/lib/ofbiz ofbiz
fi
fi
update-alternatives --install \
/usr/share/ofbiz/alternative \
ofbiz-alternative \
/usr/share/ofbiz/dist \
1000
cat << _EOF_ > /etc/ofbiz/debconf.cfg.dpkg-new
ofbiz_readers='$ofbiz_readers'
ofbiz_from_email='$ofbiz_from_email'
ofbiz_admin_port='$ofbiz_admin_port'
ofbiz_admin_key='$ofbiz_admin_key'
_EOF_
ucf /etc/ofbiz/debconf.cfg.dpkg-new /etc/ofbiz/debconf.cfg
ucfr ofbiz /etc/ofbiz/debconf.cfg
rm /etc/ofbiz/debconf.cfg.dpkg-new
;;
esac
#DEBHELPER#
exit