logo

utils

~/.local/bin tools and git-hooks git clone https://hacktivis.me/git/utils.git
commit: d1d68799f1823ca77c36aa801d846dea46d476a9
parent 4e8b536118f87ce6afe62812445c5d156f405410
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sun, 20 Mar 2022 15:30:29 +0100

Add NO_BWRAP for Gentoo

Diffstat:

MREADME.md11++++++++---
Mtest-bin/id30++++++++++++++++--------------
Mtest-sbin/memsys15+++++++++------
3 files changed, 33 insertions(+), 23 deletions(-)

diff --git a/README.md b/README.md @@ -7,8 +7,13 @@ Tested on Linux(musl), FreeBSD, NetBSD, OpenBSD: # Dependencies - POSIX System -- (optional) libbsd: To build `bin/strings` and `bin/humanize` +- (optional) libbsd: <https://libbsd.freedesktop.org/> To build `bin/strings` and `bin/humanize` - (optional, test) ATF: <https://github.com/jmmv/atf> - (optional, test) Kyua: <https://github.com/jmmv/kyua> -- (optional, lint) mandoc: for linting the manual pages -- (optional, lint) shellcheck: for linting `./configure` and shell scripts +- (optional, test) bwrap: <https://github.com/containers/bubblewrap/> For safely overlaying false files on the root filesystem +- (optional, lint) mandoc: <https://mdocml.bsd.lv/> For linting the manual pages +- (optional, lint) shellcheck: <https://www.shellcheck.net/> For linting `./configure` and shell scripts + +## Packaging +- The `./configure` script isn't auto*hell based, you can pass it arguments via key-value arguments or environment variables +- You can define the `NO_BWRAP` environment variable to skip the bwrap-based tests which can cause issues in some environments like Gentoo `sandbox` diff --git a/test-bin/id b/test-bin/id @@ -59,48 +59,50 @@ atf_test_case noetc noetc_body() { bwrap_args="--bind / / --bind /var/empty /etc" - command -v bwrap >/dev/null 2>/dev/null || atf_skip "'bwrap' command not found" + command -v "${BWRAP:-bwrap}" >/dev/null 2>/dev/null || atf_skip "${BWRAP:-bwrap} command not found" + [ -n "${NO_BWRAP}" ] && atf_skip "'NO_BWRAP' set" set -f # shellcheck disable=SC2086 - atf_check -o "inline:uid=$(id -u) gid=$(id -g) groups=$(id -g)\n" -- bwrap ${bwrap_args} ../bin/id + atf_check -o "inline:uid=$(id -u) gid=$(id -g) groups=$(id -g)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../bin/id # shellcheck disable=SC2086 - atf_check -o "inline:uid=$(id -ur) gid=$(id -gr) groups=$(id -g)\n" -- bwrap ${bwrap_args} ../bin/id -r + atf_check -o "inline:uid=$(id -ur) gid=$(id -gr) groups=$(id -g)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../bin/id -r # shellcheck disable=SC2086 - atf_check -s exit:1 -- bwrap ${bwrap_args} ../bin/id -n + atf_check -s exit:1 -- "${BWRAP:-bwrap}" ${bwrap_args} ../bin/id -n # shellcheck disable=SC2086 - atf_check -s exit:1 -- bwrap ${bwrap_args} ../bin/id -nr + atf_check -s exit:1 -- "${BWRAP:-bwrap}" ${bwrap_args} ../bin/id -nr # shellcheck disable=SC2086 - atf_check -o "inline:$(id -g)\n" -- bwrap ${bwrap_args} ../bin/id -g + atf_check -o "inline:$(id -g)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../bin/id -g # shellcheck disable=SC2086 - atf_check -o "inline:$(id -gr)\n" -- bwrap ${bwrap_args} ../bin/id -gr + atf_check -o "inline:$(id -gr)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../bin/id -gr } atf_test_case nogroup nogroup_body() { bwrap_args="--bind / / --bind /dev/null /etc/group" - command -v bwrap >/dev/null 2>/dev/null || atf_skip "'bwrap' command not found" + command -v "${BWRAP:-bwrap}" >/dev/null 2>/dev/null || atf_skip "${BWRAP:-bwrap} command not found" + [ -n "${NO_BWRAP}" ] && atf_skip "'NO_BWRAP' set" set -f # shellcheck disable=SC2086 - atf_check -o "inline:uid=$(id -u)($(id -un)) gid=$(id -g) groups=$(id -g)\n" -- bwrap ${bwrap_args} ../bin/id + atf_check -o "inline:uid=$(id -u)($(id -un)) gid=$(id -g) groups=$(id -g)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../bin/id # shellcheck disable=SC2086 - atf_check -o "inline:uid=$(id -ur)($(id -unr)) gid=$(id -gr) groups=$(id -gr)\n" -- bwrap ${bwrap_args} ../bin/id + atf_check -o "inline:uid=$(id -ur)($(id -unr)) gid=$(id -gr) groups=$(id -gr)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../bin/id # shellcheck disable=SC2086 - atf_check -s exit:1 -o "inline:uid=$(id -un)\n" -- bwrap ${bwrap_args} ../bin/id -n + atf_check -s exit:1 -o "inline:uid=$(id -un)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../bin/id -n # shellcheck disable=SC2086 - atf_check -s exit:1 -o "inline:uid=$(id -unr)\n" -- bwrap ${bwrap_args} ../bin/id -nr + atf_check -s exit:1 -o "inline:uid=$(id -unr)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../bin/id -nr # shellcheck disable=SC2086 - atf_check -o "inline:$(id -g)\n" -- bwrap ${bwrap_args} ../bin/id -g + atf_check -o "inline:$(id -g)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../bin/id -g # shellcheck disable=SC2086 - atf_check -o "inline:$(id -gr)\n" -- bwrap ${bwrap_args} ../bin/id -gr + atf_check -o "inline:$(id -gr)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../bin/id -gr } atf_test_case badarg diff --git a/test-sbin/memsys b/test-sbin/memsys @@ -2,10 +2,11 @@ atf_test_case basic cleanup basic_body() { - command -v bwrap >/dev/null 2>/dev/null || atf_skip "'bwrap' command not found" + command -v "${BWRAP:-bwrap}" >/dev/null 2>/dev/null || atf_skip "${BWRAP:-bwrap} command not found" + [ -n "${NO_BWRAP}" ] && atf_skip "'NO_BWRAP' set" atf_check touch ./tmp-memsys - atf_check -- bwrap --bind / / --bind ./tmp-memsys /sys/power/state ../sbin/memsys + atf_check -- "${BWRAP:-bwrap}" --bind / / --bind ./tmp-memsys /sys/power/state ../sbin/memsys atf_check -o 'inline:mem' cat tmp-memsys } basic_cleanup() { @@ -14,11 +15,12 @@ basic_cleanup() { atf_test_case chmod_000 cleanup chmod_000_body() { - command -v bwrap >/dev/null 2>/dev/null || atf_skip "'bwrap' command not found" + command -v "${BWRAP:-bwrap}" >/dev/null 2>/dev/null || atf_skip "${BWRAP:-bwrap} command not found" + [ -n "${NO_BWRAP}" ] && atf_skip "'NO_BWRAP' set" atf_check touch ./tmp-memsys.000 atf_check chmod 000 ./tmp-memsys.000 - atf_check -s exit:1 -e 'inline:memsys: open("/sys/power/state"): Permission denied\n' -- bwrap --bind / / --bind ./tmp-memsys.000 /sys/power/state ../sbin/memsys + atf_check -s exit:1 -e 'inline:memsys: open("/sys/power/state"): Permission denied\n' -- "${BWRAP:-bwrap}" --bind / / --bind ./tmp-memsys.000 /sys/power/state ../sbin/memsys atf_check chmod 600 ./tmp-memsys.000 atf_check -o empty cat tmp-memsys.000 } @@ -28,9 +30,10 @@ chmod_000_cleanup() { atf_test_case devfull devfull_body() { - command -v bwrap >/dev/null 2>/dev/null || atf_skip "'bwrap' command not found" + command -v "${BWRAP:-bwrap}" >/dev/null 2>/dev/null || atf_skip "${BWRAP:-bwrap} command not found" + [ -n "${NO_BWRAP}" ] && atf_skip "'NO_BWRAP' set" - atf_check -s exit:1 -e 'inline:memsys: open("/sys/power/state"): Permission denied\n' -- bwrap --bind / / --bind /dev/full /sys/power/state ../sbin/memsys + atf_check -s exit:1 -e 'inline:memsys: open("/sys/power/state"): Permission denied\n' -- "${BWRAP:-bwrap}" --bind / / --bind /dev/full /sys/power/state ../sbin/memsys } atf_init_test_cases() {