| Commit message (Collapse) | Author | Age | Files | Lines |
... | |
|
|
|
|
|
|
|
|
|
|
|
| |
Consider the value of EINFO_LOG to be false in the event that it is
equal to the value of RC_SERVICE. The reason for this is that, as of the
time of writing, openrc-run(8) defines and uses EINFO_LOG in a way that
is at odds with gentoo-functions. Ideally, the behaviour of OpenRC would
be modified so that it becomes possible to jettison this workaround.
Fixes: 0dd8364c03c6f8737150ee4f146ddeeec57efee9
Bug: https://bugs.gentoo.org/936613
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
| |
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
| |
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
|
|
| |
The POSIX-1.2024 specification was published on 2024/06/14.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
|
|
|
|
|
| |
Test whether the (non-standard) local builtin is present and behaving in
a manner considered to be conventional. Should the test fail, refrain
from conducting any further tests. This causes the test suite to fail
early for ksh - a shell not currently supported by the project.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
|
|
| |
https://austingroupbugs.net/view.php?id=339
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
|
|
|
| |
Doing so simplifies the case where /proc/uptime is read. Having one more
digit's worth of accuracy is no bad thing either.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
|
|
|
| |
Also, require for true(1) to be executable in order for it to be deemed
usable.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
|
|
|
|
|
|
|
| |
The function is a simple wrapper around GNU find(1) which presumes the
intent to use the -files0-from option to read NUL-delimited path names
from the standard input. The benefit in having it is twofold. Firstly,
the _select_by_mtime() and is_older_than() functions are thereby made a
little easier to read. Secondly, the genfun_bin_find variable is now
initialised lazily.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
|
|
|
|
| |
The mawk implementation does not react well to FS containing an invalid
ERE at any juncture. Address the issue by composing the pattern in full
before assigning it to FS.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
|
|
|
| |
Directly implement a round half up algorithm for sh, thereby avoiding a
command substitution and a potential subshell along with it.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
|
|
|
| |
It was not translating IFS to FS correctly. Have it do so and extend the
test suite accordingly.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
|
|
|
| |
I'm not yet ready to commit to it being among the core functions for the
inaugural API level.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Here are some examples which presume the default value of IFS.
contains_all " cat mat " cat dog # returns 1
contains_all " cat mat " mat cat # returns 0
contains_any " cat mat " cat dog # returns 0
contains_any " cat mat " dog # returns 1
Here are some examples showing that IFS is taken into account.
IFS=, contains_all "cat,mat" cat dog # returns 1
IFS=, contains_all "cat,mat" mat cat # returns 0
IFS=, contains_any "cat,mat" cat dog # returns 0
IFS=, contains_any "cat,mat" dog # returns 1
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
|
|
|
| |
Though it works very well, I'm not yet ready to commit to it being among
the core functions for the inaugural API level.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
|
|
| |
Thus adhering to Gentoo's convention.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
| |
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
|
|
| |
As based on the implementation in Maarten Billemont's bashlib library.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
| |
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
|
|
|
|
| |
This renders the behaviour of whenceforth() almost equivalent to type -P
in the absence of the -x option, the exception being that whenceforth()
never consults the hash table.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
| |
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
|
|
|
| |
This also makes it more pleasant to read where using the (proper) tab
size of 8 spaces.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
| |
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
|
|
|
| |
POSIX sh does not support substring expansion so it may come in handy.
The implementation is based on the awk function of the same name.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The idea is to be able to write new functions without having to
initially commit to their being in the core library or, indeed, any of
the other modules. Experimental functions may be promoted or simply
dropped without warning if it is decided that they are insufficiently
useful to merit incorporation.
This initial commit defines the is_interactive() and prepend_ts()
functions.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
|
|
|
| |
After all, the -v option is an extension. This was a mistake made
through copying and pasting during a bout of refactoring and rebasing.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
|
|
| |
While it is correct to do so, the key may be created without assignment.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
These functions allow for it to be determined whether an arbitrary
simple command yields true for either all of an arbitrary list of
parameters or at least one of them. The simple command shall be given
each parameter, one at a time. Some examples are shown below.
trueof_all test -d -- / /var/empty # returns 0
trueof_all test -d -- / /dev/null # returns 1
trueof_any test -d -- / /dev/null # returns 0
trueof_any test -d -- /etc/fstab /dev/null # returns 1
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
|
|
|
|
| |
This function makes it trivial to issue a network request - such as HTTP
GET - in a manner that is quiet and which yields a useful exit status
value. It prefers curl if present but supports wget also.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
|
|
| |
I can think of no compelling reason not to.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
| |
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Firstly, the "." builtin is not specified to support the passing of
arguments; such is a bashism. It is rather presumptuous to act as if the
present contents of the positional parameters are for the benefit of
gentoo-functions at the time of its initialisation.
Secondly, there exists a de-facto standard for suppressing colored
output, which is to define NO_COLOR as a non-empty string, per
https://no-color.org.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
For many years, the implied purpose of gentoo-functions has been to
provided parallel implementations of utilities provided by OpenRC, along
with a handful of peripheral functions. It is probably also fair to say
that it has not seen much in the way of maintenance until comparatively
recently. As of the present day, the status quo is not ideal. For one
thing, the library has never been particularly useful beyond this
definition. It is my hope that some of the recently added functions will
be well received by those needing to write effective shell scripts in
Gentoo for a number of relevant tasks. Certainly, there remains ample
room for improvement in that regard.
For another thing, the implementation of gentoo-functions is presently
inflexible. For instance, it is impossible to source the functions from
an OpenRC runscript without overriding the OpenRC implementations. Nor
may one source the functions from an ebuild or eclass without overriding
the Portage implementations. Indeed, it is has become something of a
mess. Not only does gentoo-functions implement a number of functions
that shadow the OpenRC implementations but so does Portage, owing to the
existence of its "isolated-functions.sh" unit. What's more, the various
implementations are of varying quality and do not necessarily behave in
the same manner.
This commit aims to address some of these issues by rendering
gentoo-functions modular in nature. It establishes the premise of having
a core library, with collections of additional functions being
optionally declarable. As such, all of the functions that shadow OpenRC
have been relocated to a unit named "rc.sh". This first change
encompasses the following public functions:
- ebegin
- eend
- eerrorn
- eindent
- einfon
- eoutdent
- esyslog
- ewarnn
- ewend
- get_bootparam
- is_older_than
- veend
- vewend
- yesno
Similarly, all of the functions that exclusively shadow Portage have
been relocated to a unit named "portage.sh". This second change
encompasses the following public functions:
- die
- edo
- eqatag
- eqawarn
The functions that remain in the "functions.sh" unit may now be
considered as core functions. To accommodate all of this, a new
GENFUN_MODULES variable is supported, whose behaviour is described
herewith.
If GENFUN_MODULES is found to be set at the time of "functions.sh" being
sourced, it shall be taken as a list of zero or more blank-separated
words. In turn, these words shall be taken as the basenames of
potentially available modules - not including the .sh suffix.
Presently, the only supported module names are "rc" and "portage".
Should either or both of these names be present, their respective units
shall be automatically sourced. If neither are present, no additional
units shall be sourced. Consequently, it becomes possible for a consumer
of gentoo-functions to request that only the core functions be declared
by writing:
GENFUN_MODULES= . /lib/gentoo/functions.sh
If, on the other hand, GENFUN_MODULES is found not to be set then
heuristics shall be employed to determine which of the additional units
should be sourced. The intent of these heuristics is twofold. Firstly,
to maintain an adequate degree of backward-compatibility and, secondly,
to act as is appropriate based on the characteristics of the operating
environment. The exact behaviour of these heuristics is as follows.
If the present shell is neither executing a runscript nor a subprocess
of one, the ensuing behaviour shall be as if "rc" had initially been
among the names defined by the GENFUN_MODULES variable.
If the present shell is not a subprocess of portage, the ensuing
behaviour shall be as if "portage" had initially been among the names
defined by the GENFUN_MODULES variable.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
|
|
|
|
|
|
|
|
| |
Examples follow.
is_anyof y x y z # returns 0
is_anoyf y x w z # returns 1
is_subset x y -- x y z # returns 0
is_subset x y z -- z y x # returns 0
is_subset x y -- x w z # returns 1
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
|
|
|
|
| |
The function determines whether the current shell is a subprocess of a
systemd unit that handles a service, socket, mount point or swap device,
per systemd.exec(5).
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
|
|
|
| |
The function determines whether the current shell is executing an OpenRC
runscript, or is a subprocess of one.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
|
|
|
| |
The function determines whether the current shell appears to be a
subprocess of portage.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
| |
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Limit the rate at which genfun_cols can be refreshed to intervals that
are no shorter than 5 decisconds (half a second). Doing so renders
repeated calls to the _eend() function at short intervals faster by an
order of magnitude.
On one of my fastest available machines, I performed the following
benchmark with bash 5.2.26.
$ time for ((i=0; i<50000; i++)); do ebegin "$i"; eend; done
The results were as follows.
BEFORE
real 0m56.897s
user 0m16.990s
sys 0m28.540s
AFTER
real 0m6.663s
user 0m6.435s
sys 0m0.191s
On one of my slowest available machines, I performed the following
benchmark with bash 5.2.26.
$ time for ((i=0; i<15000; i++)); do ebegin "$i"; eend; done
The results were as follows.
BEFORE
real 0m52.557s
user 0m34.484s
sys 0m18.231s
AFTER
real 0m11.422s
user 0m10.654s
sys 0m0.535s
On that same (slow) machine, I performed the following benchmark with
dash 0.5.12.
$ time dash -c '
. ./functions.sh
while :; do ebegin $((i+=1)); eend; [ $i -eq 15000 ] && exit; done'
The results were as follows.
BEFORE
real 0m43.762s
user 0m22.202s
sys 0m21.415s
AFTER
real 0m3.470s
user 0m2.535s
sys 0m0.736s
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
|
|
|
|
|
|
|
| |
In cases where the value of genfun_tty is lower than 2, it is implied
that the standard output refers either to a terminal insufficiently
capable of handling ECMA-48 CSI sequences or to a resource that is not a
terminal. Use <space> characters to indent the indicator to the extent
that the last character falls on the 80th column. Previously, the
indicator was indented by only one <space>.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
|
|
|
|
|
| |
In cases where the value of genfun_tty is 2, render it impossible for
_eend() ever to produce a CHA sequence that incorporates a negative
column number. Some terminal emulators handle it sensibly whereas others
do not.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
| |
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
|
|
|
| |
I'd rather leave the use of ewarn() to the consumers of
gentoo-functions.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
|
|
| |
Also, markedly improve the comment that documents the function.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
|
|
| |
So as to maintain an alphabetical order.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
| |
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
|
|
|
| |
This allows for simple API capability checks to be performed by users of
the library. It might also obsolete the RC_GOT_FUNCTIONS variable.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Here is an example of how to use it.
$ parallel_run 0 sha256sum dir/*
Simple commands of a greater level of sophistication can easily be
composed with the aid of functions.
$ sm3sum() { cksum -a sm3 "$@"; }
$ parallel_run 0 sm3sum dir/*
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
|
|
|
| |
It stands a good chance of printing a useful value, even in the case
that nproc(1) from coreutils is unavailable.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|
|
|
|
|
|
|
| |
It acts much as type -P does in bash. I would have liked to name it
whence but ksh and zsh already have builtins by that name.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
|