-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·97 lines (87 loc) · 2.9 KB
/
Copy pathrun.sh
File metadata and controls
executable file
·97 lines (87 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env bash
#
# run.sh -- build the native libraries and launch the Onion Router GUI.
#
# 1. Builds libonion_crypto.so + libonion_engine.so (and the test binaries)
# via the Makefile/CMake wrapper.
# 2. Picks a Python interpreter that actually has PyGObject/GTK available
# (the system /usr/bin/python3 usually does; a pyenv shim often does not).
# 3. Launches the GTK front-end.
#
# Usage:
# ./run.sh # build + run the GUI
# ./run.sh --test # build + run the C/C++ test suites, then exit
# ./run.sh --no-build # skip the build step, just launch
#
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
DO_BUILD=1
DO_TEST=0
for arg in "$@"; do
case "$arg" in
--no-build) DO_BUILD=0 ;;
--test) DO_TEST=1 ;;
-h|--help)
grep '^#' "$0" | sed 's/^# \{0,1\}//'
exit 0
;;
*) echo "Unknown option: $arg" >&2; exit 2 ;;
esac
done
# --- 1. Build --------------------------------------------------------------
if [[ "$DO_BUILD" -eq 1 ]]; then
echo ">> Building native libraries ..."
if command -v cmake >/dev/null 2>&1; then
make build
else
echo "cmake not found; falling back to a direct compiler invocation." >&2
mkdir -p build/lib
gcc -O2 -Wall -Wextra -fPIC -shared \
-o build/lib/libonion_crypto.so src/crypto/*.c -lcrypto
g++ -O2 -std=c++17 -fPIC -shared \
-o build/lib/libonion_engine.so src/engine/*.cpp \
-Isrc/crypto -Isrc/engine -Lbuild/lib -lonion_crypto -lcrypto
fi
fi
if [[ "$DO_TEST" -eq 1 ]]; then
echo ">> Running test suites ..."
make test
exit 0
fi
# --- 2. Find a GTK-capable Python -----------------------------------------
pick_python() {
local candidates=("/usr/bin/python3" "python3" "python")
if [[ -n "${ONION_PYTHON:-}" ]]; then
candidates=("$ONION_PYTHON" "${candidates[@]}")
fi
for py in "${candidates[@]}"; do
if command -v "$py" >/dev/null 2>&1; then
if "$py" - <<'PY' >/dev/null 2>&1
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk # noqa
PY
then
echo "$py"
return 0
fi
fi
done
return 1
}
PYTHON="$(pick_python || true)"
if [[ -z "$PYTHON" ]]; then
cat >&2 <<'MSG'
ERROR: could not find a Python interpreter with PyGObject/GTK 3.
Install the GTK stack, for example on Debian/Ubuntu:
sudo apt-get install -y python3-gi python3-gi-cairo gir1.2-gtk-3.0 \
libgirepository1.0-dev pkg-config
Then re-run ./run.sh (or set ONION_PYTHON=/path/to/python).
MSG
exit 1
fi
# --- 3. Launch -------------------------------------------------------------
echo ">> Launching Onion Router GUI with: $PYTHON"
export ONION_LIB_DIR="${ONION_LIB_DIR:-$SCRIPT_DIR/build/lib}"
exec "$PYTHON" src/gui/main.py