Gentoo Archives: gentoo-commits

From: Anna Vyalkova <cyber+gentoo@×××××.in>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/proj/guru:dev commit in: eclass/
Date: Thu, 22 Jul 2021 08:29:39
Message-Id: 1626942459.1aeb74d3fa80f3c5076dc86f84a4588e7ee4d4c5.cybertailor@gentoo
1 commit: 1aeb74d3fa80f3c5076dc86f84a4588e7ee4d4c5
2 Author: Anna (cybertailor) Vyalkova <cyber+gentoo <AT> sysrq <DOT> in>
3 AuthorDate: Thu Jul 22 08:10:21 2021 +0000
4 Commit: Anna Vyalkova <cyber+gentoo <AT> sysrq <DOT> in>
5 CommitDate: Thu Jul 22 08:27:39 2021 +0000
6 URL: https://gitweb.gentoo.org/repo/proj/guru.git/commit/?id=1aeb74d3
7
8 boinc-app.eclass: new eclass
9
10 Signed-off-by: Anna (cybertailor) Vyalkova <cyber+gentoo <AT> sysrq.in>
11
12 eclass/boinc-app.eclass | 308 ++++++++++++++++++++++++++++++++++++++++++++++++
13 1 file changed, 308 insertions(+)
14
15 diff --git a/eclass/boinc-app.eclass b/eclass/boinc-app.eclass
16 new file mode 100644
17 index 000000000..d62c8a91f
18 --- /dev/null
19 +++ b/eclass/boinc-app.eclass
20 @@ -0,0 +1,308 @@
21 +# Copyright 2021 Gentoo Authors
22 +# Distributed under the terms of the GNU General Public License v2
23 +
24 +# @ECLASS: boinc-app.eclass
25 +# @MAINTAINER:
26 +# Anna Vyalkova <cyber+gentoo@×××××.in>
27 +# @SUPPORTED_EAPIS: 8
28 +# @BLURB: Eclass that provides base functions for installing BOINC applications.
29 +# @DESCRIPTION:
30 +# This eclass provides base functions for installation of software developed
31 +# for the BOINC platform.
32 +#
33 +# Do not package *-bin applications as BOINC can handle them itself better.
34 +#
35 +# Note that BOINC won't detect a custom application unless you provide it with
36 +# app_info.xml file (see https://boinc.berkeley.edu/wiki/Anonymous_platform).
37 +# Attach to a project of your interest and use values from
38 +# /var/lib/boinc/client_state.xml to write the file.
39 +#
40 +# BOINC.Italy did a great job discovering sources of many BOINC applications:
41 +# https://www.boincitaly.org/progetti/sorgenti-progetti.html
42 +
43 +case ${EAPI} in
44 + 8) ;;
45 + *) die "${ECLASS}: EAPI ${EAPI} unsupported."
46 +esac
47 +
48 +# @ECLASS-VARIABLE: BOINC_APP_OPTIONAL
49 +# @DEFAULT_UNSET
50 +# @DESCRIPTION:
51 +# If set to a non-null value, BOINC part in the ebuild will be
52 +# considered optional and no phase functions will be exported.
53 +#
54 +# If you enable BOINC_APP_OPTIONAL, you have to call boinc-app
55 +# default phase functions and add dependencies manually.
56 +
57 +if [[ ! ${BOINC_APP_OPTIONAL} ]]; then
58 + EXPORT_FUNCTIONS pkg_postinst pkg_postrm
59 +fi
60 +
61 +if [[ ! ${_BOINC_APP_ECLASS} ]]; then
62 +
63 +# @ECLASS-VARIABLE: BOINC_MASTER_URL
64 +# @REQUIRED
65 +# @DESCRIPTION:
66 +# Each project is publicly identified by a master URL. It also serves
67 +# as the home page of the project.
68 +#
69 +# You need to look it up using the following command:
70 +# @CODE
71 +# grep "<master_url>" /var/lib/boinc/client_state.xml
72 +# @CODE
73 +
74 +# @ECLASS-VARIABLE: BOINC_INVITATION_CODE
75 +# @DEFAULT_UNSET
76 +# @DESCRIPTION:
77 +# Some projects restrict account creation to those who present an
78 +# "invitation code". Write it to BOINC_INVITATION_CODE variable if
79 +# it's published on project's website.
80 +
81 +# @ECLASS-VARIABLE: HOMEPAGE
82 +# @DESCRIPTION:
83 +# This variable defines the HOMEPAGE for BOINC projects if BOINC_MASTER_URL
84 +# was set before inherit.
85 +: ${HOMEPAGE:=${BOINC_MASTER_URL}}
86 +
87 +# @ECLASS-VARIABLE: BOINC_APP_HELPTEXT
88 +# @DESCRIPTION:
89 +# Help message to display during the pkg_postinst phase
90 +: ${BOINC_APP_HELPTEXT:=\
91 +You have to attach to the corresponding project
92 +in order to use this application with BOINC.}
93 +
94 +# @FUNCTION: boinc-app_add_deps
95 +# @USAGE: [--wrapper]
96 +# @DESCRIPTION:
97 +# Generate appropriate (R)DEPEND for wrapper-enabled or
98 +# native application.
99 +boinc-app_add_deps() {
100 + if [[ $1 == "--wrapper" ]]; then
101 + RDEPEND="sci-misc/boinc-wrapper"
102 + else
103 + DEPEND="sci-misc/boinc"
104 + RDEPEND="sci-misc/boinc"
105 + fi
106 +}
107 +
108 +# @FUNCTION: boinc_master_url_check
109 +# @USAGE:
110 +# @DESCRIPTION:
111 +# Make sure BOINC_MASTER_URL has a value.
112 +boinc_master_url_check() {
113 + [[ ! ${BOINC_MASTER_URL} ]] && \
114 + die "BOINC_MASTER_URL is not set"
115 + return 0
116 +}
117 +
118 +# @FUNCTION: get_boincdir
119 +# @USAGE:
120 +# @RETURN: non-prefixed default BOINC runtime directory
121 +get_boincdir() {
122 + echo /var/lib/boinc
123 +}
124 +
125 +# @FUNCTION: get_project_dirname
126 +# @INTERNAL
127 +# @USAGE:
128 +# @RETURN: project's dirname, derived from BOINC_MASTER_URL
129 +# @DESCRIPTION:
130 +# Example:
131 +#
132 +# @CODE
133 +# BOINC_MASTER_URL="https://boinc.berkeley.edu/example/"
134 +# get_project_dirname
135 +# -> boinc.berkeley.edu_example
136 +# @CODE
137 +get_project_dirname() {
138 + boinc_master_url_check
139 +
140 + local dirname
141 + dirname=${BOINC_MASTER_URL#*://} # strip http[s]://
142 + dirname=${dirname%/} # strip trailing slash
143 + dirname=${dirname////_} # replace '/' with '_'
144 +
145 + echo "${dirname}"
146 +}
147 +
148 +# @FUNCTION: get_project_root
149 +# @USAGE:
150 +# @RETURN: non-prefixed directory where applications and files should be installed
151 +get_project_root() {
152 + echo "$(get_boincdir)/projects/$(get_project_dirname)"
153 +}
154 +
155 +# @FUNCTION: boinc-app_appinfo_prepare
156 +# @USAGE: <writable app_info.xml>
157 +# @DESCRIPTION:
158 +# The default appinfo_prepare(). It replaces all occurences
159 +# of @PV@ with its corresponding value.
160 +boinc-app_appinfo_prepare() {
161 + sed -i "$1" \
162 + -e "s:%PV%:${PV}:g" \
163 + || die "app_info.xml sed failed"
164 +}
165 +
166 +# @FUNCTION: doappinfo
167 +# @USAGE: <app_info.xml>
168 +# @DESCRIPTION:
169 +# Installs given app_info.xml file to the project root.
170 +#
171 +# Tip: implement appinfo_prepare() function for all your sed hacks.
172 +# It should recognize first argument as a file and edit it in place.
173 +#
174 +# Example:
175 +# @CODE
176 +# appinfo_prepare() {
177 +# if ! use cuda; then
178 +# sed "/<plan_class>cuda/d" -i "$1" || die
179 +# fi
180 +# boinc-app_appinfo_prepare "$1"
181 +# }
182 +#
183 +# src_install() {
184 +# doappinfo "${FILESDIR}"/app_info_${PV}.xml
185 +#
186 +# exeinto $(get_project_root)
187 +# exeopts -m 0755 --owner boinc --group boinc
188 +# newexe bin/${PN} example_app_v${PV}
189 +# }
190 +# @CODE
191 +doappinfo() {
192 + (( $# == 1 )) || \
193 + die "${FUNCNAME} takes exactly one argument"
194 +
195 + cp "$1" "${T}"/app_info.xml || die
196 +
197 + if declare -f appinfo_prepare >/dev/null; then
198 + appinfo_prepare "${T}"/app_info.xml
199 + else
200 + boinc-app_appinfo_prepare "${T}"/app_info.xml
201 + fi
202 +
203 + ( # subshell to avoid pollution of calling environment
204 + insinto $(get_project_root)
205 + insopts -m 0644 --owner boinc --group boinc
206 + doins "${T}"/app_info.xml
207 + ) || die "failed to install app_info.xml"
208 +}
209 +
210 +# @FUNCTION: boinc-wrapper_foreach_wrapper_job
211 +# @USAGE: <job.xml>
212 +# @DESCRIPTION:
213 +# The default foreach_wrapper_job(). It replaces all occurences
214 +# of @PV@, @EPREFIX@ and @LIBDIR@ strings with their corresponding values.
215 +boinc-wrapper_foreach_wrapper_job() {
216 + sed -i "$1" \
217 + -e "s:@PV@:${PV}:g" \
218 + -e "s:@EPREFIX@:${EPREFIX}:g" \
219 + -e "s:@LIBDIR@:$(get_libdir):g" \
220 + || die "$(basename "$1") sed failed"
221 +}
222 +
223 +# @FUNCTION: dowrapper
224 +# @USAGE: <app> [more apps...]
225 +# @DESCRIPTION:
226 +# This function provides a uniform way to install wrapper applications
227 +# for BOINC projects. It makes symlinks to the BOINC wrapper and also
228 +# installs respective job.xml files.
229 +#
230 +# When sci-misc/boinc-example-1.0 calls `dowrapper boinc-example` it:
231 +#
232 +# 1. Installs boinc-example_job_1.0.xml from ebuild's files/ directory
233 +# to project's root directory
234 +#
235 +# 2. Installs boinc-example_wrapper_1.0 symlink, which points
236 +# to /usr/bin/boinc-wrapper, to project's root directory
237 +#
238 +# Example:
239 +# @CODE
240 +# src_install() {
241 +# meson_src_install
242 +#
243 +# dowrapper boinc-example boinc-sample
244 +# doappinfo "${FILESDIR}"/app_info_${PV}.xml
245 +# }
246 +# @CODE
247 +#
248 +# Keep your job.xml files in sync with app_info.xml!
249 +dowrapper() {
250 + for app in "$@"; do
251 + local wrapperjob="${app}_job_${PV}.xml"
252 + local wrapperexe="${app}_wrapper_${PV}"
253 +
254 + [[ -f "${FILESDIR}/${wrapperjob}" ]] || \
255 + die "${wrapperjob} not found in ebuild's files/ directory"
256 +
257 + cp "${FILESDIR}/${wrapperjob}" "${T}" || die
258 +
259 + if declare -f foreach_wrapper_job >/dev/null; then
260 + foreach_wrapper_job "${T}/${wrapperjob}"
261 + else
262 + boinc-wrapper_foreach_wrapper_job "${T}/${wrapperjob}"
263 + fi
264 +
265 + ( # subshell to avoid pollution of calling environment
266 + insinto $(get_project_root)
267 + insopts -m 0644 --owner boinc --group boinc
268 + doins "${T}"/${wrapperjob}
269 + dosym -r /usr/bin/boinc-wrapper "$(get_project_root)/${wrapperexe}"
270 + ) || die "failed to install '${app}' wrapper app"
271 + done
272 +}
273 +
274 +# @FUNCTION: boinc-app_pkg_postinst
275 +# @DESCRIPTION:
276 +# Display helpful instructions on how to make the BOINC client use installed
277 +# applications.
278 +boinc-app_pkg_postinst() {
279 + if [[ -f "${EROOT}$(get_boincdir)/master_$(get_project_dirname).xml" ]]; then
280 + if [[ ! ${REPLACING_VERSIONS} ]]; then
281 + # most likely replacing applications downloaded
282 + # by the BOINC client from project's website
283 + elog "Restart the BOINC daemon for changes to take place:"
284 + elog "# rc-service boinc restart"
285 + return
286 + else
287 + # applications are already in use
288 + return
289 + fi
290 + fi
291 +
292 + elog
293 + while read h; do
294 + elog "${h}"
295 + done <<<"${BOINC_APP_HELPTEXT}"
296 + elog
297 +
298 + if [[ ! ${BOINC_INVITATION_CODE} ]]; then
299 + elog "# rc-service boinc attach"
300 + elog " Enter the Project URL: ${BOINC_MASTER_URL}"
301 + else
302 + elog "- Master URL: ${BOINC_MASTER_URL}"
303 + elog "- Invitation code: ${BOINC_INVITATION_CODE}"
304 + fi
305 +}
306 +
307 +# @FUNCTION: boinc-app_pkg_postrm
308 +# @DESCRIPTION:
309 +# Display helpful instructions on how to cleanly uninstall unmerged
310 +# applications.
311 +boinc-app_pkg_postrm() {
312 + if [[ ! ${REPLACED_BY_VERSION} ]]; then
313 + local gui_rpc_auth="$(get_boincdir)/gui_rpc_auth.cfg"
314 + local passwd=$(cat "${EROOT}${gui_rpc_auth}")
315 + if [[ ! ${passwd} ]]; then
316 + passwd="\$(cat ${gui_rpc_auth})"
317 + fi
318 +
319 + elog
320 + elog "You should detach this project from the BOINC client"
321 + elog "to stop current tasks and delete remaining project files:"
322 + elog
323 + elog "$ boinccmd --passwd ${passwd} --project ${BOINC_MASTER_URL} detach"
324 + fi
325 +}
326 +
327 +_BOINC_APP_ECLASS=1
328 +fi