summaryrefslogtreecommitdiff
blob: 7d3ab08de7770a849c62474a3aecdd10a15f9e6a (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
# Copyright 1999-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id$

# @ECLASS: mv_mozextension.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.
# 1. It has some compatibility fixes in xpi_install/xpi_unpack.
# 2. A default src_unpack function is defined; set FILENAME to the archive name.
#    If FILENAME is unset or empty, the last part of the last SRC_URI is used.
# 3. Default functions for installation for all mozilla type browsers.

# @ECLASS-VARIABLE: MV_MOZ_MOZILLAS
# @DESCRIPTION:
# If this variables is set to the empty value, no default install functions
# are defined. Otherwise, the value of this variable should be
# "firefox seamonkey" (default)
# or a subset of these.
# The eclass will then install the extension for all these mozillas,
# set corresponding dependencies and print corresponding messages.
: ${MV_MOZ_MOZILLAS=firefox seamonkey}

inherit eutils multilib

case ${EAPI:-0} in
[01234])
	die "EAPI ${EAPI} no longer supported by ${ECLASS}";;
esac

MV_MOZ_IUSE=
RDEPEND='|| ('
case ${MV_MOZ_MOZILLAS} in
*fire*)
	MV_MOZ_IUSE="${MV_MOZ_IUSE}${MV_MOZ_IUSE:+ }firefox firefox-bin"
	RDEPEND="${RDEPEND}
	firefox? ( >=www-client/firefox-21 )
	firefox-bin? ( >=www-client/firefox-bin-21 )"
esac
case ${MV_MOZ_MOZILLAS} in
*sea*)
	MV_MOZ_IUSE="${MV_MOZ_IUSE}${MV_MOZ_IUSE:+ }seamonkey seamonkey-bin"
	RDEPEND="${RDEPEND}
	seamonkey? ( www-client/seamonkey )
	seamonkey-bin? ( www-client/seamonkey-bin )"
esac
RDEPEND="${RDEPEND} )"
IUSE=${MV_MOZ_IUSE}
REQUIRED_USE="|| ( ${MV_MOZ_IUSE} )"

DEPEND='app-arch/unzip'

mv_mozextension_src_unpack() {
	local i
	if [ -z "${FILENAME}" ]
	then	for i in ${SRC_URI}
		do	FILENAME=${i##*/}
		done
	fi
	xpi_unpack "${FILENAME}"
}

mv_mozextension_src_prepare() {
	epatch_user
}

EXPORT_FUNCTIONS src_unpack src_prepare

mv_mozextension_src_install() {
	local b e
	b="${EPREFIX}/usr/$(get_libdir)"
	e="${EPREFIX}/opt"
	mv_mozextension_install firefox "${b}/firefox/browser/extensions"
	mv_mozextension_install firefox-bin "${e}/firefox/browser/extensions"
	mv_mozextension_install seamonkey "${b}/seamonkey/extensions"
	mv_mozextension_install seamonkey-bin "${e}/seamonkey/extensions"
}

[ -z "${MV_MOZ_MOZILLAS}" ] || EXPORT_FUNCTIONS src_install

xpi_unpack() {
	local xpi srcdir u

	# Not gonna use ${A} as we are looking for a specific option being passed to function
	# You must specify which xpi to use
	[ ${#} -eq 0 ] && die \
		"Nothing passed to the ${FUNCNAME} command. Please pass which xpi to unpack"

	test -d "${S}" || mkdir "${S}" || die
	for xpi
	do	einfo "Unpacking ${xpi} to ${S}"
		xpiname=${xpi%.*}
		xpiname=${xpiname##*/}

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

		test -s "${srcdir}${xpi}" ||  die "${xpi} does not exist"

		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
}

xpi_install() {
	local d x

	# You must tell xpi_install which dir to use
	[ ${#} -eq 1 ] || die "${FUNCNAME} takes exactly one argument. Please specify the directory"

	x=${1}
	# determine id for extension
	d='{ /\<\(em:\)*id\>/!d; s/.*[\">]\([^\"<>]*\)[\"<].*/\1/; p; q }'
	d=$(sed -n -e '/install-manifest/,$ '"${d}" "${x}"/install.rdf) \
		&& [ -n "${d}" ] || die 'failed to determine extension id'
	: ${MOZILLA_EXTENSIONS_DIRECTORY:="${MOZILLA_FIVE_HOME}/extensions"}
	d="${MOZILLA_EXTENSIONS_DIRECTORY}/${d}"
	test -d "${D}${d}" || dodir "${d}" || die "failed to create ${d}"
	cp -RPl -- "${x}"/* "${D}${d}" || {
		ewarn 'Failed to hardlink extension. Falling back to USE=copy-extensions'
		insinto "${d}" && doins -r "${x}"/*
	} || die 'failed to copy extension'
}

# This function is called by mv_mozextension_src_install
# and should be overridden if the paths do not match:
# It just should call xpi_install with the correct argument(s)
xpi_install_dirs() {
	local d
	for d in "${S}"/*
	do	[ -n "${d}" ] && test -d "${d}" && xpi_install "${d}"
	done
}

mv_mozextension_install() {
	local MOZILLA_EXTENSIONS_DIRECTORY
	has "${1}" ${MV_MOZ_IUSE} && use "${1}" || return 0
	MOZILLA_EXTENSIONS_DIRECTORY=${2}
	xpi_install_dirs
}