#!/hint/bash if [[ $HOME == "$(eval echo ~$USER)" ]]; then libremessages error "\$HOME is the default for %s; use testenv: %s" "$USER" "$HOME" exit 1 fi _common_before() { : } common_before() { : } common_after() { : } before() { unset PKGDEST SRCDEST SRCPKGDEST LOGDEST unset BUILDDIR unset PKGEXT SRCEXT unset GPGKEY PACKAGER killall gpg-agent &>/dev/null || true tmpdir="$(mktemp -d --tmpdir "test-${roundup_desc//\//-}.${roundup_test_name}.XXXXXXXXXXXX")" chmod 755 "$tmpdir" stat=0 _common_before common_before } after() { common_after killall gpg-agent &>/dev/null || true if [[ -f "$tmpdir/.used-sudo" ]]; then sudo rm -rf -- "$tmpdir" "$XDG_CONFIG_HOME" "$XDG_CACHE_HOME" else rm -rf -- "$tmpdir" "$XDG_CONFIG_HOME" "$XDG_CACHE_HOME" fi } setup_chrootdir() { if [[ -z "$chrootdir" ]]; then export chrootdir="$(mktemp -d --tmpdir "test-chrootdir.XXXXXXXXXXXX")" trap "$(printf '_cleanup_chrootdir %q' "$chrootdir")" EXIT fi _common_before() { mkdir -p "$XDG_CONFIG_HOME"/libretools echo "BLACKLIST=https://git.parabola.nu/blacklist.git/plain/blacklist.txt" >"$XDG_CONFIG_HOME"/libretools/libretools.conf printf 'CHROOTDIR=%q\n' "${chrootdir}" > "$XDG_CONFIG_HOME"/libretools/chroot.conf printf 'CHROOT=%q\n' default >> "$XDG_CONFIG_HOME"/libretools/chroot.conf echo "CHROOTEXTRAPKG=()" >> "$XDG_CONFIG_HOME"/libretools/chroot.conf } } _cleanup_chrootdir() ( chrootdir=$1 shopt -s nullglob if [[ $SUDO ]]; then if [[ "$(stat -f -c %T "$chrootdir")" == btrfs ]]; then sudo find "$chrootdir" -depth -inum 256 -exec \ btrfs subvolume delete {} \; &>/dev/null fi sudo rm -rf -- "$chrootdir" else rm -rf -- "$chrootdir" fi ) require() ( set +x local missing=() if libremessages in_array "network" "$@" && ! [[ $NETWORK ]]; then missing+=('networking') fi if libremessages in_array "sudo" "$@" && ! [[ $SUDO ]]; then missing+=('sudo') fi if libremessages in_array "btrfs" "$@" && ! [[ "$(stat -f -c %T "$chrootdir" 2>/dev/null || true)" == 'btrfs' ]]; then missing+=('btrfs') fi if (( ${#missing[@]} )); then libremessages warning "Next test requires %s; Skipping (passing)..." "$(echo "${missing[*]}"|sed 's/ /, /g')" &>/dev/tty return 1 fi if libremessages in_array "sudo" "$@"; then touch "$tmpdir/.used-sudo" fi return 0 ) empty() { diff -u /dev/null "$1" } # Just using '!' doesn't trip `set -e` not() ( set +x # we don't care about what is in the file on 'not empty' # checks, so redefine 'empty' to be a bit quieter. empty() { [[ $(stat -c %s "$1") -eq 0 ]] } ! eval "$@" ) # Plain command substitution would remove trailing whitespace, despite # being significant when testing for newline-terminated lines. equals() { local stdin IFS= read -rd '' stdin || : [[ $1 == "$stdin" ]] }