1 # Copyright 1999-2018 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: tmpfiles.eclass
6 # Gentoo systemd project <systemd@gentoo.org>
7 # William Hubbs <williamh@gentoo.org>
9 # Mike Gilbert <floppym@gentoo.org>
10 # William Hubbs <williamh@gentoo.org>
11 # @BLURB: Functions related to tmpfiles.d files
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:
17 # https://www.freedesktop.org/software/systemd/man/tmpfiles.d.html
19 # The dotmpfiles and newtmpfiles functions are used to install
20 # configuration files into /usr/lib/tmpfiles.d, then in pkg_postinst,
21 # the tmpfiles_process function must be called to process the newly
22 # installed tmpfiles.d entries.
24 # The tmpfiles.d files can be used by service managers to recreate/clean
25 # up temporary directories on boot or periodically. Additionally,
26 # the pkg_postinst() call ensures that the directories are created
27 # on systems that do not support tmpfiles.d natively, without a need
28 # for explicit fallback.
31 # Typical usage of this eclass:
41 # dotmpfiles "${FILESDIR}"/file1.conf "${FILESDIR}"/file2.conf
42 # newtmpfiles "${FILESDIR}"/file3.conf-${PV} file3.conf
48 # tmpfiles_process file1.conf file2.conf file3.conf
54 if [[ -z ${TMPFILES_ECLASS} ]]; then
59 *) die "API is undefined for EAPI ${EAPI}" ;;
62 RDEPEND="virtual/tmpfiles"
64 # @FUNCTION: dotmpfiles
65 # @USAGE: dotmpfiles <tmpfiles.d_file> ...
67 # Install one or more tmpfiles.d files into /usr/lib/tmpfiles.d.
69 debug-print-function "${FUNCNAME}" "$@"
73 if [[ ${f} != *.conf ]]; then
74 die "tmpfiles.d files must end with .conf"
79 insinto /usr/lib/tmpfiles.d
84 # @FUNCTION: newtmpfiles
85 # @USAGE: newtmpfiles <old-name> <new-name>.conf
87 # Install a tmpfiles.d file in /usr/lib/tmpfiles.d under a new name.
89 debug-print-function "${FUNCNAME}" "$@"
91 if [[ $2 != *.conf ]]; then
92 die "tmpfiles.d files must end with .conf"
96 insinto /usr/lib/tmpfiles.d
101 # @FUNCTION: tmpfiles_process
102 # @USAGE: tmpfiles_process <filename> <filename> ...
104 # Call a tmpfiles.d implementation to create new volatile and temporary
105 # files and directories.
107 debug-print-function "${FUNCNAME}" "$@"
109 [[ ${EBUILD_PHASE} == postinst ]] || die "${FUNCNAME}: Only valid in pkg_postinst"
110 [[ ${#} -gt 0 ]] || die "${FUNCNAME}: Must specify at least one filename"
112 # Only process tmpfiles for the currently running system
113 [[ ${ROOT} == / ]] || return 0
115 if type systemd-tmpfiles &> /dev/null; then
116 systemd-tmpfiles --create "$@"
117 elif type tmpfiles &> /dev/null; then
118 tmpfiles --create "$@"
120 if [[ $? -ne 0 ]]; then
121 ewarn "The tmpfiles processor exited with a non-zero exit code"