| #!/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" |
| 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 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 |
| eval /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="" |
| 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 |
| ) |
| } |
| 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 |
| } |
| start_ofbiz() { |
| if [ -x "/etc/init.d/ofbiz" ]; then |
| if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then |
| invoke-rc.d ofbiz start || exit $? |
| else |
| /etc/init.d/ofbiz start || exit $? |
| fi |
| fi |
| } |
| stop_ofbiz() { |
| if [ -x "/etc/init.d/ofbiz" ]; then |
| if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then |
| invoke-rc.d ofbiz stop || exit $? |
| else |
| /etc/init.d/ofbiz stop || exit $? |
| fi |
| fi |
| } |
| |
| . /usr/share/debconf/confmodule |
| . /usr/share/dbconfig-common/dpkg/postinst |
| dbc_generate_include=sh:/etc/ofbiz/debconf.cfg |
| [ "$1" != "triggered" ] && 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_admin_port="" |
| fi |
| |
| if [ "$1" = "triggered" ]; then |
| for trigger in $2; do |
| case "$trigger" in |
| (ofbiz-start) |
| start_ofbiz |
| ;; |
| (ofbiz-install|ofbiz-upgrade) |
| ofbiz_reseed="" |
| if [ "$trigger" = "ofbiz-install" ]; then |
| ofbiz_reseed=1 |
| ofbiz_import_readers=1 |
| fi |
| get ofbiz_readers ofbiz/readers ofbiz_import_readers ofbiz_reseed |
| if [ "z" = "z$ofbiz_readers" ]; then |
| ofbiz_readers="seed" |
| else |
| ofbiz_readers="seed,$ofbiz_readers" |
| fi |
| ofbiz_readers="$(fix_readers "$ofbiz_readers")" |
| get ofbiz_admin_port ofbiz/admin-port |
| stop_ofbiz |
| if [ "z" != "z$ofbiz_reseed" ]; then |
| echo "Need to modify ofbiz data." 1>&2 |
| configure_ofbiz |
| fi |
| dpkg-trigger --no-await ofbiz-start |
| ;; |
| esac |
| done |
| db_stop |
| exit 0 |
| fi |
| |
| ofbiz_reseed="" |
| case "$1" in |
| (configure|reconfigure) |
| if [ "$2" ]; then |
| dpkg-trigger --no-await ofbiz-upgrade |
| else |
| dpkg-trigger --no-await ofbiz-install |
| 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 |
| dpkg-statoverride --update --add ofbiz ofbiz 755 /var/lib/ofbiz |
| fi |
| ;; |
| esac |
| #DEBHELPER# |
| db_stop |
| exit |
| |