1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: xdg-utils.eclass
8 # Original author: Gilles Dartiguelongue <eva@gentoo.org>
9 # @SUPPORTED_EAPIS: 0 1 2 3 4 5 6 7
10 # @BLURB: Auxiliary functions commonly used by XDG compliant packages.
12 # This eclass provides a set of auxiliary functions needed by most XDG
14 # It provides XDG stack related functions such as:
15 # * GTK/Qt5 icon theme cache management
16 # * XDG .desktop files cache management
17 # * XDG mime information database management
21 *) die "EAPI=${EAPI} is not supported" ;;
24 # @ECLASS-VARIABLE: DESKTOP_DATABASE_DIR
27 # Directory where .desktop files database is stored
28 : ${DESKTOP_DATABASE_DIR="/usr/share/applications"}
30 # @ECLASS-VARIABLE: MIMEINFO_DATABASE_DIR
33 # Directory where .desktop files database is stored
34 : ${MIMEINFO_DATABASE_DIR:="/usr/share/mime"}
36 # @FUNCTION: xdg_environment_reset
38 # Clean up environment for clean builds.
39 xdg_environment_reset() {
40 # Prepare XDG base directories
41 export XDG_DATA_HOME="${HOME}/.local/share"
42 export XDG_CONFIG_HOME="${HOME}/.config"
43 export XDG_CACHE_HOME="${HOME}/.cache"
44 export XDG_RUNTIME_DIR="${T}/run"
45 mkdir -p "${XDG_DATA_HOME}" "${XDG_CONFIG_HOME}" "${XDG_CACHE_HOME}" \
46 "${XDG_RUNTIME_DIR}" || die
47 # This directory needs to be owned by the user, and chmod 0700
48 # https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
49 chmod 0700 "${XDG_RUNTIME_DIR}" || die
51 unset DBUS_SESSION_BUS_ADDRESS
54 # @FUNCTION: xdg_desktop_database_update
56 # Updates the .desktop files database.
57 # Generates a list of mimetypes linked to applications that can handle them
58 xdg_desktop_database_update() {
59 if [[ ${EBUILD_PHASE} != post* ]] ; then
60 die "xdg_desktop_database_update must be used in pkg_post* phases."
63 if ! type update-desktop-database &>/dev/null; then
64 debug-print "update-desktop-database is not found"
68 ebegin "Updating .desktop files database"
69 update-desktop-database -q "${EROOT%/}${DESKTOP_DATABASE_DIR}"
73 # @FUNCTION: xdg_icon_cache_update
75 # Updates icon theme cache files under /usr/share/icons.
76 # This function should be called from pkg_postinst and pkg_postrm.
77 xdg_icon_cache_update() {
78 if [[ ${EBUILD_PHASE} != post* ]] ; then
79 die "xdg_icon_cache_update must be used in pkg_post* phases."
82 if ! type gtk-update-icon-cache &>/dev/null; then
83 debug-print "gtk-update-icon-cache is not found"
87 ebegin "Updating icons cache"
90 for dir in "${EROOT%/}"/usr/share/icons/*
92 if [[ -f "${dir}/index.theme" ]] ; then
94 gtk-update-icon-cache -qf "${dir}"
96 if [[ ! $rv -eq 0 ]] ; then
97 debug-print "Updating cache failed on ${dir}"
98 # Add to the list of failures
102 elif [[ $(ls "${dir}") = "icon-theme.cache" ]]; then
103 # Clear stale cache files after theme uninstallation
104 rm "${dir}/icon-theme.cache"
106 if [[ -z $(ls "${dir}") ]]; then
107 # Clear empty theme directories after theme uninstallation
112 for f in "${fails[@]}" ; do
113 eerror "Failed to update cache with icon $f"
117 # @FUNCTION: xdg_mimeinfo_database_update
119 # Update the mime database.
120 # Creates a general list of mime types from several sources
121 xdg_mimeinfo_database_update() {
122 if [[ ${EBUILD_PHASE} != post* ]] ; then
123 die "xdg_mimeinfo_database_update must be used in pkg_post* phases."
126 if ! type update-mime-database &>/dev/null; then
127 debug-print "update-mime-database is not found"
131 ebegin "Updating shared mime info database"
132 update-mime-database "${EROOT%/}${MIMEINFO_DATABASE_DIR}"