1 # Copyright 1999-2013 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: office-ext-r1.eclass
6 # The office team <openoffice@gentoo.org>
8 # Tomáš Chvátal <scarabeus@gentoo.org>
9 # @SUPPORTED_EAPIS: 5 6
10 # @BLURB: Eclass for installing libreoffice/openoffice extensions
12 # Eclass for easing maintenance of libreoffice/openoffice extensions.
15 5|6) OEXT_EXPORTED_FUNCTIONS="src_unpack src_install pkg_postinst pkg_prerm" ;;
16 *) die "EAPI=${EAPI} is not supported" ;;
19 inherit eutils multilib
21 # @ECLASS-VARIABLE: OFFICE_REQ_USE
23 # Useflags required on office implementation for the extension.
27 # OFFICE_REQ_USE="java,jemalloc(-)?"
29 if [[ ${OFFICE_REQ_USE} ]]; then
30 # Append the brackets for the depend bellow
31 OFFICE_REQ_USE="[${OFFICE_REQ_USE}]"
34 # @ECLASS-VARIABLE: OFFICE_IMPLEMENTATIONS
36 # List of implementations supported by the extension.
37 # Some work only for libreoffice and vice versa.
38 # Default value is all implementations.
42 # OFFICE_IMPLEMENTATIONS=( "libreoffice" "openoffice" )
44 [[ -z ${OFFICE_IMPLEMENTATIONS} ]] && OFFICE_IMPLEMENTATIONS=( "libreoffice" "openoffice" )
46 # @ECLASS-VARIABLE: OFFICE_EXTENSIONS
49 # Array containing list of extensions to install.
53 # OFFICE_EXTENSIONS=( ${PN}_${PV}.oxt )
55 [[ -z ${OFFICE_EXTENSIONS} ]] && die "OFFICE_EXTENSIONS variable is unset."
56 if [[ "$(declare -p OFFICE_EXTENSIONS 2>/dev/null 2>&1)" != "declare -a"* ]]; then
57 die "OFFICE_EXTENSIONS variable is not an array."
60 # @ECLASS-VARIABLE: OFFICE_EXTENSIONS_LOCATION
62 # Path to the extensions location. Defaults to ${DISTDIR}.
66 # OFFICE_EXTENSIONS_LOCATION="${S}/unpacked/"
68 : ${OFFICE_EXTENSIONS_LOCATION:=${DISTDIR}}
73 for i in ${OFFICE_IMPLEMENTATIONS[@]}; do
74 IUSE+=" office_implementation_${i}"
75 if [[ ${i} == "openoffice" ]]; then
78 office_implementation_openoffice? (
79 app-office/openoffice-bin${OFFICE_REQ_USE}
84 office_implementation_${i}? (
86 app-office/${i}${OFFICE_REQ_USE}
87 app-office/${i}-bin${OFFICE_REQ_USE}
95 for i in ${OFFICE_IMPLEMENTATIONS[@]}; do
96 REQUIRED_USE+=" office_implementation_${i} "
104 # Most projects actually do not provide any relevant sourcedir as they are oxt.
107 # @FUNCTION: office-ext-r1_src_unpack
109 # Flush the cache after removal of an extension.
110 office-ext-r1_src_unpack() {
111 debug-print-function ${FUNCNAME} "$@"
116 for i in ${OFFICE_EXTENSIONS[@]}; do
117 # Unpack the extensions where required and add case for oxt
118 # which should be most common case for the extensions.
119 if [[ -f "${OFFICE_EXTENSIONS_LOCATION}/${i}" ]] ; then
122 mkdir -p "${WORKDIR}/${i}/"
123 pushd "${WORKDIR}/${i}/" > /dev/null
124 echo ">>> Unpacking "${OFFICE_EXTENSIONS_LOCATION}/${i}" to ${PWD}"
125 unzip -qo ${OFFICE_EXTENSIONS_LOCATION}/${i}
126 assert "failed unpacking ${OFFICE_EXTENSIONS_LOCATION}/${i}"
135 # @FUNCTION: office-ext-r1_src_install
137 # Install the extension source to the proper location.
138 office-ext-r1_src_install() {
139 debug-print-function ${FUNCNAME} "$@"
140 debug-print "Extensions: ${OFFICE_EXTENSIONS[@]}"
144 for i in ${OFFICE_IMPLEMENTATIONS[@]}; do
145 if use office_implementation_${i}; then
146 if [[ ${i} == openoffice ]]; then
147 # OOO needs to use uno because direct deployment segfaults.
148 # This is bug by their side, but i don't want to waste time
150 insinto /usr/$(get_libdir)/${i}/share/extension/install
151 for j in ${OFFICE_EXTENSIONS[@]}; do
152 doins ${OFFICE_EXTENSIONS_LOCATION}/${j}
155 for j in ${OFFICE_EXTENSIONS[@]}; do
156 pushd "${WORKDIR}/${j}/" > /dev/null
157 insinto /usr/$(get_libdir)/${i}/share/extensions/${j/.oxt/}
166 #### OPENOFFICE COMPAT CODE
168 UNOPKG_BINARY="/usr/lib64/openoffice/program/unopkg"
170 # @FUNCTION: office-ext-r1_add_extension
172 # Install the extension into the libreoffice/openoffice.
173 office-ext-r1_add_extension() {
174 debug-print-function ${FUNCNAME} "$@"
176 local tmpdir=$(emktemp -d)
178 debug-print "${FUNCNAME}: ${UNOPKG_BINARY} add --shared \"${ext}\""
179 ebegin "Adding office extension: \"${ext}\""
180 ${UNOPKG_BINARY} add --suppress-license \
182 "-env:UserInstallation=file:///${tmpdir}" \
183 "-env:JFW_PLUGIN_DO_NOT_CHECK_ACCESSIBILITY=1"
185 ${UNOPKG_BINARY} list --shared > /dev/null
189 # @FUNCTION: office-ext-r1_remove_extension
191 # Remove the extension from the libreoffice/openoffice.
192 office-ext-r1_remove_extension() {
193 debug-print-function ${FUNCNAME} "$@"
195 local tmpdir=$(mktemp -d --tmpdir="${T}")
197 debug-print "${FUNCNAME}: ${UNOPKG_BINARY} remove --shared \"${ext}\""
198 ebegin "Removing office extension: \"${ext}\""
199 ${UNOPKG_BINARY} remove --suppress-license \
201 "-env:UserInstallation=file:///${tmpdir}" \
202 "-env:JFW_PLUGIN_DO_NOT_CHECK_ACCESSIBILITY=1"
204 ${UNOPKG_BINARY} list --shared > /dev/null
208 # @FUNCTION: office-ext-r1_pkg_postinst
210 # Add the extensions to the openoffice.
211 office-ext-r1_pkg_postinst() {
212 if in_iuse office_implementation_openoffice && use office_implementation_openoffice; then
213 debug-print-function ${FUNCNAME} "$@"
214 debug-print "Extensions: ${OFFICE_EXTENSIONS[@]}"
217 for i in ${OFFICE_EXTENSIONS[@]}; do
218 office-ext-r1_add_extension "/usr/lib64/openoffice/share/extension/install/${i}"
223 # @FUNCTION: office-ext-r1_pkg_prerm
225 # Remove the extensions from the openoffice.
226 office-ext-r1_pkg_prerm() {
227 if in_iuse office_implementation_openoffice && use office_implementation_openoffice; then
228 debug-print-function ${FUNCNAME} "$@"
229 debug-print "Extensions: ${OFFICE_EXTENSIONS[@]}"
232 for i in ${OFFICE_EXTENSIONS[@]}; do
233 office-ext-r1_remove_extension "${i}"
238 EXPORT_FUNCTIONS ${OEXT_EXPORTED_FUNCTIONS}
239 unset OEXT_EXPORTED_FUNCTIONS