kde-plasma/breeze-gtk: x86 stable wrt bug #613144
[gentoo.git] / eclass / tmpfiles.eclass
1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: tmpfiles.eclass
5 # @MAINTAINER:
6 # Gentoo systemd project <systemd@gentoo.org>
7 # William Hubbs <williamh@gentoo.org>
8 # @AUTHOR:
9 # Mike Gilbert <floppym@gentoo.org>
10 # William Hubbs <williamh@gentoo.org>
11 # @BLURB: Functions related to tmpfiles.d files
12 # @DESCRIPTION:
13 # This eclass provides functionality related to installing and
14 # creating volatile and temporary files based on configuration files$and
15 # locations defined at this URL:
16 #
17 # https://www.freedesktop.org/software/systemd/man/tmpfiles.d.html
18 #
19 # The dotmpfiles and newtmpfiles functions are used to install
20 # configuration files into /usr/lib/tmpfiles.d, then in pkg_postinst, the
21 # tmpfiles_process function can be called to process the newly
22 # installed tmpfiles.d entries.
23 #
24 # @EXAMPLE:
25 # Typical usage of this eclass:
26 #
27 # @CODE
28 #       EAPI=6
29 #       inherit tmpfiles
30 #
31 #       ...
32 #
33 #       src_install() {
34 #               ...
35 #               dotmpfiles "${FILESDIR}"/file1.conf "${FILESDIR}"/file2.conf
36 #               newtmpfiles "${FILESDIR}"/file3.conf-${PV} file3.conf
37 #               ...
38 #       }
39 #
40 #       pkg_postinst() {
41 #               ...
42 #               tmpfiles_process file1.conf file2.conf file3.conf
43 #               ...
44 #       }
45 #
46 # @CODE
47
48 if [[ -z ${TMPFILES_ECLASS} ]]; then
49 TMPFILES_ECLASS=1
50
51 case "${EAPI}" in
52 6) ;;
53 *) die "API is undefined for EAPI ${EAPI}" ;;
54 esac
55
56 RDEPEND="kernel_linux? ( virtual/tmpfiles )"
57
58 # @FUNCTION: dotmpfiles
59 # @USAGE: dotmpfiles <tmpfiles.d_file> ...
60 # @DESCRIPTION:
61 # Install one or more tmpfiles.d files into /usr/lib/tmpfiles.d.
62 dotmpfiles() {
63         debug-print-function "${FUNCNAME}" "$@"
64
65         use kernel_linux || return 0
66         local f
67         for f; do
68                 if [[ ${f} != *.conf ]]; then
69                         die "tmpfiles.d files must end with .conf"
70                 fi
71         done
72
73         (
74                 insinto /usr/lib/tmpfiles.d
75                 doins "$@"
76         )
77 }
78
79 # @FUNCTION: newtmpfiles
80 # @USAGE: newtmpfiles <old-name> <new-name>.conf
81 # @DESCRIPTION:
82 # Install a tmpfiles.d file in /usr/lib/tmpfiles.d under a new name.
83 newtmpfiles() {
84         debug-print-function "${FUNCNAME}" "$@"
85
86         use kernel_linux || return 0
87         if [[ $2 != *.conf ]]; then
88                 die "tmpfiles.d files must end with .conf"
89         fi
90
91         (
92                 insinto /usr/lib/tmpfiles.d
93                 newins "$@"
94         )
95 }
96
97 # @FUNCTION: tmpfiles_process
98 # @USAGE: tmpfiles_process <filename> <filename> ...
99 # @DESCRIPTION:
100 # Call a tmpfiles.d implementation to create new volatile and temporary
101 # files and directories.
102 tmpfiles_process() {
103         debug-print-function "${FUNCNAME}" "$@"
104
105         use kernel_linux || return 0
106         [[ ${EBUILD_PHASE} == postinst ]] || die "${FUNCNAME}: Only valid in pkg_postinst"
107         [[ ${#} -gt 0 ]] || die "${FUNCNAME}: Must specify at least one filename"
108
109         # Only process tmpfiles for the currently running system
110         [[ ${ROOT} == / ]] || return 0
111
112         if type systemd-tmpfiles &> /dev/null; then
113                 systemd-tmpfiles --create "$@"
114         elif type tmpfiles &> /dev/null; then
115                 tmpfiles --create "$@"
116         fi
117         if [[ $? -ne 0 ]]; then
118                 ewarn "The tmpfiles processor exited with a non-zero exit code"
119         fi
120 }
121
122 fi