Gentoo Archives: gentoo-commits

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