1 # Copyright 1999-2016 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, the
21 # tmpfiles_process function can be called to process the newly
22 # installed tmpfiles.d entries.
25 # Typical usage of this eclass:
35 # dotmpfiles "${FILESDIR}"/file1.conf "${FILESDIR}"/file2.conf
36 # newtmpfiles "${FILESDIR}"/file3.conf-${PV} file3.conf
42 # tmpfiles_process file1.conf file2.conf file3.conf
48 if [[ -z ${TMPFILES_ECLASS} ]]; then
53 *) die "API is undefined for EAPI ${EAPI}" ;;
56 RDEPEND="kernel_linux? ( virtual/tmpfiles )"
58 # @FUNCTION: dotmpfiles
59 # @USAGE: dotmpfiles <tmpfiles.d_file> ...
61 # Install one or more tmpfiles.d files into /usr/lib/tmpfiles.d.
63 debug-print-function "${FUNCNAME}" "$@"
65 use kernel_linux || return 0
68 if [[ ${f} != *.conf ]]; then
69 die "tmpfiles.d files must end with .conf"
74 insinto /usr/lib/tmpfiles.d
79 # @FUNCTION: newtmpfiles
80 # @USAGE: newtmpfiles <old-name> <new-name>.conf
82 # Install a tmpfiles.d file in /usr/lib/tmpfiles.d under a new name.
84 debug-print-function "${FUNCNAME}" "$@"
86 use kernel_linux || return 0
87 if [[ $2 != *.conf ]]; then
88 die "tmpfiles.d files must end with .conf"
92 insinto /usr/lib/tmpfiles.d
97 # @FUNCTION: tmpfiles_process
98 # @USAGE: tmpfiles_process <filename> <filename> ...
100 # Call a tmpfiles.d implementation to create new volatile and temporary
101 # files and directories.
103 debug-print-function "${FUNCNAME}" "$@"
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"
109 # Only process tmpfiles for the currently running system
110 [[ ${ROOT} == / ]] || return 0
112 if type systemd-tmpfiles &> /dev/null; then
113 systemd-tmpfiles --create "$@"
114 elif type tmpfiles &> /dev/null; then
115 tmpfiles --create "$@"
117 if [[ $? -ne 0 ]]; then
118 ewarn "The tmpfiles processor exited with a non-zero exit code"