sync-webroot-to-runtime.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  4. PROJECT_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"
  5. RUNTIME_DIR="${PROJECT_ROOT}/local-run/runtime/full-local"
  6. WEBAPP_DIR="${RUNTIME_DIR}/webapp"
  7. if [[ ! -d "${WEBAPP_DIR}" ]]; then
  8. echo "运行副本不存在,请先启动完整后台:${PROJECT_ROOT}/local-run/bin/start-full.sh" >&2
  9. exit 1
  10. fi
  11. "${SCRIPT_DIR}/compile-hxcs-deploy-classes.sh"
  12. rsync -a --delete "${PROJECT_ROOT}/WebRoot/" "${WEBAPP_DIR}/"
  13. echo "已同步 WebRoot -> ${WEBAPP_DIR}"
  14. "${SCRIPT_DIR}/apply-local-runtime-config.sh"
  15. if [[ "$(uname -s)" == "Darwin" ]]; then
  16. libreoffice_path="${ZQ_LIBREOFFICE_MAC_PATH:-}"
  17. if [[ -z "${libreoffice_path}" ]]; then
  18. for candidate in \
  19. "/Applications/LibreOffice.app/Contents/MacOS/soffice" \
  20. "$(command -v soffice 2>/dev/null || true)" \
  21. "$(command -v libreoffice 2>/dev/null || true)"; do
  22. if [[ -n "${candidate}" && -x "${candidate}" ]]; then
  23. libreoffice_path="${candidate}"
  24. break
  25. fi
  26. done
  27. fi
  28. if [[ -n "${libreoffice_path}" && -x "${libreoffice_path}" ]]; then
  29. /usr/bin/python3 - "${WEBAPP_DIR}/WEB-INF/application.xml" "${libreoffice_path}" <<'PY'
  30. import re
  31. import sys
  32. from pathlib import Path
  33. config = Path(sys.argv[1])
  34. path = sys.argv[2]
  35. content = config.read_text(encoding="utf-8")
  36. content, count = re.subn(
  37. r"<libreOfficeMacOrMacOSXPath>.*?</libreOfficeMacOrMacOSXPath>",
  38. f"<libreOfficeMacOrMacOSXPath>{path}</libreOfficeMacOrMacOSXPath>",
  39. content,
  40. count=1,
  41. )
  42. if count:
  43. config.write_text(content, encoding="utf-8")
  44. PY
  45. echo "本地 LibreOffice 路径:${libreoffice_path}"
  46. else
  47. echo "提醒:未找到可执行的 LibreOffice,Word 导入将回退 Mammoth 基础格式。"
  48. fi
  49. fi