#!/bin/bash
#
#
#   OPEN-XCHANGE legal information
#
#   All intellectual property rights in the Software are protected by
#   international copyright laws.
#
#
#   In some countries OX, OX Open-Xchange, open xchange and OXtender
#   as well as the corresponding Logos OX Open-Xchange and OX are registered
#   trademarks of the Open-Xchange, Inc. group of companies.
#   The use of the Logos is not covered by the GNU General Public License.
#   Instead, you are allowed to use these Logos according to the terms and
#   conditions of the Creative Commons License, Version 2.5, Attribution,
#   Non-commercial, ShareAlike, and the interpretation of the term
#   Non-commercial applicable to the aforementioned license is published
#   on the web site http://www.open-xchange.com/EN/legal/index.html.
#
#   Please make sure that third-party modules and libraries are used
#   according to their respective licenses.
#
#   Any modifications to this package must retain all copyright notices
#   of the original copyright holder(s) for the original code used.
#
#   After any such modifications, the original and derivative code shall remain
#   under the copyright of the copyright holder(s) and/or original author(s)per
#   the Attribution and Assignment Agreement that can be located at
#   http://www.open-xchange.com/EN/developer/. The contributing author shall be
#   given Attribution for the derivative code and a license granting use.
#
#    Copyright (C) 2004-2012 Open-Xchange, Inc.
#    Mail: info@open-xchange.com
#
#
#    This program is free software; you can redistribute it and/or modify it
#    under the terms of the GNU General Public License, Version 2 as published
#    by the Free Software Foundation.
#
#    This program is distributed in the hope that it will be useful, but
#    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
#    or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
#    for more details.
#
#    You should have received a copy of the GNU General Public License along
#    with this program; if not, write to the Free Software Foundation, Inc., 59
#    Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#


OXFUNCTIONS=/opt/open-xchange/lib/oxfunctions.sh
OXCONFIG=/opt/open-xchange/etc/ox-scriptconf.sh

test -f $OXFUNCTIONS || {
    echo "missing common shell functions file"
    exit 1
}

. $OXFUNCTIONS

test -f $OXCONFIG && . $OXCONFIG

ox_set_JAVA_BIN

JAVAMAIN="com.openexchange.admin.user.copy.console.UserCopy"

test -z "$JAVA_OXCMD_OPTS" && JAVA_OXCMD_OPTS="-Xmx280M"

JAVA_OPTS="${JAVA_OXCMD_OPTS} \
-Djava.awt.headless=true \
-Dopenexchange.propdir=$PROPERTIESDIR"

CLASSPATH="-classpath /opt/open-xchange/bundles/com.openexchange.common/lib/jakarta-slide-webdavlib-2.1.jar:/opt/open-xchange/bundles/com.openexchange.common/lib/concurrentlinkedhashmap-lru-1.3.2.jar:/opt/open-xchange/bundles/com.openexchange.common/lib/automaton-1.11-8.jar:/opt/open-xchange/bundles/com.openexchange.xerces.sun/lib/serializer-2.7.1.jar:/opt/open-xchange/bundles/com.openexchange.common/lib/high-scale-lib-1.1.4.jar:/opt/open-xchange/bundles/com.openexchange.common/lib/rabin-hash-function-2.0.jar:/opt/open-xchange/bundles/com.openexchange.common/lib/httpmime-4.2.1.jar:/opt/open-xchange/bundles/javax.mail/lib/libidn-1.9.jar:/opt/open-xchange/bundles/org.apache.commons.io_2.0.1.v201105210651.jar:/opt/open-xchange/bundles/com.openexchange.admin.console.common/lib/opencsv-2.0.jar:/opt/open-xchange/bundles/com.openexchange.system.extension.jar:/opt/open-xchange/bundles/com.openexchange.admin.rmi.jar:/opt/open-xchange/bundles/com.openexchange.common/lib/httpcore-4.2.1.jar:/opt/open-xchange/bundles/com.openexchange.xerces.sun/lib/xml-apis-1.3.04.jar:/opt/open-xchange/bundles/org.eclipse.osgi_3.9.1.v20140110-1610.jar:/opt/open-xchange/bundles/com.openexchange.common/lib/httpclient-4.2.1.jar:/opt/open-xchange/bundles/com.openexchange.common/lib/jericho-html-3.3.jar:/opt/open-xchange/bundles/com.openexchange.net.jar:/opt/open-xchange/bundles/org.apache.tika/org.apache.tika.jar:/opt/open-xchange/bundles/com.openexchange.common/lib/concurrentlinkedhashmap-1.0.1-custom.jar:/opt/open-xchange/bundles/com.openexchange.common/lib/apache-mime4j-dom-0.7.2.jar:/opt/open-xchange/bundles/org.apache.commons.lang_2.6.0.v201205030909.jar:/opt/open-xchange/bundles/com.openexchange.common/lib/apache-mime4j-core-0.7.2.jar:/opt/open-xchange/bundles/com.openexchange.common/lib/fluent-hc-4.2.1.jar:/opt/open-xchange/bundles/com.openexchange.common/lib/commons-compress-1.3.jar:/opt/open-xchange/bundles/com.openexchange.common/lib/ical4j-1.0.6.jar:/opt/open-xchange/bundles/com.openexchange.common/lib/commons-httpclient-3.1.jar:/opt/open-xchange/bundles/com.openexchange.common/com.openexchange.common.jar:/opt/open-xchange/bundles/org.apache.commons.net_3.2.0.v201305141515.jar:/opt/open-xchange/bundles/javax.servlet_2.5.0.v201103041518.jar:/opt/open-xchange/bundles/org.json.jar:/opt/open-xchange/bundles/jcl-over-slf4j-1.7.5.jar:/opt/open-xchange/bundles/com.openexchange.common/lib/scribe-java-1.3.7.jar:/opt/open-xchange/bundles/org.apache.tika/lib/tika-app-1.4.jar:/opt/open-xchange/bundles/com.openexchange.common/lib/httpcore-ab-4.2.1.jar:/opt/open-xchange/bundles/slf4j-api-1.7.5.jar:/opt/open-xchange/bundles/org.apache.commons.codec_1.6.0.v201305230611.jar:/opt/open-xchange/bundles/com.openexchange.common/lib/apache-mime4j-examples-0.7.2.jar:/opt/open-xchange/bundles/com.openexchange.common/lib/commons-collections-3.2.1.jar:/opt/open-xchange/bundles/com.openexchange.common/lib/jdo2-api-2.3-eb.jar:/opt/open-xchange/bundles/logback-classic-1.0.13.jar:/opt/open-xchange/bundles/com.openexchange.common/lib/owasp-esapi-2.0.1.jar:/opt/open-xchange/bundles/commons-cli-1.2.jar:/opt/open-xchange/bundles/org.w3c.css.sac_1.3.1.v200903091627.jar:/opt/open-xchange/bundles/javax.mail/lib/EmailAddress.jar:/opt/open-xchange/bundles/com.openexchange.common/lib/commons-fileupload-1.3.1.jar:/opt/open-xchange/bundles/com.openexchange.common/lib/jsoup-1.8.1.jar:/opt/open-xchange/bundles/com.openexchange.common/lib/trove-3.0.3.jar:/opt/open-xchange/bundles/javax.mail/lib/tnef-1.8.0.jar:/opt/open-xchange/bundles/com.openexchange.common/lib/chardet-1.1.jar:/opt/open-xchange/bundles/com.openexchange.common/lib/nekohtml-1.9.18.jar:/opt/open-xchange/bundles/com.openexchange.common/lib/jsr305.jar:/opt/open-xchange/bundles/com.openexchange.common/lib/htmlcleaner-2.9.jar:/opt/open-xchange/bundles/com.openexchange.common/lib/mysql-connector-java-5.1.30-bin.jar:/opt/open-xchange/bundles/com.openexchange.common/lib/backport-util-concurrent-3.1.jar:/opt/open-xchange/bundles/com.openexchange.common/lib/brownies-collections-0.9.6.jar:/opt/open-xchange/bundles/javax.mail/javax.mail.jar:/opt/open-xchange/bundles/com.openexchange.admin.user.copy.rmi.jar:/opt/open-xchange/bundles/com.openexchange.common/lib/httpcore-nio-4.2.1.jar:/opt/open-xchange/bundles/com.openexchange.xerces.sun/lib/xerces.jar:/opt/open-xchange/bundles/com.openexchange.common/lib/cssparser-0.9.7.jar:/opt/open-xchange/bundles/log4j-over-slf4j-1.7.5.jar:/opt/open-xchange/bundles/com.openexchange.admin.console.common/com.openexchange.admin.console.common.jar:/opt/open-xchange/bundles/com.openexchange.common/lib/apache-mime4j-storage-0.7.2.jar:/opt/open-xchange/bundles/com.openexchange.common/lib/libidn-1.9.jar:/opt/open-xchange/bundles/logback-core-1.0.13.jar:/opt/open-xchange/bundles/com.openexchange.common/lib/gnu-rex.jar:/opt/open-xchange/bundles/com.openexchange.java.jar:/opt/open-xchange/bundles/com.openexchange.common/lib/jboss-jms-api.jar:/opt/open-xchange/bundles/com.openexchange.common/lib/httpclient-cache-4.2.1.jar:/opt/open-xchange/lib/com.openexchange.admin.user.copy.console.jar"

test -z "$LIBPATH" && LIBPATH=${PREFIX}/lib

ADMINCP=$(for jar in $LIBPATH/*.jar; do
    echo -n "${jar}:"
    done)

exec $JAVA_BIN $JAVA_OPTS $CLASSPATH:$ADMINCP $JAVAMAIN $*
