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