Repository navigation
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·82 lines (72 loc) · 2.02 KB
/
Copy pathrun.sh
File metadata and controls
executable file
·82 lines (72 loc) · 2.02 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
#!/usr/bin/env bash
# Copyright (c) 2025 TESAIoT Platform (TESA)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
VENV_DIR="$SCRIPT_DIR/.venv"
PYTHON_BIN="python3"
# Helper script to bootstrap a virtualenv and run the CLI in line with the README steps.
usage() {
cat <<USAGE
Usage:
$(basename "$0") bootstrap # Create virtualenv and install dependencies
$(basename "$0") run [args...] # Run the app (virtualenv must exist)
USAGE
}
ensure_python() {
# Ensure python3 exists in PATH so we fail early with a friendly tip.
if ! command -v "$PYTHON_BIN" >/dev/null 2>&1; then
echo "python3 is required" >&2
exit 1
fi
}
bootstrap() {
# Mirrors the README "bootstrap" section: create venv, upgrade pip, install deps.
ensure_python
if [ ! -d "$VENV_DIR" ]; then
"$PYTHON_BIN" -m venv "$VENV_DIR"
fi
source "$VENV_DIR/bin/activate"
pip install --upgrade pip
pip install -r "$SCRIPT_DIR/requirements.txt"
echo "Dependency installation completed" >&2
}
run_app() {
# Activate the virtualenv, then pass through any CLI parameters to Typer.
ensure_python
if [ ! -d "$VENV_DIR" ]; then
echo "Virtualenv not found. Run '$0 bootstrap' first." >&2
exit 1
fi
source "$VENV_DIR/bin/activate"
PYTHONPATH="$SCRIPT_DIR" python "$SCRIPT_DIR/app.py" "$@"
}
if [ $# -lt 1 ]; then
usage
exit 1
fi
case "$1" in
bootstrap)
shift
bootstrap "$@"
;;
run)
shift
run_app "$@"
;;
*)
usage
exit 1
;;
esac