diff --git a/jodconverter-core/src/main/java/org/artofsolving/jodconverter/office/OfficeUtils.java b/jodconverter-core/src/main/java/org/artofsolving/jodconverter/office/OfficeUtils.java index 8b802a2a..db89c210 100644 --- a/jodconverter-core/src/main/java/org/artofsolving/jodconverter/office/OfficeUtils.java +++ b/jodconverter-core/src/main/java/org/artofsolving/jodconverter/office/OfficeUtils.java @@ -86,6 +86,7 @@ public class OfficeUtils { return findOfficeHome( "/opt/openoffice.org3", "/opt/libreoffice", + "/opt/openoffice4", "/usr/lib/openoffice", "/usr/lib/libreoffice" ); diff --git a/jodconverter-web/src/main/bin/startup.sh b/jodconverter-web/src/main/bin/startup.sh index 51ddfdf6..64c53148 100644 --- a/jodconverter-web/src/main/bin/startup.sh +++ b/jodconverter-web/src/main/bin/startup.sh @@ -1,8 +1,30 @@ #!/bin/bash -KKFILEVIEW_BIN_FOLDER=$(cd "$(dirname "$0")";pwd) +DIR_HOME=("/opt/openoffice.org3" "/opt/libreoffice" "/opt/openoffice4" "/usr/lib/openoffice" "/usr/lib/libreoffice") +FLAG= +OFFICE_HOME= +KKFILEVIEW_BIN_FOLDER=$(cd "$(dirname "$0")";pwd)vim export KKFILEVIEW_BIN_FOLDER=$KKFILEVIEW_BIN_FOLDER cd $KKFILEVIEW_BIN_FOLDER echo "Using KKFILEVIEW_BIN_FOLDER $KKFILEVIEW_BIN_FOLDER" +grep 'office\.home' ../conf/application.properties | grep '!^#' +if [ $? -eq 0 ]; then + echo "Using customized office.home" +else + for i in ${DIR_HOME[@]} + do + if [ -f $i"/program/soffice.bin" ]; then + FLAG=true + OFFICE_HOME=${i} + break + fi + done + if [ ! -n "${FLAG}" ]; then + echo "Installing OpenOffice" + sh ../script/install.sh + else + echo "Detected office component has been installed in $OFFICE_HOME" + fi +fi echo "Starting kkFileView..." echo "Please check log file for more information" -nohup java -Dspring.config.location=../conf/application.properties -jar kkFileView-0.1.jar ../log/kkFileView.log 2>&1 & \ No newline at end of file +nohup java -Dspring.config.location=../conf/application.properties -jar kkFileView-0.1.jar > ../log/kkFileView.log 2>&1 & diff --git a/jodconverter-web/src/main/java/cn/keking/config/ConfigRefreshComponent.java b/jodconverter-web/src/main/java/cn/keking/config/ConfigRefreshComponent.java index f1798cd2..d392292c 100644 --- a/jodconverter-web/src/main/java/cn/keking/config/ConfigRefreshComponent.java +++ b/jodconverter-web/src/main/java/cn/keking/config/ConfigRefreshComponent.java @@ -1,13 +1,12 @@ package cn.keking.config; -import cn.keking.utils.HomePathUtils; +import org.artofsolving.jodconverter.office.OfficeUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; import java.io.BufferedReader; -import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.Properties; @@ -38,7 +37,7 @@ public class ConfigRefreshComponent { String convertedFileCharset; String[] textArray ; String[] mediaArray; - String homePath = HomePathUtils.getHomePath(); + String homePath = OfficeUtils.getHomePath(); String separator = java.io.File.separator; String configFilePath = homePath + separator + "conf" + separator + "application.properties"; while (true) { diff --git a/jodconverter-web/src/main/java/cn/keking/utils/HomePathUtils.java b/jodconverter-web/src/main/java/cn/keking/utils/HomePathUtils.java deleted file mode 100644 index e5b107ad..00000000 --- a/jodconverter-web/src/main/java/cn/keking/utils/HomePathUtils.java +++ /dev/null @@ -1,26 +0,0 @@ -package cn.keking.utils; - -import java.io.File; - -/** - * @auther: chenjh - * @time: 2019/4/15 9:11 - * @description - */ -public class HomePathUtils { - - public static String getHomePath() { - String userDir = System.getenv("KKFILEVIEW_BIN_FOLDER"); - if (userDir == null) { - userDir = System.getProperty("user.dir"); - } - if (userDir.endsWith("bin")) { - userDir = userDir.substring(0, userDir.length() - 4); - } else { - String separator = File.separator; - userDir = userDir + separator + "jodconverter-web" + separator + "src" + separator + "main"; - } - return userDir; - } - -} diff --git a/jodconverter-web/src/main/resources/assembly.xml b/jodconverter-web/src/main/resources/assembly.xml index 42652a43..e1b541ff 100644 --- a/jodconverter-web/src/main/resources/assembly.xml +++ b/jodconverter-web/src/main/resources/assembly.xml @@ -20,6 +20,11 @@ ${file.separator}bin 755 + + src/main/script + ${file.separator}script + 755 + src/main/log ${file.separator}log diff --git a/jodconverter-web/src/main/resources/logback.xml b/jodconverter-web/src/main/resources/logback.xml deleted file mode 100644 index cb40b409..00000000 --- a/jodconverter-web/src/main/resources/logback.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - 10800 - 192.168.1.109 - true - {"app_name":"@appName@"} - - - - - - \ No newline at end of file diff --git a/jodconverter-web/src/main/script/install.sh b/jodconverter-web/src/main/script/install.sh new file mode 100644 index 00000000..4ab77647 --- /dev/null +++ b/jodconverter-web/src/main/script/install.sh @@ -0,0 +1,36 @@ +#!/bin/bash +cd /tmp + +install_redhat() { + wget https://iweb.dl.sourceforge.net/project/openofficeorg.mirror/4.1.6/binaries/zh-CN/Apache_OpenOffice_4.1.6_Linux_x86-64_install-rpm_zh-CN.tar.gz -cO openoffice_rpm.tar.gz && tar zxf /tmp/openoffice_rpm.tar.gz && cd /tmp/zh-CN/RPMS + if [ $? -eq 0 ];then + rpm -Uvih *.rpm + echo 'install desktop service ...' + rpm -Uvih desktop-integration/openoffice4.1.6-redhat-menus-4.1.6-9790.noarch.rpm + echo 'install finshed...' + else + echo 'download package error...' + fi +} + +install_ubuntu() { + wget https://iweb.dl.sourceforge.net/project/openofficeorg.mirror/4.1.6/binaries/zh-CN/Apache_OpenOffice_4.1.6_Linux_x86-64_install-deb_zh-CN.tar.gz -cO openoffice_deb.tar.gz && tar zxf /tmp/openoffice_deb.tar.gz && cd /tmp/zh-CN/DEBS + echo $? + if [ $? -eq 0 ];then + dpkg -i *.deb + echo 'install desktop service ...' + dpkg -i desktop-integration/openoffice4.1-debian-menus_4.1.6-9790_all.deb + echo 'install finshed...' + else + echo 'download package error...' + fi +} + + +if [ -f "/etc/redhat-release" ]; then + yum install wget + install_redhat +else + apt-get install wget + install_ubuntu +fi \ No newline at end of file