1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # Author: Kevin F. Quinn <kevquinn@gentoo.org>
5 # Packages: app-dicts/myspell-*
6 # Maintainer: maintainer-needed@gentoo.org
10 EXPORT_FUNCTIONS src_install pkg_preinst pkg_postinst
16 # tar, gzip, bzip2 are included in the base profile, but not unzip
17 DEPEND="app-arch/unzip"
19 # Dictionaries don't have any runtime dependencies
20 # Myspell dictionaries can be used by hunspell, openoffice and others
23 # The destination directory for myspell dictionaries
24 MYSPELL_DICTBASE="/usr/share/myspell"
26 # Legacy variable for dictionaries installed before eselect-oodict existed
27 # so has to remain for binpkg support. This variable is unmaintained -
28 # if you have a problem with it, emerge app-eselect/eselect-oodict.
29 # The location for openoffice softlinks
30 MYSPELL_OOOBASE="/usr/lib/openoffice/share/dict/ooo"
33 # set array "fields" to the elements of $1, separated by $2.
34 # This saves having to muck about with IFS all over the place.
43 # language is the second element of the ebuild name
44 # myspell-<lang>-<version>
51 get_myspell_suffixes() {
53 DICT) echo ".aff .dic" ;;
55 THES) echo ".dat .idx" ;;
59 # OOo dictionary files are held on the mirrors, rather than
60 # being fetched direct from the OOo site as upstream doesn't
61 # change the name when they rebuild the dictionaries.
62 # <lang>-<country>.zip becomes myspell-<lang>-<country>-version.zip
63 get_myspell_ooo_uri() {
64 local files fields newfile filestem srcfile dict uris
68 "${MYSPELL_SPELLING_DICTIONARIES[@]}" \
69 "${MYSPELL_HYPHENATION_DICTIONARIES[@]}" \
70 "${MYSPELL_THESAURUS_DICTIONARIES[@]}"; do
71 set_fields "${dict}" ","
72 newfile=${fields[4]// }
73 for file in "${files[@]}"; do
74 [[ ${file} == ${newfile} ]] && continue 2
76 filestem=${newfile/.zip}
77 files=("${files[@]}" "${newfile}")
78 srcfile="myspell-${filestem}-${PV}.zip"
80 uris="mirror://gentoo/${srcfile}" ||
81 uris="${uris} mirror://gentoo/${srcfile}"
87 [[ -z ${SRC_URI} ]] && SRC_URI=$(get_myspell_ooo_uri)
89 # Format of dictionary.lst files (from OOo standard
90 # dictionary.lst file):
92 # List of All Dictionaries to be Loaded by OpenOffice
93 # ---------------------------------------------------
94 # Each Entry in the list have the following space delimited fields
96 # Field 0: Entry Type "DICT" - spellchecking dictionary
97 # "HYPH" - hyphenation dictionary
98 # "THES" - thesaurus files
100 # Field 1: Language code from Locale "en" or "de" or "pt" ...
102 # Field 2: Country Code from Locale "US" or "GB" or "PT"
104 # Field 3: Root name of file(s) "en_US" or "hyph_de" or "th_en_US"
105 # (do not add extensions to the name)
107 # Format of MYSPELL_[SPELLING|HYPHENATION|THESAURUS]_DICTIONARIES:
109 # Field 0: Language code
110 # Field 1: Country code
111 # Field 2: Root name of dictionary files
112 # Field 3: Description
113 # Field 4: Archive filename
115 # This format is from the available.lst, hyphavail.lst and
116 # thesavail.lst files on the openoffice.org repository.
118 myspell_src_install() {
119 local filen fields entry dictlst
121 # Install the dictionary, hyphenation and thesaurus files.
122 # Create dictionary.lst.<lang> file containing the parts of
123 # OOo's dictionary.lst file for this language, indicating
124 # which dictionaries are relevant for each country variant
126 insinto ${MYSPELL_DICTBASE}
127 dictlst="dictionary.lst.$(get_myspell_lang)"
128 echo "# Autogenerated by ${CATEGORY}/${P}" > ${dictlst}
129 for entry in "${MYSPELL_SPELLING_DICTIONARIES[@]}"; do
130 set_fields "${entry}" ","
131 echo "DICT ${fields[0]} ${fields[1]} ${fields[2]}" >> ${dictlst}
132 doins ${fields[2]}.aff || die "Missing ${fields[2]}.aff"
133 doins ${fields[2]}.dic || die "Missing ${fields[2]}.dic"
135 for entry in "${MYSPELL_HYPHENATION_DICTIONARIES[@]}"; do
136 set_fields "${entry}" ","
137 echo "HYPH ${fields[0]} ${fields[1]} ${fields[2]}" >> ${dictlst}
138 doins ${fields[2]}.dic || die "Missing ${fields[2]}.dic"
140 for entry in "${MYSPELL_THESAURUS_DICTIONARIES[@]}"; do
141 set_fields "${entry}" ","
142 echo "THES ${fields[0]} ${fields[1]} ${fields[2]}" >> ${dictlst}
143 doins ${fields[2]}.dat || die "Missing ${fields[2]}.dat"
144 doins ${fields[2]}.idx || die "Missing ${fields[2]}.idx"
146 doins ${dictlst} || die "Failed to install ${dictlst}"
147 # Install any txt files (usually README.txt) as documentation
148 for filen in *.txt; do
149 [[ -s ${filen} ]] && dodoc ${filen}
154 # Add entries in dictionary.lst.<lang> to OOo dictionary.lst
155 # and create softlinks indicated by dictionary.lst.<lang>
156 myspell_pkg_postinst() {
157 # Update for known applications
158 if has_version ">=app-eselect/eselect-oodict-20060706"; then
159 if has_version app-office/openoffice; then
160 eselect oodict set myspell-$(get_myspell_lang)
162 if has_version app-office/openoffice-bin; then
163 # On AMD64, openoffice-bin is 32-bit so force ABI
164 has_multilib_profile && ABI=x86
165 eselect oodict set myspell-$(get_myspell_lang) --libdir $(get_libdir)
169 if has_version app-eselect/eselect-oodict; then
170 eselect oodict set myspell-$(get_myspell_lang)
174 # Legacy code for dictionaries installed before eselect-oodict existed
175 # so has to remain for binpkg support. This code is unmaintained -
176 # if you have a problem with it, emerge app-eselect/eselect-oodict.
177 [[ -d ${MYSPELL_OOOBASE} ]] || return
178 # This stuff is here, not in src_install, as the softlinks are
179 # deliberately _not_ listed in the package database.
180 local dictlst entry fields prefix suffix suffixes filen
181 # Note; can only reach this point if ${MYSPELL_DICTBASE}/${dictlst}
182 # was successfully installed
183 dictlst="dictionary.lst.$(get_myspell_lang)"
186 [[ ${fields[0]:0:1} == "#" ]] && continue
187 [[ -f ${MYSPELL_OOOBASE}/dictionary.lst ]] || \
188 touch ${MYSPELL_OOOBASE}/dictionary.lst
189 grep "^${fields[0]} ${fields[1]} ${fields[2]} " \
190 ${MYSPELL_OOOBASE}/dictionary.lst > /dev/null 2>&1 ||
191 echo "${entry}" >> ${MYSPELL_OOOBASE}/dictionary.lst
192 for suffix in $(get_myspell_suffixes ${fields[0]}); do
193 filen="${fields[3]}${suffix}"
194 [[ -h ${MYSPELL_OOOBASE}/${filen} ]] &&
195 rm -f ${MYSPELL_OOOBASE}/${filen}
196 [[ ! -f ${MYSPELL_OOOBASE}/${filen} ]] &&
197 ln -s ${MYSPELL_DICTBASE}/${filen} \
198 ${MYSPELL_OOOBASE}/${filen}
200 done < ${MYSPELL_DICTBASE}/${dictlst}
204 # Remove softlinks and entries in dictionary.lst - uses
205 # dictionary.<lang>.lst from /usr/share/myspell
206 # Done in preinst (prerm happens after postinst, which overwrites
207 # the dictionary.<lang>.lst file)
208 myspell_pkg_preinst() {
209 # Update for known applications
210 if has_version ">=app-eselect/eselect-oodict-20060706"; then
211 if has_version app-office/openoffice; then
212 # When building from source, the default library path is correct
213 eselect oodict unset myspell-$(get_myspell_lang)
215 if has_version app-office/openoffice-bin; then
216 # On AMD64, openoffice-bin is 32-bit, so get 32-bit library directory
217 has_multilib_profile && ABI=x86
218 eselect oodict unset myspell-$(get_myspell_lang) --libdir $(get_libdir)
220 eselect oodict unset myspell-$(get_myspell_lang) --libdir $(get_libdir)
223 # Previous versions of eselect-oodict didn't cater for -bin on amd64
224 if has_version app-eselect/eselect-oodict; then
225 eselect oodict unset myspell-$(get_myspell_lang)
229 # Legacy code for dictionaries installed before eselect-oodict existed
230 # Don't delete this; needed for uninstalls and binpkg support.
231 # This code is unmaintained - if you have a problem with it,
232 # emerge app-eselect/eselect-oodict.
233 local filen dictlst entry fields removeentry suffix
234 dictlst="dictionary.lst.$(get_myspell_lang)"
235 [[ -d ${MYSPELL_OOOBASE} ]] || return
236 [[ -f ${MYSPELL_DICTBASE}/${dictlst} ]] || return
239 [[ ${fields[0]:0:1} == "#" ]] && continue
240 [[ ${fields[3]} == "" ]] && continue
241 # Remove entry from dictionary.lst
242 sed -i -e "/^${fields[0]} ${fields[1]} ${fields[2]} ${fields[3]}$/ { d }" \
243 ${MYSPELL_OOOBASE}/dictionary.lst
244 # See if any other entries in dictionary.lst match the current
245 # dictionary type and filename
246 grep "^${fields[0]} .* ${fields[3]}$" ${MYSPELL_OOOBASE}/dictionary.lst \
247 2>&1 > /dev/null && continue
248 # If no other entries match, remove relevant symlinks
249 for suffix in $(get_myspell_suffixes ${fields[0]}); do
250 filen="${fields[3]}${suffix}"
251 ewarn "Removing entry ${MYSPELL_OOOBASE}/${filen}"
252 [[ -h ${MYSPELL_OOOBASE}/${filen} ]] &&
253 rm -f ${MYSPELL_OOOBASE}/${filen}
255 done < ${MYSPELL_DICTBASE}/${dictlst}