net-irc/limnoria: use HTTPS for GitHub and HOMEPAGE
[gentoo.git] / eclass / xdg-utils.eclass
1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: xdg-utils.eclass
5 # @MAINTAINER:
6 # gnome@gentoo.org
7 # @AUTHOR:
8 # Original author: Gilles Dartiguelongue <eva@gentoo.org>
9 # @BLURB: Auxiliary functions commonly used by XDG compliant packages.
10 # @DESCRIPTION:
11 # This eclass provides a set of auxiliary functions needed by most XDG
12 # compliant packages.
13 # It provides XDG stack related functions such as:
14 #  * XDG .desktop files cache management
15 #  * XDG mime information database management
16
17 case "${EAPI:-0}" in
18         0|1|2|3|4|5|6) ;;
19         *) die "EAPI=${EAPI} is not supported" ;;
20 esac
21
22 # @ECLASS-VARIABLE: DESKTOP_DATABASE_UPDATE_BIN
23 # @INTERNAL
24 # @DESCRIPTION:
25 # Path to update-desktop-database
26 : ${DESKTOP_DATABASE_UPDATE_BIN:="/usr/bin/update-desktop-database"}
27
28 # @ECLASS-VARIABLE: DESKTOP_DATABASE_DIR
29 # @INTERNAL
30 # @DESCRIPTION:
31 # Directory where .desktop files database is stored
32 : ${DESKTOP_DATABASE_DIR="/usr/share/applications"}
33
34 # @ECLASS-VARIABLE: MIMEINFO_DATABASE_UPDATE_BIN
35 # @INTERNAL
36 # @DESCRIPTION:
37 # Path to update-mime-database
38 : ${MIMEINFO_DATABASE_UPDATE_BIN:="/usr/bin/update-mime-database"}
39
40 # @ECLASS-VARIABLE: MIMEINFO_DATABASE_DIR
41 # @INTERNAL
42 # @DESCRIPTION:
43 # Directory where .desktop files database is stored
44 : ${MIMEINFO_DATABASE_DIR:="/usr/share/mime"}
45
46 # @FUNCTION: xdg_environment_reset
47 # @DESCRIPTION:
48 # Clean up environment for clean builds.
49 xdg_environment_reset() {
50         # Prepare XDG base directories
51         export XDG_DATA_HOME="${HOME}/.local/share"
52         export XDG_CONFIG_HOME="${HOME}/.config"
53         export XDG_CACHE_HOME="${HOME}/.cache"
54         export XDG_RUNTIME_DIR="${T}/run"
55         mkdir -p "${XDG_DATA_HOME}" "${XDG_CONFIG_HOME}" "${XDG_CACHE_HOME}" \
56                 "${XDG_RUNTIME_DIR}" || die
57         # This directory needs to be owned by the user, and chmod 0700
58         # http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
59         chmod 0700 "${XDG_RUNTIME_DIR}" || die
60
61         unset DBUS_SESSION_BUS_ADDRESS
62 }
63
64 # @FUNCTION: fdo-xdg_desktop_database_update
65 # @DESCRIPTION:
66 # Updates the .desktop files database.
67 # Generates a list of mimetypes linked to applications that can handle them
68 xdg_desktop_database_update() {
69         local updater="${EROOT}${DESKTOP_DATABASE_UPDATE_BIN}"
70
71         if [[ ${EBUILD_PHASE} != post* ]] ; then
72                 die "xdg_desktop_database_update must be used in pkg_post* phases."
73         fi
74
75         if [[ ! -x "${updater}" ]] ; then
76                 debug-print "${updater} is not executable"
77                 return
78         fi
79
80         ebegin "Updating .desktop files database"
81         "${updater}" -q "${EROOT}${DESKTOP_DATABASE_DIR}"
82         eend $?
83 }
84
85 # @FUNCTION: xdg_mimeinfo_database_update
86 # @DESCRIPTION:
87 # Update the mime database.
88 # Creates a general list of mime types from several sources
89 xdg_mimeinfo_database_update() {
90         local updater="${EROOT}${MIMEINFO_DATABASE_UPDATE_BIN}"
91
92         if [[ ${EBUILD_PHASE} != post* ]] ; then
93                 die "xdg_mimeinfo_database_update must be used in pkg_post* phases."
94         fi
95
96         if [[ ! -x "${updater}" ]] ; then
97                 debug-print "${updater} is not executable"
98                 return
99         fi
100
101         ebegin "Updating shared mime info database"
102         "${updater}" "${EROOT}${MIMEINFO_DATABASE_DIR}"
103         eend $?
104 }