Lines 1-59
Link Here
|
1 |
# Copyright 1999-2011 Gentoo Foundation |
1 |
# Copyright 1999-2013 Gentoo Foundation |
2 |
# Distributed under the terms of the GNU General Public License v2 |
2 |
# Distributed under the terms of the GNU General Public License v2 |
3 |
# $Header: /var/cvsroot/gentoo-x86/eclass/mozextension.eclass,v 1.7 2011/12/27 17:55:12 fauli Exp $ |
3 |
# $Header: $ |
4 |
# |
4 |
|
5 |
# @ECLASS: mozextension.eclass |
5 |
# @ECLASS: mozextension.eclass |
6 |
# @MAINTAINER: |
6 |
# @MAINTAINER: |
7 |
# Mozilla team <mozilla@gentoo.org> |
7 |
# Mozilla team <mozilla@gentoo.org> |
8 |
# @DESCRIPTION: |
8 |
# @DESCRIPTION: |
9 |
# Install extensions for use in mozilla products. |
9 |
# Install extensions for use in mozilla products. |
10 |
|
10 |
|
|
|
11 |
# @ECLASS-VARIABLE: MOZ_MOZILLAS |
12 |
# @DESCRIPTION: |
13 |
# If this variables is set to the empty value, no default install functions |
14 |
# are defined. Otherwise, the value of this variable should be |
15 |
# "conkeror firefox seamonkey" (default) |
16 |
# or a subset of these. |
17 |
# The eclass will then install the extension for all these mozillas, |
18 |
# set corresponding dependencies and print corresponding messages. |
19 |
: ${MOZ_MOZILLAS=conkeror firefox seamonkey} |
11 |
|
20 |
|
12 |
inherit eutils |
21 |
# @ECLASS-VARIABLE: MOZ_EXTDIR |
|
|
22 |
# @DESCRIPTION: |
23 |
# If this variable has the special value "*", the extension is copied directly |
24 |
# into the extension directory of the installed MOZILLA's. |
25 |
# Otherwise, only symlinks are made in that directory, and the extension is |
26 |
# installed only once into MOZ_EXTDIR (a default directory is |
27 |
# chosen if MOZ_EXTDIR is empty). |
28 |
# If this variable has the special value "?" (default), it acts like "*" or |
29 |
# "" depending on whether MOZ_MOZILLAS applies to more than 1 installed |
30 |
# mozilla or not. |
31 |
: ${MOZ_EXTDIR=?} |
32 |
|
33 |
inherit eutils multilib |
34 |
|
35 |
case ${EAPI:-0} in |
36 |
[01234]) |
37 |
die "EAPI ${EAPI} no longer supported by ${ECLASS}";; |
38 |
esac |
39 |
|
40 |
|
41 |
RDEPEND="|| (" |
42 |
case "${MOZ_MOZILLAS}" in |
43 |
*fire*) |
44 |
RDEPEND="${RDEPEND} |
45 |
www-client/firefox:= |
46 |
www-client/firefox-bin:=";; |
47 |
esac |
48 |
case "${MOZ_MOZILLAS}" in |
49 |
*sea*) |
50 |
RDEPEND="${RDEPEND} |
51 |
www-client/seamonkey:= |
52 |
www-client/seamonkey-bin:=";; |
53 |
esac |
54 |
case "${MOZ_MOZILLAS}" in |
55 |
*conkeror*) |
56 |
RDEPEND="${RDEPEND} |
57 |
www-client/conkeror:=";; |
58 |
esac |
59 |
|
60 |
RDEPEND="${RDEPEND} |
61 |
)" |
13 |
|
62 |
|
14 |
DEPEND="app-arch/unzip" |
63 |
DEPEND="app-arch/unzip" |
|
|
64 |
[ -n "${RDEPEND}" ] && DEPEND="${DEPEND} |
65 |
${RDEPEND}" |
66 |
|
67 |
[ "${MOZ_EXTDIR}" = '*' ] || IUSE='copy-extensions symlink-extensions' |
68 |
|
69 |
mozextension_src_unpack() { |
70 |
local i |
71 |
if [ -z "${FILENAME}" ] |
72 |
then for i in ${SRC_URI} |
73 |
do FILENAME=${i##*/} |
74 |
done |
75 |
fi |
76 |
xpi_unpack "${FILENAME}" |
77 |
} |
78 |
|
79 |
mozextension_src_prepare() { |
80 |
epatch_user |
81 |
} |
82 |
|
83 |
EXPORT_FUNCTIONS src_unpack src_prepare |
84 |
|
85 |
declare -a MOZ_INS MOZ_PKG MOZ_CPY MOZ_DIR |
86 |
|
87 |
mozextension_install() { |
88 |
local MOZILLA_EXTENSIONS_DIRECTORY |
89 |
MOZILLA_EXTENSIONS_DIRECTORY=${1} |
90 |
MOZ_INS=() |
91 |
xpi_install_dirs |
92 |
} |
93 |
|
94 |
mozextension_calc() { |
95 |
local v |
96 |
case ${MOZ_MOZILLAS} in |
97 |
${1}) |
98 |
false;; |
99 |
esac && return |
100 |
v=`best_version "${2}"` && [ -n "${v}" ] || return |
101 |
MOZ_PKG+=("${v}") |
102 |
MOZ_DIR+=("${3}") |
103 |
} |
104 |
|
105 |
mozextension_src_install() { |
106 |
local b d e i j k l s |
107 |
MOZ_PKG=() |
108 |
MOZ_DIR=() |
109 |
b="${EPREFIX%/}/usr/`get_libdir`/" |
110 |
e="${EPREFIX%/}/opt/" |
111 |
mozextension_calc '*fire*' 'www-client/firefox' "${b}firefox" |
112 |
mozextension_calc '*fire*' 'www-client/firefox-bin' "${e}firefox" |
113 |
mozextension_calc '*sea*' 'www-client/seamonkey' "${b}seamonkey" |
114 |
mozextension_calc '*sea*' 'www-client/seamonkey-bin' "${e}seamonkey" |
115 |
mozextension_calc '*conkeror*' 'www-client/conkeror' "/usr/share/conkeror" |
116 |
[ ${#MOZ_DIR[@]} -ne 0 ] || die 'no supported mozilla is installed' |
117 |
d=${MOZ_EXTDIR} |
118 |
if [ "${d}" = '?' ] |
119 |
then if [ ${#MOZ_PKG[@]} -gt 1 ] |
120 |
then d='' |
121 |
else d='*' |
122 |
fi |
123 |
fi |
124 |
MOZ_SYM=() |
125 |
MOZ_LNK=false |
126 |
if [ "${d}" = '*' ] || ! use symlink-extensions |
127 |
then MOZ_CPY=: |
128 |
else MOZ_CPY=false |
129 |
if [ -n "${d}" ] |
130 |
then mozextension_install "${d}" |
131 |
else mozextension_install "${b}mozilla/extensions" |
132 |
fi |
133 |
fi |
134 |
use copy-extensions || MOZ_LNK=: |
135 |
for i in "${MOZ_DIR[@]}" |
136 |
do j="${i}/extensions" |
137 |
${MOZ_CPY} && mozextension_install "${j}" |
138 |
for k in "${MOZ_INS[@]}" |
139 |
do l="${j}/${k##*/}" |
140 |
MOZ_SYM+=("${l}") |
141 |
${MOZ_CPY} || dosym "${ROOT%/}${k}" "${l}" |
142 |
done |
143 |
done |
144 |
} |
145 |
|
146 |
mozextension_pkg_preinst() { |
147 |
local i j |
148 |
einfo 'checking for switching between dirs and symlinks' |
149 |
for i in "${MOZ_SYM[@]}" |
150 |
do j=${ROOT%/}${i} |
151 |
# There are two forms of installation: |
152 |
# (1) symlink mozilla-dir/extensions/X -> $MOZILLA_EXTENSIONS_DIRECTORY/X |
153 |
# (2) data in mozilla-dir/extensions/X |
154 |
# Since we might switch between (1) and (2), we must take caution, since |
155 |
# in general portage cannot merge into the live directory properly: |
156 |
if ${MOZ_CPY} |
157 |
then test -L "${j}" && { |
158 |
# We switched from (1) to (2). If this happened, portage would |
159 |
# actually merge the data of (2) into $MOZILLA_EXTENSIONS_DIRECTORY/X, |
160 |
# since this is where the symlink from (1) points to. |
161 |
# Hence, we have to remove this symlink in advance, in this case. |
162 |
rm -v -- "${j}" |
163 |
} |
164 |
else test -d "${j}" && ! test -L "${j}" && { |
165 |
# We switched from (2) to (1). If this happened, portage cannot |
166 |
# merge the symlink to the live system, since this can only happen once |
167 |
# the directory mozilla-dir/extensions/X is removed. |
168 |
# We could remove this directory here. |
169 |
# However, removing a directory is a dangerous thing, and so |
170 |
# we prefer to tell the user only that he has to reemerge the package. |
171 |
eerror |
172 |
eerror "It is necessary to reemerge again ${CATEGORY}/${PN}" |
173 |
eerror '(a directory should be removed in the cleanup after the first emerge' |
174 |
eerror 'in order to install a symlink of the same name in the second emerge.)' |
175 |
eerror |
176 |
break |
177 |
} |
178 |
fi |
179 |
done |
180 |
} |
181 |
|
182 |
mozextension_pkg_postinst() { |
183 |
local i |
184 |
[ "${#MOZ_PKG[@]}" -ge 1 ] || die 'no supported mozilla is installed' |
185 |
elog "${CATEGORY}/${PN} has been installed for the following packages:" |
186 |
for i in ${MOZ_PKG[@]} |
187 |
do elog " ${i}" |
188 |
done |
189 |
elog "When you install/uninstall/reemerge some of: ${MOZ_MOZILLAS}" |
190 |
elog "you might need to reemerge ${CATEGORY}/${PN}" |
191 |
${MOZ_CPY} || { |
192 |
elog |
193 |
elog 'The extension was installed using symlinks. This saves space but may require' |
194 |
elog 'to remove ~/.mozilla/*/*/extensions.ini for each browser restart.' |
195 |
} |
196 |
} |
197 |
|
198 |
if [ -n "${MOZ_MOZILLAS}" ] |
199 |
then EXPORT_FUNCTIONS src_install pkg_preinst pkg_postinst |
200 |
fi |
15 |
|
201 |
|
16 |
xpi_unpack() { |
202 |
xpi_unpack() { |
17 |
local xpi xpiname srcdir |
203 |
local xpi srcdir |
18 |
|
204 |
|
19 |
# Not gonna use ${A} as we are looking for a specific option being passed to function |
205 |
# Not gonna use ${A} as we are looking for a specific option being passed to function |
20 |
# You must specify which xpi to use |
206 |
# You must specify which xpi to use |
21 |
[[ -z "$*" ]] && die "Nothing passed to the $FUNCNAME command. please pass which xpi to unpack" |
207 |
[ ${#} -eq 0 ] && die \ |
22 |
|
208 |
"Nothing passed to the ${FUNCNAME} command. Please pass which xpi to unpack" |
23 |
for xpi in "$@"; do |
|
|
24 |
einfo "Unpacking ${xpi} to ${PWD}" |
25 |
xpiname=$(basename ${xpi%.*}) |
26 |
|
209 |
|
27 |
if [[ "${xpi:0:2}" != "./" ]] && [[ "${xpi:0:1}" != "/" ]] ; then |
210 |
test -d "${S}" || mkdir "${S}" |
28 |
srcdir="${DISTDIR}/" |
211 |
for xpi |
29 |
fi |
212 |
do einfo "Unpacking ${xpi} to ${S}" |
|
|
213 |
xpiname=${xpi%.*} |
214 |
xpiname=${xpiname##*/} |
215 |
|
216 |
case ${xpi} in |
217 |
./*|/*) |
218 |
srcdir='';; |
219 |
*) |
220 |
srcdir="${DISTDIR}/";; |
221 |
esac |
30 |
|
222 |
|
31 |
[[ -s "${srcdir}${xpi}" ]] || die "${xpi} does not exist" |
223 |
test -s "${srcdir}${xpi}" || die "${xpi} does not exist" |
32 |
|
224 |
|
33 |
case "${xpi##*.}" in |
225 |
case ${xpi##*.} in |
34 |
ZIP|zip|jar|xpi) |
226 |
ZIP|zip|jar|xpi) |
35 |
mkdir "${WORKDIR}/${xpiname}" && \ |
227 |
mkdir -- "${S}/${xpiname}" && \ |
36 |
unzip -qo "${srcdir}${xpi}" -d "${WORKDIR}/${xpiname}" || die "failed to unpack ${xpi}" |
228 |
cd -- "${S}/${xpiname}" && \ |
37 |
;; |
229 |
unzip -qo -- "${srcdir}${xpi}" \ |
38 |
*) |
230 |
|| die "failed to unpack ${xpi}" |
39 |
einfo "unpack ${xpi}: file format not recognized. Ignoring." |
231 |
chmod -R a+rX,u+w,go-w -- "${S}/${xpiname}";; |
40 |
;; |
232 |
*) |
|
|
233 |
einfo "unpack ${xpi}: file format not recognized. Ignoring.";; |
41 |
esac |
234 |
esac |
42 |
done |
235 |
done |
43 |
} |
236 |
} |
44 |
|
237 |
|
45 |
|
|
|
46 |
xpi_install() { |
238 |
xpi_install() { |
47 |
local emid |
239 |
local d x |
48 |
|
240 |
|
49 |
# You must tell xpi_install which xpi to use |
241 |
# You must tell xpi_install which dir to use |
50 |
[[ ${#} -ne 1 ]] && die "$FUNCNAME takes exactly one argument, please specify an xpi to unpack" |
242 |
[ ${#} -ne 1 ] && die "${FUNCNAME} takes exactly one argument. Please specify the directory" |
51 |
|
243 |
|
52 |
x="${1}" |
244 |
x=${1} |
53 |
cd ${x} |
|
|
54 |
# determine id for extension |
245 |
# determine id for extension |
55 |
emid="$(sed -n -e '/install-manifest/,$ { /em:id/!d; s/.*[\">]\([^\"<>]*\)[\"<].*/\1/; p; q }' "${x}"/install.rdf)" \ |
246 |
d='{ /\<\(em:\)*id\>/!d; s/.*[\">]\([^\"<>]*\)[\"<].*/\1/; p; q }' |
56 |
|| die "failed to determine extension id" |
247 |
d=`sed -n -e '/install-manifest/,$ '"${d}" "${x}"/install.rdf` \ |
57 |
insinto "${MOZILLA_FIVE_HOME}"/extensions/${emid} |
248 |
&& [ -n "${d}" ] || die 'failed to determine extension id' |
58 |
doins -r "${x}"/* || die "failed to copy extension" |
249 |
if [ -n "${MOZILLA_EXTENSIONS_DIRECTORY}" ] |
|
|
250 |
then d="${MOZILLA_EXTENSIONS_DIRECTORY}/${d}" |
251 |
MOZ_INS+=("${d}") |
252 |
else d="${MOZILLA_FIVE_HOME}/extensions/${d}" |
253 |
fi |
254 |
test -d "${D}${d}" || dodir "${d}" || die "failed to create ${d}" |
255 |
${MOZ_LNK} && cp -RPl -- "${x}"/* "${D}${d}" || { |
256 |
${MOZ_LNK} && \ |
257 |
ewarn 'Failed to hardlink extension. Falling back to USE=copy-extensions' |
258 |
insinto "${d}" && doins -r "${x}"/* |
259 |
} || { |
260 |
${MOZ_LNK} && \ |
261 |
die 'failed to copy extension. Please retry emerging with USE=copy-extensions' |
262 |
die 'failed to copy extension' |
263 |
} |
264 |
} |
265 |
|
266 |
# This function is called by mozextension_src_install |
267 |
# and should be overridden if the paths do not match: |
268 |
# It just should call xpi_install with the correct argument(s) |
269 |
xpi_install_dirs() { |
270 |
local d |
271 |
for d in "${S}"/* |
272 |
do [ -n "${d}" ] && test -d "${d}" && xpi_install "${d}" |
273 |
done |
59 |
} |
274 |
} |