office-ext-r1.eclass 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. # Copyright 1999-2013 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. # @ECLASS: office-ext-r1.eclass
  4. # @MAINTAINER:
  5. # The office team <openoffice@gentoo.org>
  6. # @AUTHOR:
  7. # Tomáš Chvátal <scarabeus@gentoo.org>
  8. # @BLURB: Eclass for installing libreoffice/openoffice extensions
  9. # @DESCRIPTION:
  10. # Eclass for easing maitenance of libreoffice/openoffice extensions.
  11. case "${EAPI:-0}" in
  12. 5) OEXT_EXPORTED_FUNCTIONS="src_unpack src_install pkg_postinst pkg_prerm" ;;
  13. *) die "EAPI=${EAPI} is not supported" ;;
  14. esac
  15. inherit eutils multilib
  16. # @ECLASS-VARIABLE: OFFICE_REQ_USE
  17. # @DESCRIPTION:
  18. # Useflags required on office implementation for the extension.
  19. #
  20. # Example:
  21. # @CODE
  22. # OFFICE_REQ_USE="java,jemalloc(-)?"
  23. # @CODE
  24. if [[ ${OFFICE_REQ_USE} ]]; then
  25. # Append the brackets for the depend bellow
  26. OFFICE_REQ_USE="[${OFFICE_REQ_USE}]"
  27. fi
  28. # @ECLASS-VARIABLE: OFFICE_IMPLEMENTATIONS
  29. # @DESCRIPTION:
  30. # List of implementations supported by the extension.
  31. # Some work only for libreoffice and vice versa.
  32. # Default value is all implementations.
  33. #
  34. # Example:
  35. # @CODE
  36. # OFFICE_IMPLEMENTATIONS=( "libreoffice" "openoffice" )
  37. # @CODE
  38. [[ -z ${OFFICE_IMPLEMENTATIONS} ]] && OFFICE_IMPLEMENTATIONS=( "libreoffice" "openoffice" )
  39. # @ECLASS-VARIABLE: OFFICE_EXTENSIONS
  40. # @REQUIRED
  41. # @DESCRIPTION:
  42. # Array containing list of extensions to install.
  43. #
  44. # Example:
  45. # @CODE
  46. # OFFICE_EXTENSIONS=( ${PN}_${PV}.oxt )
  47. # @CODE
  48. [[ -z ${OFFICE_EXTENSIONS} ]] && die "OFFICE_EXTENSIONS variable is unset."
  49. if [[ "$(declare -p OFFICE_EXTENSIONS 2>/dev/null 2>&1)" != "declare -a"* ]]; then
  50. die "OFFICE_EXTENSIONS variable is not an array."
  51. fi
  52. # @ECLASS-VARIABLE: OFFICE_EXTENSIONS_LOCATION
  53. # @DESCRIPTION:
  54. # Path to the extensions location. Defaults to ${DISTDIR}.
  55. #
  56. # Example:
  57. # @CODE
  58. # OFFICE_EXTENSIONS_LOCATION="${S}/unpacked/"
  59. # @CODE
  60. : ${OFFICE_EXTENSIONS_LOCATION:=${DISTDIR}}
  61. IUSE=""
  62. RDEPEND=""
  63. for i in ${OFFICE_IMPLEMENTATIONS[@]}; do
  64. IUSE+=" office_implementation_${i}"
  65. if [[ ${i} == "openoffice" ]]; then
  66. # special only binary
  67. RDEPEND+="
  68. office_implementation_openoffice? (
  69. app-office/openoffice-bin${OFFICE_REQ_USE}
  70. )
  71. "
  72. else
  73. RDEPEND+="
  74. office_implementation_${i}? (
  75. || (
  76. app-office/${i}${OFFICE_REQ_USE}
  77. app-office/${i}-bin${OFFICE_REQ_USE}
  78. )
  79. )
  80. "
  81. fi
  82. done
  83. REQUIRED_USE="|| ( "
  84. for i in ${OFFICE_IMPLEMENTATIONS[@]}; do
  85. REQUIRED_USE+=" office_implementation_${i} "
  86. done
  87. REQUIRED_USE+=" )"
  88. DEPEND="${RDEPEND}
  89. app-arch/unzip
  90. "
  91. # Most projects actually do not provide any relevant sourcedir as they are oxt.
  92. S="${WORKDIR}"
  93. # @FUNCTION: office-ext-r1_src_unpack
  94. # @DESCRIPTION:
  95. # Flush the cache after removal of an extension.
  96. office-ext-r1_src_unpack() {
  97. debug-print-function ${FUNCNAME} "$@"
  98. local i
  99. default
  100. for i in ${OFFICE_EXTENSIONS[@]}; do
  101. # Unpack the extensions where required and add case for oxt
  102. # which should be most common case for the extensions.
  103. if [[ -f "${OFFICE_EXTENSIONS_LOCATION}/${i}" ]] ; then
  104. case ${i} in
  105. *.oxt)
  106. mkdir -p "${WORKDIR}/${i}/"
  107. pushd "${WORKDIR}/${i}/" > /dev/null
  108. echo ">>> Unpacking "${OFFICE_EXTENSIONS_LOCATION}/${i}" to ${PWD}"
  109. unzip -qo ${OFFICE_EXTENSIONS_LOCATION}/${i}
  110. assert "failed unpacking ${OFFICE_EXTENSIONS_LOCATION}/${i}"
  111. popd > /dev/null
  112. ;;
  113. *) unpack ${i} ;;
  114. esac
  115. fi
  116. done
  117. }
  118. # @FUNCTION: office-ext-r1_src_install
  119. # @DESCRIPTION:
  120. # Install the extension source to the proper location.
  121. office-ext-r1_src_install() {
  122. debug-print-function ${FUNCNAME} "$@"
  123. debug-print "Extensions: ${OFFICE_EXTENSIONS[@]}"
  124. local i j
  125. for i in ${OFFICE_IMPLEMENTATIONS[@]}; do
  126. if use office_implementation_${i}; then
  127. if [[ ${i} == openoffice ]]; then
  128. # OOO needs to use uno because direct deployment segfaults.
  129. # This is bug by their side, but i don't want to waste time
  130. # fixing it myself.
  131. insinto /usr/$(get_libdir)/${i}/share/extension/install
  132. for j in ${OFFICE_EXTENSIONS[@]}; do
  133. doins ${OFFICE_EXTENSIONS_LOCATION}/${j}
  134. done
  135. else
  136. for j in ${OFFICE_EXTENSIONS[@]}; do
  137. pushd "${WORKDIR}/${j}/" > /dev/null
  138. insinto /usr/$(get_libdir)/${i}/share/extensions/${j/.oxt/}
  139. doins -r *
  140. popd > /dev/null
  141. done
  142. fi
  143. fi
  144. done
  145. }
  146. #### OPENOFFICE COMPAT CODE
  147. UNOPKG_BINARY="/usr/lib64/openoffice/program/unopkg"
  148. # @FUNCTION: office-ext-r1_add_extension
  149. # @DESCRIPTION:
  150. # Install the extension into the libreoffice/openoffice.
  151. office-ext-r1_add_extension() {
  152. debug-print-function ${FUNCNAME} "$@"
  153. local ext=$1
  154. local tmpdir=$(emktemp -d)
  155. debug-print "${FUNCNAME}: ${UNOPKG_BINARY} add --shared \"${ext}\""
  156. ebegin "Adding office extension: \"${ext}\""
  157. ${UNOPKG_BINARY} add --suppress-license \
  158. --shared "${ext}" \
  159. "-env:UserInstallation=file:///${tmpdir}" \
  160. "-env:JFW_PLUGIN_DO_NOT_CHECK_ACCESSIBILITY=1"
  161. eend $?
  162. ${UNOPKG_BINARY} list --shared > /dev/null
  163. rm -rf "${tmpdir}"
  164. }
  165. # @FUNCTION: office-ext-r1_remove_extension
  166. # @DESCRIPTION:
  167. # Remove the extension from the libreoffice/openoffice.
  168. office-ext-r1_remove_extension() {
  169. debug-print-function ${FUNCNAME} "$@"
  170. local ext=$1
  171. local tmpdir=$(mktemp -d --tmpdir="${T}")
  172. debug-print "${FUNCNAME}: ${UNOPKG_BINARY} remove --shared \"${ext}\""
  173. ebegin "Removing office extension: \"${ext}\""
  174. ${UNOPKG_BINARY} remove --suppress-license \
  175. --shared "${ext}" \
  176. "-env:UserInstallation=file:///${tmpdir}" \
  177. "-env:JFW_PLUGIN_DO_NOT_CHECK_ACCESSIBILITY=1"
  178. eend $?
  179. ${UNOPKG_BINARY} list --shared > /dev/null
  180. rm -rf "${tmpdir}"
  181. }
  182. # @FUNCTION: office-ext-r1_pkg_postinst
  183. # @DESCRIPTION:
  184. # Add the extensions to the openoffice.
  185. office-ext-r1_pkg_postinst() {
  186. if in_iuse office_implementation_openoffice && use office_implementation_openoffice; then
  187. debug-print-function ${FUNCNAME} "$@"
  188. debug-print "Extensions: ${OFFICE_EXTENSIONS[@]}"
  189. local i
  190. for i in ${OFFICE_EXTENSIONS[@]}; do
  191. office-ext-r1_add_extension "/usr/lib64/openoffice/share/extension/install/${i}"
  192. done
  193. fi
  194. }
  195. # @FUNCTION: office-ext-r1_pkg_prerm
  196. # @DESCRIPTION:
  197. # Remove the extensions from the openoffice.
  198. office-ext-r1_pkg_prerm() {
  199. if in_iuse office_implementation_openoffice && use office_implementation_openoffice; then
  200. debug-print-function ${FUNCNAME} "$@"
  201. debug-print "Extensions: ${OFFICE_EXTENSIONS[@]}"
  202. local i
  203. for i in ${OFFICE_EXTENSIONS[@]}; do
  204. office-ext-r1_remove_extension "${i}"
  205. done
  206. fi
  207. }
  208. EXPORT_FUNCTIONS ${OEXT_EXPORTED_FUNCTIONS}
  209. unset OEXT_EXPORTED_FUNCTIONS