1 # Copyright 1999-2019 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: office-ext-r1.eclass
6 # The office team <office@gentoo.org>
8 # Tomáš Chvátal <scarabeus@gentoo.org>
9 # @SUPPORTED_EAPIS: 5 6 7
10 # @BLURB: Eclass for installing libreoffice/openoffice extensions
12 # Eclass for easing maintenance of libreoffice/openoffice extensions.
15 5|6) inherit eutils multilib ;;
17 *) die "EAPI=${EAPI} is not supported" ;;
20 OEXT_EXPORTED_FUNCTIONS="src_unpack src_install pkg_postinst pkg_prerm"
22 # @ECLASS-VARIABLE: OFFICE_REQ_USE
24 # Useflags required on office implementation for the extension.
28 # OFFICE_REQ_USE="java,jemalloc(-)?"
30 if [[ ${OFFICE_REQ_USE} ]]; then
31 # Append the brackets for the depend bellow
32 OFFICE_REQ_USE="[${OFFICE_REQ_USE}]"
35 # @ECLASS-VARIABLE: OFFICE_IMPLEMENTATIONS
37 # List of implementations supported by the extension.
38 # Some work only for libreoffice and vice versa.
39 # Default value is all implementations.
43 # OFFICE_IMPLEMENTATIONS=( "libreoffice" "openoffice" )
45 [[ -z ${OFFICE_IMPLEMENTATIONS} ]] && OFFICE_IMPLEMENTATIONS=( "libreoffice" "openoffice" )
47 # @ECLASS-VARIABLE: OFFICE_EXTENSIONS
50 # Array containing list of extensions to install.
54 # OFFICE_EXTENSIONS=( ${PN}_${PV}.oxt )
56 [[ -z ${OFFICE_EXTENSIONS} ]] && die "OFFICE_EXTENSIONS variable is unset."
57 if [[ "$(declare -p OFFICE_EXTENSIONS 2>/dev/null 2>&1)" != "declare -a"* ]]; then
58 die "OFFICE_EXTENSIONS variable is not an array."
61 # @ECLASS-VARIABLE: OFFICE_EXTENSIONS_LOCATION
63 # Path to the extensions location. Defaults to ${DISTDIR}.
67 # OFFICE_EXTENSIONS_LOCATION="${S}/unpacked/"
69 : ${OFFICE_EXTENSIONS_LOCATION:=${DISTDIR}}
74 for i in ${OFFICE_IMPLEMENTATIONS[@]}; do
75 IUSE+=" office_implementation_${i}"
76 if [[ ${i} == "openoffice" ]]; then
79 office_implementation_openoffice? (
80 app-office/openoffice-bin${OFFICE_REQ_USE}
85 office_implementation_${i}? (
87 app-office/${i}${OFFICE_REQ_USE}
88 app-office/${i}-bin${OFFICE_REQ_USE}
96 for i in ${OFFICE_IMPLEMENTATIONS[@]}; do
97 REQUIRED_USE+=" office_implementation_${i} "
105 # Most projects actually do not provide any relevant sourcedir as they are oxt.
108 # @FUNCTION: office-ext-r1_src_unpack
110 # Flush the cache after removal of an extension.
111 office-ext-r1_src_unpack() {
112 debug-print-function ${FUNCNAME} "$@"
117 for i in ${OFFICE_EXTENSIONS[@]}; do
118 # Unpack the extensions where required and add case for oxt
119 # which should be most common case for the extensions.
120 if [[ -f "${OFFICE_EXTENSIONS_LOCATION}/${i}" ]] ; then
123 mkdir -p "${WORKDIR}/${i}/"
124 pushd "${WORKDIR}/${i}/" > /dev/null
125 echo ">>> Unpacking "${OFFICE_EXTENSIONS_LOCATION}/${i}" to ${PWD}"
126 unzip -qo ${OFFICE_EXTENSIONS_LOCATION}/${i}
127 assert "failed unpacking ${OFFICE_EXTENSIONS_LOCATION}/${i}"
136 # @FUNCTION: office-ext-r1_src_install
138 # Install the extension source to the proper location.
139 office-ext-r1_src_install() {
140 debug-print-function ${FUNCNAME} "$@"
141 debug-print "Extensions: ${OFFICE_EXTENSIONS[@]}"
145 for i in ${OFFICE_IMPLEMENTATIONS[@]}; do
146 if use office_implementation_${i}; then
147 if [[ ${i} == openoffice ]]; then
148 # OOO needs to use uno because direct deployment segfaults.
149 # This is bug by their side, but i don't want to waste time
151 insinto /usr/$(get_libdir)/${i}/share/extension/install
152 for j in ${OFFICE_EXTENSIONS[@]}; do
153 doins ${OFFICE_EXTENSIONS_LOCATION}/${j}
156 for j in ${OFFICE_EXTENSIONS[@]}; do
157 pushd "${WORKDIR}/${j}/" > /dev/null
158 insinto /usr/$(get_libdir)/${i}/share/extensions/${j/.oxt/}
167 #### OPENOFFICE COMPAT CODE
169 UNOPKG_BINARY="/usr/lib64/openoffice/program/unopkg"
171 # @FUNCTION: office-ext-r1_add_extension
173 # Install the extension into the libreoffice/openoffice.
174 office-ext-r1_add_extension() {
175 debug-print-function ${FUNCNAME} "$@"
177 local tmpdir=$(emktemp -d)
179 debug-print "${FUNCNAME}: ${UNOPKG_BINARY} add --shared \"${ext}\""
180 ebegin "Adding office extension: \"${ext}\""
181 ${UNOPKG_BINARY} add --suppress-license \
183 "-env:UserInstallation=file:///${tmpdir}" \
184 "-env:JFW_PLUGIN_DO_NOT_CHECK_ACCESSIBILITY=1"
186 ${UNOPKG_BINARY} list --shared > /dev/null
187 rm -r "${tmpdir}" || dir "failed to clean up"
190 # @FUNCTION: office-ext-r1_remove_extension
192 # Remove the extension from the libreoffice/openoffice.
193 office-ext-r1_remove_extension() {
194 debug-print-function ${FUNCNAME} "$@"
196 local tmpdir=$(mktemp -d --tmpdir="${T}")
198 debug-print "${FUNCNAME}: ${UNOPKG_BINARY} remove --shared \"${ext}\""
199 ebegin "Removing office extension: \"${ext}\""
200 ${UNOPKG_BINARY} remove --suppress-license \
202 "-env:UserInstallation=file:///${tmpdir}" \
203 "-env:JFW_PLUGIN_DO_NOT_CHECK_ACCESSIBILITY=1"
205 ${UNOPKG_BINARY} list --shared > /dev/null
206 rm -r "${tmpdir}" || dir "failed to clean up"
209 # @FUNCTION: office-ext-r1_pkg_postinst
211 # Add the extensions to the openoffice.
212 office-ext-r1_pkg_postinst() {
213 if in_iuse office_implementation_openoffice && use office_implementation_openoffice; then
214 debug-print-function ${FUNCNAME} "$@"
215 debug-print "Extensions: ${OFFICE_EXTENSIONS[@]}"
218 for i in ${OFFICE_EXTENSIONS[@]}; do
219 office-ext-r1_add_extension "/usr/lib64/openoffice/share/extension/install/${i}"
224 # @FUNCTION: office-ext-r1_pkg_prerm
226 # Remove the extensions from the openoffice.
227 office-ext-r1_pkg_prerm() {
228 if in_iuse office_implementation_openoffice && use office_implementation_openoffice; then
229 debug-print-function ${FUNCNAME} "$@"
230 debug-print "Extensions: ${OFFICE_EXTENSIONS[@]}"
233 for i in ${OFFICE_EXTENSIONS[@]}; do
234 office-ext-r1_remove_extension "${i}"
239 EXPORT_FUNCTIONS ${OEXT_EXPORTED_FUNCTIONS}
240 unset OEXT_EXPORTED_FUNCTIONS