summaryrefslogtreecommitdiff
path: root/eclass/freedesktop.eclass
blob: 02063678be9a4a213387371b78f6965f38e0d08c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Copyright 1999-2015 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

# @ECLASS: freedesktop
# @MAINTAINER:
# freedesktop-bugs@gentoo.org
# @BLURB: Useful functions for working with freedesktop-compliant applications
# @DESCRIPTION:
# Set up directories according to the XDG Base Directory Specification.
# Also provides functions for updating desktop, mime, and icon caches.
# @EXAMPLE:
# @CODE
# inherit freedesktop
#
# pkg_setup() {
# 	freedesktop_setup
# }
# pkg_postinst() {
# 	freedesktop_desktop_database_update
# 	freedesktop_mime_database_update
# }
# @CODE

# Unset these globally to avoid leaking values from the calling environment.
unset XDG_DATA_HOME XDG_CONFIG_HOME XDG_CACHE_HOME XDG_RUNTIME_DIR

# @FUNCTION: freedesktop_setup
# @DESCRIPTION:
# Creates sensible locations for the following environment variables:
# XDG_DATA_HOME
# XDG_CONFIG_HOME
# XDG_CACHE_HOME
# XDG_RUNTIME_DIR
freedesktop_setup() {
	export XDG_DATA_HOME="${HOME}/.local/share"
	export XDG_CONFIG_HOME="${HOME}/.config"
	export XDG_CACHE_HOME="${HOME}/.cache"
	export XDG_RUNTIME_DIR="${T}/run"
	mkdir -p "${XDG_DATA_HOME}" "${XDG_CONFIG_HOME}" "${XDG_CACHE_HOME}" || die
	mkdir -p -m 0700 "${XDG_RUNTIME_DIR}" || die
}

# @FUNCTION: freedesktop_desktop_database_update
# @DESCRIPTION:
# Updates the desktop database.
# Generates a list of mimetypes linked to applications that can handle them
freedesktop_desktop_database_update() {
	has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
	has "${EAPI:-0}" 0 1 2 && ! use prefix && EROOT="${ROOT}"
	if [ -x "${EPREFIX}/usr/bin/update-desktop-database" ]
	then
		einfo "Updating desktop mime database ..."
		"${EPREFIX}/usr/bin/update-desktop-database" -q "${EROOT}usr/share/applications"
	fi
}

# @FUNCTION: freedesktop_mime_database_update
# @DESCRIPTION:
# Update the mime database.
# Creates a general list of mime types from several sources
freedesktop_mime_database_update() {
	has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
	has "${EAPI:-0}" 0 1 2 && ! use prefix && EROOT="${ROOT}"
	if [ -x "${EPREFIX}/usr/bin/update-mime-database" ]
	then
		einfo "Updating shared mime info database ..."
		"${EPREFIX}/usr/bin/update-mime-database" "${EROOT}usr/share/mime"
	fi
}