1#!/bin/sh
2
3umask 077
4set -e
5set -x
6
7# emulate realpath(), in case coreutils or equivalent is not installed.
8abspath() {
9    f="$*"
10    if [ -d "$f" ]; then
11        dir="$f"
12        base=""
13    else
14        dir="$(dirname "$f")"
15        base="/$(basename "$f")"
16    fi
17    dir="$(cd "$dir" && pwd)"
18    echo "$dir$base"
19}
20
21UNAME_OS=$(uname -s | cut -d_ -f1)
22if test "$UNAME_OS" = 'CYGWIN' || \
23   test "$UNAME_OS" = 'MSYS' || \
24   test "$UNAME_OS" = 'MINGW' || \
25   test "$UNAME_OS" = 'MINGW32' || \
26   test "$UNAME_OS" = 'MINGW64'; then
27  if test "$APPVEYOR" = 'True'; then
28    echo "This test is disabled on Windows CI, as it requires firewall exemptions. Skipping." >&2
29    exit 77
30  fi
31fi
32
33# find the tor binary
34if [ $# -ge 1 ]; then
35  TOR_BINARY="${1}"
36  shift
37else
38  TOR_BINARY="${TESTING_TOR_BINARY:-./src/app/tor}"
39fi
40
41TOR_BINARY="$(abspath "$TOR_BINARY")"
42
43echo "TOR BINARY IS ${TOR_BINARY}"
44
45if "${TOR_BINARY}" --list-modules | grep -q "relay: no"; then
46  echo "This test requires the relay module. Skipping." >&2
47  exit 77
48fi
49
50tmpdir=
51clean () {
52  if [ -n "$tmpdir" ] && [ -d "$tmpdir" ]; then
53    rm -rf "$tmpdir"
54  fi
55}
56
57trap clean EXIT HUP INT TERM
58
59tmpdir="$(mktemp -d -t tor_include_test.XXXXXX)"
60if [ -z "$tmpdir" ]; then
61  echo >&2 mktemp failed
62  exit 2
63elif [ ! -d "$tmpdir" ]; then
64  echo >&2 mktemp failed to make a directory
65  exit 3
66fi
67
68datadir="$tmpdir/data"
69mkdir "$datadir"
70
71configdir="$tmpdir/config"
72mkdir "$configdir"
73
74# translate paths to windows format
75if test "$UNAME_OS" = 'CYGWIN' || \
76   test "$UNAME_OS" = 'MSYS' || \
77   test "$UNAME_OS" = 'MINGW' || \
78   test "$UNAME_OS" = 'MINGW32' || \
79   test "$UNAME_OS" = 'MINGW64'; then
80    datadir=$(cygpath --windows "$datadir")
81    configdir=$(cygpath --windows "$configdir")
82fi
83
84# create test folder structure in configdir
85torrcd="$configdir/torrc.d"
86mkdir "$torrcd"
87mkdir "$torrcd/folder"
88mkdir "$torrcd/empty_folder"
89echo "NodeFamily 1" > "$torrcd/01_one.conf"
90echo "NodeFamily 2" > "$torrcd/02_two.conf"
91echo "NodeFamily 3" > "$torrcd/aa_three.conf"
92echo "NodeFamily 42" > "$torrcd/.hidden.conf"
93echo "NodeFamily 6" > "$torrcd/foo"
94touch "$torrcd/empty.conf"
95echo "# comment" > "$torrcd/comment.conf"
96echo "NodeFamily 4" > "$torrcd/folder/04_four.conf"
97echo "NodeFamily 5" > "$torrcd/folder/05_five.conf"
98torrc="$configdir/torrc"
99echo "Sandbox 1" > "$torrc"
100echo "
101%include $torrcd/*.conf
102%include $torrcd/f*
103%include $torrcd/*/*
104%include $torrcd/empty_folder
105%include $torrcd/empty.conf
106%include $torrcd/comment.conf
107" >> "$torrc"
108
109"${PYTHON:-python}" "${abs_top_srcdir:-.}/src/test/test_include.py" "${TOR_BINARY}" "$datadir" "$configdir"
110
111exit $?
112