mate-base/mate-common: Drop old
[gentoo.git] / eclass / mozextension.eclass
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 #
4 # @ECLASS: mozextension.eclass
5 # @MAINTAINER:
6 # Mozilla team <mozilla@gentoo.org>
7 # @BLURB: Install extensions for use in mozilla products.
8 #
9 if [[ ! ${_MOZEXTENSION} ]]; then
10
11 # @ECLASS-VARIABLE: MOZEXTENSION_TARGET
12 # @DESCRIPTION:
13 # This variable allows the installation path for xpi_install
14 # to be overridden from the default app-global extensions path.
15 # Default is empty, which installs to predetermined hard-coded
16 # paths specified in the eclass.
17 : ${MOZEXTENSION_TARGET:=""}
18
19 inherit eutils
20
21 DEPEND="app-arch/unzip"
22
23 mozversion_extension_location() {
24         case ${PN} in
25                 firefox|firefox-bin|palemoon)
26                         if [[ $(get_version_component_range 1) -ge 21 ]] ; then
27                                 return 0
28                         fi
29                 ;;
30         esac
31
32         return 1
33 }
34
35 xpi_unpack() {
36         local xpi xpiname srcdir
37
38         # Not gonna use ${A} as we are looking for a specific option being passed to function
39         # You must specify which xpi to use
40         [[ -z "$*" ]] && die "Nothing passed to the $FUNCNAME command. please pass which xpi to unpack"
41
42         for xpi in "$@"; do
43                 einfo "Unpacking ${xpi} to ${PWD}"
44                 xpiname=$(basename ${xpi%.*})
45
46                 if   [[ "${xpi:0:2}" != "./" ]] && [[ "${xpi:0:1}" != "/" ]] ; then
47                         srcdir="${DISTDIR}/"
48                 fi
49
50                 [[ -s "${srcdir}${xpi}" ]] ||  die "${xpi} does not exist"
51
52                 case "${xpi##*.}" in
53                         ZIP|zip|jar|xpi)
54                                 mkdir "${WORKDIR}/${xpiname}" && \
55                                                                            unzip -qo "${srcdir}${xpi}" -d "${WORKDIR}/${xpiname}" ||  die "failed to unpack ${xpi}"
56                                 ;;
57                         *)
58                                 einfo "unpack ${xpi}: file format not recognized. Ignoring."
59                                 ;;
60                 esac
61         done
62 }
63
64
65 xpi_install() {
66         local emid
67
68         # You must tell xpi_install which xpi to use
69         [[ ${#} -ne 1 ]] && die "$FUNCNAME takes exactly one argument, please specify an xpi to unpack"
70
71         x="${1}"
72         #cd ${x}
73         # determine id for extension
74         if [[ -f "${x}"/install.rdf ]]; then
75                 emid="$(sed -n -e '/install-manifest/,$ { /em:id/!d; s/.*[\">]\([^\"<>]*\)[\"<].*/\1/; p; q }' "${x}"/install.rdf)"
76                 [[ -z "${emid}" ]] && die "failed to determine extension id from install.rdf"
77         elif [[ -f "${x}"/manifest.json ]]; then
78                 emid="$( sed -n 's/.*"id": "\(.*\)".*/\1/p' "${x}"/manifest.json )"
79                 [[ -z "${emid}" ]] && die "failed to determine extension id from manifest.json"
80         else
81                 die "failed to determine extension id"
82         fi
83
84         if [[ -n ${MOZEXTENSION_TARGET} ]]; then
85                 insinto "${MOZILLA_FIVE_HOME}"/${MOZEXTENSION_TARGET%/}/${emid}
86         elif $(mozversion_extension_location) ; then
87                 insinto "${MOZILLA_FIVE_HOME}"/browser/extensions/${emid}
88         else
89                 insinto "${MOZILLA_FIVE_HOME}"/extensions/${emid}
90         fi
91         doins -r "${x}"/* || die "failed to copy extension"
92 }
93
94 xpi_copy() {
95         local emid
96
97         # You must tell xpi_install which xpi to use
98         [[ ${#} -ne 1 ]] && die "$FUNCNAME takes exactly one argument, please specify an xpi to unpack"
99
100         x="${1}"
101         #cd ${x}
102         # determine id for extension
103         if [[ -f "${x}"/install.rdf ]]; then
104                 emid="$(sed -n -e '/install-manifest/,$ { /em:id/!d; s/.*[\">]\([^\"<>]*\)[\"<].*/\1/; p; q }' "${x}"/install.rdf)"
105                 [[ -z "${emid}" ]] && die "failed to determine extension id from install.rdf"
106         elif [[ -f "${x}"/manifest.json ]]; then
107                 emid="$(sed -n 's/.*"id": "\([^"]*\)".*/\1/p' "${x}"/manifest.json)"
108                 [[ -z "${emid}" ]] && die "failed to determine extension id from manifest.json"
109         else
110                 die "failed to determine extension id"
111         fi
112
113         if [[ -n ${MOZEXTENSION_TARGET} ]]; then
114                 insinto "${MOZILLA_FIVE_HOME}"/${MOZEXTENSION_TARGET%/}
115         elif $(mozversion_extension_location) ; then
116                 insinto "${MOZILLA_FIVE_HOME}"/browser/extensions
117         else
118                 insinto "${MOZILLA_FIVE_HOME}"/extensions
119         fi
120
121         newins "${DISTDIR%/}"/${x##*/}.xpi ${emid}.xpi
122 }
123
124 _MOZEXTENSION=1
125 fi