1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # @ECLASS: tmpfiles.eclass
7 # Gentoo systemd project <systemd@gentoo.org>
8 # William Hubbs <williamh@gentoo.org>
10 # Mike Gilbert <floppym@gentoo.org>
11 # William Hubbs <williamh@gentoo.org>
12 # @BLURB: Functions related to tmpfiles.d files
14 # This eclass provides functionality related to installing and
15 # creating volatile and temporary files based on configuration files$and
16 # locations defined at this URL:
18 # https://www.freedesktop.org/software/systemd/man/tmpfiles.d.html
20 # The dotmpfiles and newtmpfiles functions are used to install
21 # configuration files into /usr/lib/tmpfiles.d, then in pkg_postinst, the
22 # tmpfiles_process function can be called to process the newly
23 # installed tmpfiles.d entries.
26 # Typical usage of this eclass:
36 # dotmpfiles "${FILESDIR}"/file1.conf "${FILESDIR}"/file2.conf
37 # newtmpfiles "${FILESDIR}"/file3.conf-${PV} file3.conf
43 # tmpfiles_process file1.conf file2.conf file3.conf
49 if [[ -z ${TMPFILES_ECLASS} ]]; then
54 *) die "API is undefined for EAPI ${EAPI}" ;;
57 RDEPEND="kernel_linux? ( virtual/tmpfiles )"
59 # @FUNCTION: dotmpfiles
60 # @USAGE: dotmpfiles <tmpfiles.d_file> ...
62 # Install one or more tmpfiles.d files into /usr/lib/tmpfiles.d.
64 debug-print-function "${FUNCNAME}" "$@"
66 use kernel_linux || return 0
69 if [[ ${f} != *.conf ]]
70 die "tmpfiles.d files must end with .conf"
75 insinto /usr/lib/tmpfiles.d
80 # @FUNCTION: newtmpfiles
81 # @USAGE: newtmpfiles <old-name> <new-name>.conf
83 # Install a tmpfiles.d file in /usr/lib/tmpfiles.d under a new name.
85 debug-print-function "${FUNCNAME}" "$@"
87 use kernel_linux || return 0
88 if [[ $2 != *.conf ]]; then
89 die "tmpfiles.d files must end with .conf"
93 insinto /usr/lib/tmpfiles.d
98 # @FUNCTION: tmpfiles_process
99 # @USAGE: tmpfiles_process <filename> <filename> ...
101 # Call a tmpfiles.d implementation to create new volatile and temporary
102 # files and directories.
104 debug-print-function "${FUNCNAME}" "$@"
106 use kernel_linux || return 0
107 [[ ${EBUILD_PHASE} == postinst ]] || die "${FUNCNAME}: Only valid in pkg_postinst"
108 [[ ${#} -gt 0 ]] || die "${FUNCNAME}: Must specify at least one filename"
110 # Only process tmpfiles for the currently running system
111 [[ ${ROOT} == / ]] || return 0
113 if type systemd-tmpfiles &> /dev/null; then
114 systemd-tmpfiles --create "$@"
115 elif type opentmpfiles &> /dev/null; then
116 opentmpfiles --create "$@"
118 if [[ $? -ne 0 ]]; then
119 ewarn "The tmpfiles processor exited with a non-zero exit code"