diff options
author | William Hubbs <williamh@gentoo.org> | 2016-12-01 16:16:41 -0600 |
---|---|---|
committer | William Hubbs <williamh@gentoo.org> | 2016-12-01 16:17:10 -0600 |
commit | 13c2dad013013fc555cb583668c57bc410007350 (patch) | |
tree | 45efa989c5cf4c2c715f277e2d00c8d42a2c0c4f | |
parent | virtual/tmpfiles: Add a new virtual for tmpfiles processing (diff) | |
download | gentoo-13c2dad013013fc555cb583668c57bc410007350.tar.gz gentoo-13c2dad013013fc555cb583668c57bc410007350.tar.bz2 gentoo-13c2dad013013fc555cb583668c57bc410007350.zip |
tmpfiles.eclass: add eclass for tmpfiles processing
-rw-r--r-- | eclass/tmpfiles.eclass | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/eclass/tmpfiles.eclass b/eclass/tmpfiles.eclass new file mode 100644 index 000000000000..d66545eb27de --- /dev/null +++ b/eclass/tmpfiles.eclass @@ -0,0 +1,123 @@ +# Copyright 1999-2016 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Id$ + +# @ECLASS: tmpfiles.eclass +# @MAINTAINER: +# Gentoo systemd project <systemd@gentoo.org> +# William Hubbs <williamh@gentoo.org> +# @AUTHOR: +# Mike Gilbert <floppym@gentoo.org> +# William Hubbs <williamh@gentoo.org> +# @BLURB: Functions related to tmpfiles.d files +# @DESCRIPTION: +# This eclass provides functionality related to installing and +# creating volatile and temporary files based on configuration files$and +# locations defined at this URL: +# +# https://www.freedesktop.org/software/systemd/man/tmpfiles.d.html +# +# The dotmpfiles and newtmpfiles functions are used to install +# configuration files into /usr/lib/tmpfiles.d, then in pkg_postinst, the +# tmpfiles_process function can be called to process the newly +# installed tmpfiles.d entries. +# +# @EXAMPLE: +# Typical usage of this eclass: +# +# @CODE +# EAPI=6 +# inherit tmpfiles +# +# ... +# +# src_install() { +# ... +# dotmpfiles "${FILESDIR}"/file1.conf "${FILESDIR}"/file2.conf +# newtmpfiles "${FILESDIR}"/file3.conf-${PV} file3.conf +# ... +# } +# +# pkg_postinst() { +# ... +# tmpfiles_process file1.conf file2.conf file3.conf +# ... +# } +# +# @CODE + +if [[ -z ${TMPFILES_ECLASS} ]]; then +TMPFILES_ECLASS=1 + +case "${EAPI}" in +6) ;; +*) die "API is undefined for EAPI ${EAPI}" ;; +esac + +RDEPEND="kernel_linux? ( virtual/tmpfiles )" + +# @FUNCTION: dotmpfiles +# @USAGE: dotmpfiles <tmpfiles.d_file> ... +# @DESCRIPTION: +# Install one or more tmpfiles.d files into /usr/lib/tmpfiles.d. +dotmpfiles() { + debug-print-function "${FUNCNAME}" "$@" + + use kernel_linux || return 0 + local f + for f; do + if [[ ${f} != *.conf ]] + die "tmpfiles.d files must end with .conf" + fi + done + + ( + insinto /usr/lib/tmpfiles.d + doins "$@" + ) +} + +# @FUNCTION: newtmpfiles +# @USAGE: newtmpfiles <old-name> <new-name>.conf +# @DESCRIPTION: +# Install a tmpfiles.d file in /usr/lib/tmpfiles.d under a new name. +newtmpfiles() { + debug-print-function "${FUNCNAME}" "$@" + + use kernel_linux || return 0 + if [[ $2 != *.conf ]]; then + die "tmpfiles.d files must end with .conf" + fi + + ( + insinto /usr/lib/tmpfiles.d + newins "$@" + ) +} + +# @FUNCTION: tmpfiles_process +# @USAGE: tmpfiles_process <filename> <filename> ... +# @DESCRIPTION: +# Call a tmpfiles.d implementation to create new volatile and temporary +# files and directories. +tmpfiles_process() { + debug-print-function "${FUNCNAME}" "$@" + + use kernel_linux || return 0 + [[ ${EBUILD_PHASE} == postinst ]] || die "${FUNCNAME}: Only valid in pkg_postinst" + [[ ${#} -gt 0 ]] || die "${FUNCNAME}: Must specify at least one filename" + + # Only process tmpfiles for the currently running system + [[ ${ROOT} == / ]] || return 0 + + if type systemd-tmpfiles &> /dev/null; then + systemd-tmpfiles --create "$@" + elif type opentmpfiles &> /dev/null; then + opentmpfiles --create "$@" + fi + if [[ $? -ne 0 ]]; then + ewarn "The tmpfiles processor exited with a non-zero exit code" + fi +} + +fi |