summaryrefslogtreecommitdiff
blob: 7e58de6d5dbf29e6076f3b2163424d38656e1323 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# Copyright 1999-2015 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id$

# @ECLASS: moz.eclass
# @MAINTAINER:
# Martin Väth <martin@mvath.de>
# @BLURB: This eclass provides functions to install mozilla extensions
# @DESCRIPTION:
# The eclass is based on mozextension.eclass with many extensions
# and compatiblity fixes.
# @EXAMPLE:
# @CODE
# inherit moz
#
# moz_defaults firefox seamonkey # no arguments mean all browsers
#
# @CODE
# inherit moz
#
# MOZ="firefox seamonkey"
# DEPEND=${MOZ_DEPEND}
# RDEPEND=$(moz_rdepend ${MOZ})
# IUSE=$(moz_iuse ${MOZ})
# REQUIRED_USE=$(moz_required_use ${MOZ})
#
# src_unpack() {
#	moz_unpack
# }
#
# src_install() {
#	default
#	moz_install
# }

case ${EAPI:-0} in
[0-5])
	die "EAPI ${EAPI} not supported by ${ECLASS}";;
esac

# @FUNCTION: moz_defaults
# @USAGE: [<browser>] [<browser>] [...]
# @DESCRIPTION:
# This is just a convenience wrapper for moz_variables [arguments]; moz_phases
moz_defaults() {
	moz_variables "${@}"
	moz_phases
}

# @FUNCTION: moz_variables
# @USAGE: [<browser>] [<browser>] [...]
# @DESCRIPTION:
# Sets the variables DEPEND, RDEPEND, IUSE, REQUIRED_USE for browsers.
# browser is firefox or seamonkey and implies source or binary version.
# If no browser is specified, all are assumed.
moz_variables() {
	DEPEND=${MOZ_DEPEND}
	RDEPEND=$(moz_rdepend "${@}")
	IUSE=$(moz_iuse "${@}")
	REQUIRED_USE=$(moz_required_use "${@}")
}

# @FUNCTION: moz_phases
# @USAGE: [<browser>] [<browser>] [...]
# @DESCRIPTION:
# Defines src_unpack and src_install to call only moz_unpack and moz_install
moz_phases() {
src_unpack() {
moz_unpack
}
src_install() {
default
moz_install
}
}

# @ECLASS-VARIABLE: MOZ_DEPEND
# @DESCRIPTION:
# This is an eclass-generated depend expression needed for moz_unpack to work
MOZ_DEPEND='app-arch/unzip'

# @FUNCTION: moz_rdepend
# @USAGE: [<browser>] [<browser>] [...]
# @DESCRIPTION:
# Outputs RDEPEND expression appropriate for browsers.
# browser is [firefox|seamonkey][-source|-bin] (no specified means both/all)
moz_rdepend() {
	local rdep i
	[ ${#} -ne 0 ] || set -- "firefox seamonkey"
	i=
	rdep=
	case "${*}" in
	*firefox?source*)
		i=a
		rdep="browser_firefox? ( www-client/firefox )";;
	*firefox?bin*)
		i=a
		rdep="browser_firefox-bin? ( www-client/firefox-bin )";;
	*firefox*)
		i=aa
		rdep="browser_firefox? ( www-client/firefox )
browser_firefox-bin? ( www-client/firefox-bin )";;
	esac
	case "${*}" in
	*seamonkey?source*)
		i=${i}a
		rdep=${rdep}${rdep:+'
'}"browser_seamonkey? ( www-client/seamonkey )";;
	*seamonkey?bin*)
		i=${i}a
		rdep=${rdep}${rdep:+'
'}"browser_seamonkey-bin? ( www-client/seamonkey-bin )";;
	*seamonkey*)
		i=${i}aa
		rdep=${rdep}${rdep:+'
'}"browser_seamonkey? ( www-client/seamonkey )
browser_seamonkey-bin? ( www-client/seamonkey-bin )";;
	esac
	[ -n "${i}" ] || die "args must be [firefox|seamonkey][-source|-bin]"
	[ "${i}" = a ] && echo "${rdep}" || echo "|| ( ${rdep} )"
}

# @FUNCTION: moz_iuse
# @USAGE: [<browser>] [<browser>] [...]
# @DESCRIPTION:
# Outputs IUSE expression appropriate for browsers.
# browser is [firefox|seamonkey][-source|-bin] (no specified means both/all)
moz_iuse() {
	local iuse i
	[ ${#} -ne 0 ] || set -- "firefox seamonkey"
	iuse=
	case "${*}" in
	*firefox?source*)
		iuse="browser_firefox";;
	*firefox?bin*)
		iuse="browser_firefox-bin";;
	*firefox*)
		iuse="browser_firefox browser_firefox-bin";;
	esac
	case "${*}" in
	*seamonkey?source*)
		iuse="${iuse}${iuse:+ }browser_seamonkey";;
	*seamonkey?bin*)
		iuse="${iuse}${iuse:+ }browser_seamonkey-bin";;
	*seamonkey*)
		iuse="${iuse}${iuse:+ }browser_seamonkey browser_seamonkey-bin";;
	esac
	[ -n "${iuse}" ] || die "args must be [firefox|seamonkey][-source|-bin]"
	echo "${iuse}"
}

# @FUNCTION: moz_required_use
# @USAGE: [<browser>] [<browser>] [...]
# @DESCRIPTION:
# Outputs REQUIRED_USE expression appropriate for browsers.
# browser is [firefox|seamonkey][-source|-bin] (no specified means both/all)
moz_required_use() {
	set -- $(moz_iuse "${@}")
	[ ${#} -lt 2 ] && echo "${*}" || echo "|| ( ${*} )"
}

# @FUNCTION: moz_unpack
# @USAGE: <file> <file> [...]
# @DESCRIPTION:
# Unpack xpi files. If no file is specified, ${A} is used.
moz_unpack() {
	local xpi srcdir xpiname

	[ ${#} -ne 0 ] || set -- ${A}
	test -d "${S}" || mkdir "${S}" || die "cannot create ${S}"
	for xpi
	do	einfo "Unpacking ${xpi} to ${S}"
		xpiname=${xpi%.*}
		xpiname=${xpiname##*/}

		case ${xpi} in
		./*|/*)
			srcdir=;;
		*)
			srcdir="${DISTDIR}/";;
		esac

		test -f "${srcdir}${xpi}" || die "${xpi} does not exist or is no file"

		case ${xpi##*.} in
		ZIP|zip|jar|xpi)
			mkdir -- "${S}/${xpiname}" && \
				cd -- "${S}/${xpiname}" && \
				unzip -qo -- "${srcdir}${xpi}" \
					|| die "failed to unpack ${xpi}"
			chmod -R a+rX,u+w,go-w -- "${S}/${xpiname}";;
		*)
			einfo "unpack ${xpi}: file format not recognized. Ignoring.";;
		esac
	done
}

# @FUNCTION: moz_install_to_dir
# @USAGE: <extension-directory> <dir> <dir> [...]
# @DESCRIPTION:
# Installs dirs into a subdirectory (id) of extension-directory,
# the name of the id being determined from ${dir}/install.rdf
# Arguments which are not directories are silently ignored.
# If arguments are specified, they must contain at least one directory.
# If no argument is specified, all directories from "${S}" are considered.
moz_install_to_dir() {
	local sub dest i s have
	[ ${#} -ne 0 ] || die "${FUNCNAME} needs at least one argument"
	dest=${1}
	shift
	[ ${#} -gt 0 ] || set -- "${S}"/*
	s='{ /\<\(em:\)*id\>/!d; s/.*[\">]\([^\"<>]*\)[\"<].*/\1/; p; q }'
	have=false
	for i
	do	[ -n "${i}" ] && test -d "${i}" || continue
		have=:
		test -r "${i}"/install.rdf && \
			sub=$(sed -n -e '/install-manifest/,$ '"${s}" "${i}"/install.rdf) \
				&& [ -n "${sub}" ] || die 'failed to determine id of ${i}'
		sub=${dest%/}/${sub}
		dodir "${sub}" || die "failed to create ${sub}"
		cp -RPl -- "${i}"/* "${ED}${sub}" || {
			insinto "${sub}" && doins -r "${x}"/*
		} || die "failed to install extension ${i}"
	done
	${have} || die "no directory found in argument list"
}

# @FUNCTION: moz_install_for_browser
# @USAGE: <browser> <dir> <dir> [...]
# @DESCRIPTION:
# Installs dirs for browser (firefox firefox-bin seamonkey seamonkey-bin)
# Arguments which are not directories are silently ignored.
# If arguments are specified, they must contain at least one directory.
# If no argument is specified, all directories from "${S}" are considered.
moz_install_for_browser() {
	local dest firefox seamonkey
	[ ${#} -ne 0 ] || die "${FUNCNAME} needs at least one argument"
	firefox="firefox/browser/extensions"
	seamonkey="seamonkey/extensions"
	case ${1} in
	firefox)
		dest="/usr/$(get_libdir)/${firefox}";;
	firefox?bin)
		dest="/opt/${firefox}";;
	seamonkey)
		dest="/usr/$(get_libdir)/${seamonkey}";;
	seamonkey?bin)
		dest="/opt/${seamonkey}";;
	*)
		die "unknown browser specified";;
	esac
	shift
	moz_install_to_dir "${dest}" "${@}"
}

# @FUNCTION: moz_install
# @USAGE: <dir> <dir> [...]
# @DESCRIPTION:
# Installs dirs into appropriate destinations, depending on USE.
# Arguments which are not directories are silently ignored.
# If arguments are specified, they must contain at least one directory.
# If no argument is specified, all directories from "${S}" are considered.
moz_install() {
	local i
	for i in firefox firefox-bin seamonkey seamonkey-bin
	do	if in_iuse "browser_${i}" && use "browser_${i}"
		then	moz_install_for_browser "${i}" "${@}"
		fi
	done
}