blob: 9b13f62bdab1aadb86eea603ea6c7c2c611f397a [file] [log] [blame]
Patrick Williams92b42cb2022-09-03 06:53:57 -05001#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
7#
8# This class is used by recipes installing mime types
9#
10
11DEPENDS += "${@bb.utils.contains('BPN', 'shared-mime-info', '', 'shared-mime-info', d)}"
12PACKAGE_WRITE_DEPS += "shared-mime-info-native"
13MIMEDIR = "${datadir}/mime"
14
15mime_postinst() {
16if [ "x$D" != "x" ]; then
17 $INTERCEPT_DIR/postinst_intercept update_mime_database ${PKG} \
18 mlprefix=${MLPREFIX} \
19 mimedir=${MIMEDIR}
20else
21 echo "Updating MIME database... this may take a while."
22 update-mime-database $D${MIMEDIR}
23fi
24}
25
26mime_postrm() {
27if [ "x$D" != "x" ]; then
28 $INTERCEPT_DIR/postinst_intercept update_mime_database ${PKG} \
29 mlprefix=${MLPREFIX} \
30 mimedir=${MIMEDIR}
31else
32 echo "Updating MIME database... this may take a while."
33 # $D${MIMEDIR}/packages belong to package shared-mime-info-data,
34 # packages like libfm-mime depend on shared-mime-info-data.
35 # after shared-mime-info-data uninstalled, $D${MIMEDIR}/packages
36 # is removed, but update-mime-database need this dir to update
37 # database, workaround to create one and remove it later
38 if [ ! -d $D${MIMEDIR}/packages ]; then
39 mkdir -p $D${MIMEDIR}/packages
40 update-mime-database $D${MIMEDIR}
41 rmdir --ignore-fail-on-non-empty $D${MIMEDIR}/packages
42 else
43 update-mime-database $D${MIMEDIR}
44fi
45fi
46}
47
48python populate_packages:append () {
49 packages = d.getVar('PACKAGES').split()
50 pkgdest = d.getVar('PKGDEST')
51 mimedir = d.getVar('MIMEDIR')
52
53 for pkg in packages:
54 mime_packages_dir = '%s/%s%s/packages' % (pkgdest, pkg, mimedir)
55 mimes_types_found = False
56 if os.path.exists(mime_packages_dir):
57 for f in os.listdir(mime_packages_dir):
58 if f.endswith('.xml'):
59 mimes_types_found = True
60 break
61 if mimes_types_found:
62 bb.note("adding mime postinst and postrm scripts to %s" % pkg)
63 postinst = d.getVar('pkg_postinst:%s' % pkg)
64 if not postinst:
65 postinst = '#!/bin/sh\n'
66 postinst += d.getVar('mime_postinst')
67 d.setVar('pkg_postinst:%s' % pkg, postinst)
68 postrm = d.getVar('pkg_postrm:%s' % pkg)
69 if not postrm:
70 postrm = '#!/bin/sh\n'
71 postrm += d.getVar('mime_postrm')
72 d.setVar('pkg_postrm:%s' % pkg, postrm)
73 if pkg != 'shared-mime-info-data':
74 bb.note("adding shared-mime-info-data dependency to %s" % pkg)
75 d.appendVar('RDEPENDS:' + pkg, " " + d.getVar('MLPREFIX')+"shared-mime-info-data")
76}