1 # Copyright 1999-2020 Gentoo Authors
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 multilib ;;
17 *) die "EAPI=${EAPI} is not supported" ;;
20 # eutils.eclass: emktemp
23 OEXT_EXPORTED_FUNCTIONS="src_unpack src_install pkg_postinst pkg_prerm"
25 # @ECLASS-VARIABLE: OFFICE_REQ_USE
27 # Useflags required on office implementation for the extension.
31 # OFFICE_REQ_USE="java,jemalloc(-)?"
33 if [[ ${OFFICE_REQ_USE} ]]; then
34 # Append the brackets for the depend bellow
35 OFFICE_REQ_USE="[${OFFICE_REQ_USE}]"
38 # @ECLASS-VARIABLE: OFFICE_IMPLEMENTATIONS
40 # List of implementations supported by the extension.
41 # Some work only for libreoffice and vice versa.
42 # Default value is all implementations.
46 # OFFICE_IMPLEMENTATIONS=( "libreoffice" "openoffice" )
48 [[ -z ${OFFICE_IMPLEMENTATIONS} ]] && OFFICE_IMPLEMENTATIONS=( "libreoffice" "openoffice" )
50 # @ECLASS-VARIABLE: OFFICE_EXTENSIONS
53 # Array containing list of extensions to install.
57 # OFFICE_EXTENSIONS=( ${PN}_${PV}.oxt )
59 [[ -z ${OFFICE_EXTENSIONS} ]] && die "OFFICE_EXTENSIONS variable is unset."
60 if [[ "$(declare -p OFFICE_EXTENSIONS 2>/dev/null 2>&1)" != "declare -a"* ]]; then
61 die "OFFICE_EXTENSIONS variable is not an array."
64 # @ECLASS-VARIABLE: OFFICE_EXTENSIONS_LOCATION
66 # Path to the extensions location. Defaults to ${DISTDIR}.
70 # OFFICE_EXTENSIONS_LOCATION="${S}/unpacked/"
72 : ${OFFICE_EXTENSIONS_LOCATION:=${DISTDIR}}
77 for i in ${OFFICE_IMPLEMENTATIONS[@]}; do
78 IUSE+=" office_implementation_${i}"
79 if [[ ${i} == "openoffice" ]]; then
82 office_implementation_openoffice? (
83 app-office/openoffice-bin${OFFICE_REQ_USE}
88 office_implementation_${i}? (
90 app-office/${i}${OFFICE_REQ_USE}
91 app-office/${i}-bin${OFFICE_REQ_USE}
99 for i in ${OFFICE_IMPLEMENTATIONS[@]}; do
100 REQUIRED_USE+=" office_implementation_${i} "
108 # Most projects actually do not provide any relevant sourcedir as they are oxt.
111 # @FUNCTION: office-ext-r1_src_unpack
113 # Flush the cache after removal of an extension.
114 office-ext-r1_src_unpack() {
115 debug-print-function ${FUNCNAME} "$@"
120 for i in ${OFFICE_EXTENSIONS[@]}; do
121 # Unpack the extensions where required and add case for oxt
122 # which should be most common case for the extensions.
123 if [[ -f "${OFFICE_EXTENSIONS_LOCATION}/${i}" ]] ; then
126 mkdir -p "${WORKDIR}/${i}/"
127 pushd "${WORKDIR}/${i}/" > /dev/null
128 echo ">>> Unpacking "${OFFICE_EXTENSIONS_LOCATION}/${i}" to ${PWD}"
129 unzip -qo ${OFFICE_EXTENSIONS_LOCATION}/${i}
130 assert "failed unpacking ${OFFICE_EXTENSIONS_LOCATION}/${i}"
139 # @FUNCTION: office-ext-r1_src_install
141 # Install the extension source to the proper location.
142 office-ext-r1_src_install() {
143 debug-print-function ${FUNCNAME} "$@"
144 debug-print "Extensions: ${OFFICE_EXTENSIONS[@]}"
148 for i in ${OFFICE_IMPLEMENTATIONS[@]}; do
149 if use office_implementation_${i}; then
150 if [[ ${i} == openoffice ]]; then
151 # OOO needs to use uno because direct deployment segfaults.
152 # This is bug by their side, but i don't want to waste time
154 insinto /usr/$(get_libdir)/${i}/share/extension/install
155 for j in ${OFFICE_EXTENSIONS[@]}; do
156 doins ${OFFICE_EXTENSIONS_LOCATION}/${j}
159 for j in ${OFFICE_EXTENSIONS[@]}; do
160 pushd "${WORKDIR}/${j}/" > /dev/null
161 insinto /usr/$(get_libdir)/${i}/share/extensions/${j/.oxt/}
170 #### OPENOFFICE COMPAT CODE
172 UNOPKG_BINARY="/usr/lib64/openoffice/program/unopkg"
174 # @FUNCTION: office-ext-r1_add_extension
176 # Install the extension into the libreoffice/openoffice.
177 office-ext-r1_add_extension() {
178 debug-print-function ${FUNCNAME} "$@"
180 local tmpdir=$(emktemp -d)
182 debug-print "${FUNCNAME}: ${UNOPKG_BINARY} add --shared \"${ext}\""
183 ebegin "Adding office extension: \"${ext}\""
184 ${UNOPKG_BINARY} add --suppress-license \
186 "-env:UserInstallation=file:///${tmpdir}" \
187 "-env:JFW_PLUGIN_DO_NOT_CHECK_ACCESSIBILITY=1"
189 ${UNOPKG_BINARY} list --shared > /dev/null
190 rm -r "${tmpdir}" || dir "failed to clean up"
193 # @FUNCTION: office-ext-r1_remove_extension
195 # Remove the extension from the libreoffice/openoffice.
196 office-ext-r1_remove_extension() {
197 debug-print-function ${FUNCNAME} "$@"
199 local tmpdir=$(mktemp -d --tmpdir="${T}")
201 debug-print "${FUNCNAME}: ${UNOPKG_BINARY} remove --shared \"${ext}\""
202 ebegin "Removing office extension: \"${ext}\""
203 ${UNOPKG_BINARY} remove --suppress-license \
205 "-env:UserInstallation=file:///${tmpdir}" \
206 "-env:JFW_PLUGIN_DO_NOT_CHECK_ACCESSIBILITY=1"
208 ${UNOPKG_BINARY} list --shared > /dev/null
209 rm -r "${tmpdir}" || dir "failed to clean up"
212 # @FUNCTION: office-ext-r1_pkg_postinst
214 # Add the extensions to the openoffice.
215 office-ext-r1_pkg_postinst() {
216 if in_iuse office_implementation_openoffice && use office_implementation_openoffice; then
217 debug-print-function ${FUNCNAME} "$@"
218 debug-print "Extensions: ${OFFICE_EXTENSIONS[@]}"
221 for i in ${OFFICE_EXTENSIONS[@]}; do
222 office-ext-r1_add_extension "/usr/lib64/openoffice/share/extension/install/${i}"
227 # @FUNCTION: office-ext-r1_pkg_prerm
229 # Remove the extensions from the openoffice.
230 office-ext-r1_pkg_prerm() {
231 if in_iuse office_implementation_openoffice && use office_implementation_openoffice; then
232 debug-print-function ${FUNCNAME} "$@"
233 debug-print "Extensions: ${OFFICE_EXTENSIONS[@]}"
236 for i in ${OFFICE_EXTENSIONS[@]}; do
237 office-ext-r1_remove_extension "${i}"
242 EXPORT_FUNCTIONS ${OEXT_EXPORTED_FUNCTIONS}
243 unset OEXT_EXPORTED_FUNCTIONS