1 |
On Thu, Jan 03, 2013 at 02:01:03PM +0100, Pacho Ramos wrote: |
2 |
> # Copyright 1999-2012 Gentoo Foundation |
3 |
> # Distributed under the terms of the GNU General Public License v2 |
4 |
> # $Header: $ |
5 |
> |
6 |
> # @ECLASS: configuration-doc |
7 |
> # @MAINTAINER: |
8 |
> # Pacho Ramos <pacho@g.o> |
9 |
> # @AUTHOR: |
10 |
> # Author: Pacho Ramos <pacho@g.o> |
11 |
> # @BLURB: An eclass for installing a CONFIGURATION doc file recording tips |
12 |
> # shown via elog messages. With this eclass, those elog messages will only be |
13 |
> # shown at first package installation and a file for later reviewing will be |
14 |
> # installed under /usr/share/doc/${PF} |
15 |
> # @DESCRIPTION: |
16 |
> # An eclass for installing a CONFIGURATION doc file recording tips |
17 |
> # shown via elog messages. With this eclass, those elog messages will only be |
18 |
> # shown at first package installation and a file for later reviewing will be |
19 |
> # installed under /usr/share/doc/${PF} |
20 |
> |
21 |
> if [[ ${___ECLASS_ONCE_CONFIGURATION_DOC} != "recur -_+^+_- spank" ]] ; then |
22 |
> ___ECLASS_ONCE_CONFIGURATION_DOC="recur -_+^+_- spank" |
23 |
> |
24 |
> inherit eutils |
25 |
> |
26 |
> case "${EAPI:-0}" in |
27 |
> 0|1|2|3) |
28 |
> die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}" |
29 |
> ;; |
30 |
> 4|5) |
31 |
> # EAPI>=4 is required for REPLACING_VERSIONS preventing us |
32 |
> # from needing to export another pkg_preinst phase to save has_version |
33 |
> # result. Also relies on EAPI >=4 default src_install phase. |
34 |
> ;; |
35 |
> *) |
36 |
> die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}" |
37 |
> ;; |
38 |
> esac |
39 |
|
40 |
Why does it matter if the unsupported eapi is too old or unknown? I |
41 |
think you can combine the first and last branches of this case |
42 |
statement. |
43 |
|
44 |
On the other hand, if you don't export phase functions, you don't have |
45 |
to worry about EAPIS; you can just allow ebuild developers to call your |
46 |
functions directly. This is what I see happening in your sample ebuild |
47 |
below. |
48 |
|
49 |
> EXPORT_FUNCTIONS src_install pkg_postinst |
50 |
|
51 |
Drop this export_functions call. You don't need it based on what I see |
52 |
in your ebuild. |
53 |
|
54 |
> # @FUNCTION: configuration_create_doc |
55 |
> # @DESCRIPTION: |
56 |
> # Create doc file with CONFIGURATION_INSTRUCTIONS contents. |
57 |
> # Usually called at src_install phase. |
58 |
|
59 |
You can pass in the content as $1 instead of using a global variable for |
60 |
it: |
61 |
|
62 |
> configuration_create_doc() { |
63 |
> debug-print-function ${FUNCNAME} "${@}" |
64 |
> |
65 |
> if [[ -n "${1}" ]]; then |
66 |
> eshopts_push |
67 |
> set -f |
68 |
> echo ${CONFIGURATION_INSTRUCTIONS} | fmt > CONFIGURATION |
69 |
|
70 |
I would use "${T}"/CONFIGURATION here. |
71 |
|
72 |
echo "${1}" | fmt > "${T}"CONFIGURATION |
73 |
|
74 |
> eshopts_pop |
75 |
> dodoc CONFIGURATION |
76 |
|
77 |
Again, "${T}"/CONFIGURATION |
78 |
|
79 |
> fi |
80 |
> } |
81 |
> |
82 |
> # @FUNCTION: configuration_print_elog |
83 |
> # @DESCRIPTION: |
84 |
> # Print elog messages with CONFIGURATION_INSTRUCTIONS contents. |
85 |
> # Usually called at pkg_postinst phase. |
86 |
> configuration_print_elog() { |
87 |
> debug-print-function ${FUNCNAME} "${@}" |
88 |
> |
89 |
> if [[ -n "${CONFIGURATION_INSTRUCTIONS}" ]]; then |
90 |
|
91 |
I would recommend using the CONFIGURATION file here, as follows: |
92 |
|
93 |
if [ -f "${T}"/CONFIGURATION ]; then |
94 |
|
95 |
> if ! [[ "${REPLACING_VERSIONS}" ]]; then |
96 |
|
97 |
This is an issue if I want to add display some tips that have changed |
98 |
between different versions of the software. I would propose not trying |
99 |
to do this, but let the user call this function. |
100 |
|
101 |
> eshopts_push |
102 |
> set -f |
103 |
> echo ${CONFIGURATION_INSTRUCTIONS} | fmt | while read -r ELINE; do elog "${ELINE}"; done |
104 |
|
105 |
cat "${T}"/CONFIGURATION | fmt | while read -r ELINE; do elog "${ELINE}"; done |
106 |
|
107 |
> eshopts_pop |
108 |
> fi |
109 |
> fi |
110 |
> } |
111 |
|
112 |
> # @FUNCTION: configuration-doc_src_install |
113 |
> # @DESCRIPTION: |
114 |
> # Show elog messages from CONFIGURATION_INSTRUCTIONS variable, that will be |
115 |
> # shared with /usr/share/doc/${PF}/CONFIGURATION content. |
116 |
> configuration-doc_src_install() { |
117 |
> debug-print-function ${FUNCNAME} "${@}" |
118 |
> |
119 |
> default |
120 |
> configuration_create_doc |
121 |
> } |
122 |
> |
123 |
> # @FUNCTION: configuration-doc_pkg_postinst |
124 |
> # @DESCRIPTION: |
125 |
> # Show elog messages from CONFIGURATION_INSTRUCTIONS variable, that will be |
126 |
> # shared with /usr/share/doc/${PF}/CONFIGURATION content. |
127 |
> configuration-doc_pkg_postinst() { |
128 |
> debug-print-function ${FUNCNAME} "${@}" |
129 |
> configuration_print_elog |
130 |
> } |
131 |
> |
132 |
> fi |
133 |
|
134 |
These can go; your example ebuild doesn't need them since it calls the |
135 |
eclass functions. |
136 |
|
137 |
|
138 |
Below, I am showing how the ebuild would change based on my changes to |
139 |
the eclass. |
140 |
|
141 |
> # Copyright 1999-2012 Gentoo Foundation |
142 |
> # Distributed under the terms of the GNU General Public License v2 |
143 |
> # $Header: /var/cvsroot/gentoo-x86/sys-power/acpid/acpid-2.0.17.ebuild,v 1.6 2012/11/25 18:59:25 armin76 Exp $ |
144 |
> |
145 |
> EAPI=4 |
146 |
> inherit configuration-doc systemd |
147 |
> |
148 |
> DESCRIPTION="Daemon for Advanced Configuration and Power Interface" |
149 |
> HOMEPAGE="http://tedfelix.com/linux/acpid-netlink.html" |
150 |
> SRC_URI="http://tedfelix.com/linux/${P}.tar.xz" |
151 |
> |
152 |
> LICENSE="GPL-2" |
153 |
> SLOT="0" |
154 |
> KEYWORDS="amd64 ia64 -ppc x86" |
155 |
> IUSE="selinux" |
156 |
> |
157 |
> RDEPEND="selinux? ( sec-policy/selinux-apm )" |
158 |
> DEPEND="${RDEPEND}" |
159 |
> |
160 |
> CONFIGURATION_INSTRUCTIONS=" |
161 |
> You may wish to read the Gentoo Linux Power Management Guide, |
162 |
> which can be found online at: |
163 |
> http://www.gentoo.org/doc/en/power-management-guide.xml" |
164 |
|
165 |
Delete this and make it a local below if you want the variable, |
166 |
otherwise pass it as a constant. |
167 |
|
168 |
> src_configure() { |
169 |
> econf --docdir=/usr/share/doc/${PF} |
170 |
> } |
171 |
> |
172 |
> src_install() { |
173 |
> emake DESTDIR="${D}" install |
174 |
> |
175 |
> newdoc kacpimon/README README.kacpimon |
176 |
> dodoc -r samples |
177 |
> rm -f "${D}"/usr/share/doc/${PF}/COPYING |
178 |
> |
179 |
> exeinto /etc/acpi |
180 |
> newexe "${FILESDIR}"/${PN}-1.0.6-default.sh default.sh |
181 |
> insinto /etc/acpi/events |
182 |
> newins "${FILESDIR}"/${PN}-1.0.4-default default |
183 |
> |
184 |
> newinitd "${FILESDIR}"/${PN}-2.0.16-init.d ${PN} |
185 |
> newconfd "${FILESDIR}"/${PN}-2.0.16-conf.d ${PN} |
186 |
> |
187 |
> systemd_dounit "${FILESDIR}"/systemd/${PN}.{service,socket} |
188 |
|
189 |
local CONFIGURATION_INSTRUCTIONS=" |
190 |
You may wish to read the Gentoo Linux Power Management Guide, |
191 |
which can be found online at: |
192 |
http://www.gentoo.org/doc/en/power-management-guide.xml" |
193 |
|
194 |
> configuration_create_doc |
195 |
|
196 |
configuration_create_doc "${CONFIGURATION_INSTRUCTIONS}" |
197 |
> } |
198 |
> |
199 |
> pkg_postinst() { |
200 |
> configuration_print_elog |
201 |
|
202 |
The thing that would change here would be that you would have to make |
203 |
postinst smart enough to know when to call configuration_print_elog. |
204 |
Maybe you do it all the time like this, or maybe you do it the first |
205 |
time the package is installed, or you do it when you are upgrading from |
206 |
an older version and adding or removing some configuration information. |
207 |
|
208 |
> # files/systemd/acpid.socket -> ListenStream=/run/acpid.socket |
209 |
> mkdir -p "${ROOT}"/run |
210 |
> |
211 |
> if ! grep -qs "^tmpfs.*/run " "${ROOT}"/proc/mounts ; then |
212 |
> echo |
213 |
> ewarn "You should reboot the system now to get /run mounted with tmpfs!" |
214 |
> fi |
215 |
> } |
216 |
|
217 |
William |