]> arthur.barton.de Git - bup.git/blob - t/lib.sh
cirrus: allow failures on macos with python 2
[bup.git] / t / lib.sh
1 # Assumes shell is Bash, and pipefail is set.
2
3 bup_t_lib_script_home=$(cd "$(dirname $0)" && pwd) || exit $?
4
5 bup-cfg-py() { "$bup_t_lib_script_home/../config/bin/python" "$@"; }
6 bup-python() { "$bup_t_lib_script_home/../dev/bup-python" "$@"; }
7
8 force-delete()
9 {
10     "$bup_t_lib_script_home/force-delete" "$@"
11 }
12
13 resolve-parent()
14 {
15     test "$#" -eq 1 || return $?
16     echo "$1" | \
17         PYTHONPATH="$bup_t_lib_script_home/../lib" bup-python -c \
18         "import sys, bup.helpers; print(bup.helpers.resolve_parent(sys.stdin.readline()))" \
19         || return $?
20 }
21
22 current-filesystem()
23 {
24     local kernel="$(uname -s)" || return $?
25     case "$kernel" in
26         NetBSD)
27             df -G . | sed -En 's/.* ([^ ]*) fstype.*/\1/p'
28             ;;
29         SunOS)
30             df -g . | sed -En 's/.* ([^ ]*) fstype.*/\1/p'
31             ;;
32         *)
33             df -T . | awk 'END{print $2}'
34     esac
35 }
36
37 path-filesystems()
38 (
39     # Return filesystem for each dir from $1 to /.
40     # Perhaps for /foo/bar, "ext4\next4\nbtrfs\n".
41     test "$#" -eq 1 || exit $?
42     cd "$1" || exit $?
43     current-filesystem || exit $?
44     dir="$(pwd)" || exit $?
45     while test "$dir" != /; do
46         cd .. || exit $?
47         dir="$(pwd)" || exit $?
48         current-filesystem || exit $?
49     done
50     exit 0
51 )
52
53 escape-erx()
54 {
55     sed 's/[][\.|$(){?+*^]/\\&/g' <<< "$*"
56 }