-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·130 lines (109 loc) · 3.05 KB
/
run.sh
File metadata and controls
executable file
·130 lines (109 loc) · 3.05 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$ROOT_DIR"
command_exists() {
command -v "$1" >/dev/null 2>&1
}
detect_linux_distro() {
if [[ ! -r /etc/os-release ]]; then
echo "unknown"
return
fi
# shellcheck disable=SC1091
source /etc/os-release
local distro="${ID:-unknown}"
local like="${ID_LIKE:-}"
case " $distro $like " in
*" ubuntu "*|*" debian "*)
echo "ubuntu"
;;
*" fedora "*|*" rhel "*|*" centos "*)
echo "fedora"
;;
*" arch "*)
echo "arch"
;;
*)
echo "$distro"
;;
esac
}
missing_fetcher_help() {
local distro="$1"
echo "uv is not installed, and neither curl nor wget is available."
case "$distro" in
ubuntu)
echo "Install curl with: sudo apt install curl"
;;
fedora)
echo "Install curl with: sudo dnf install curl"
;;
arch)
echo "Install curl with: sudo pacman -S curl"
;;
*)
echo "Install curl or wget, then run this script again."
;;
esac
}
install_uv() {
if command_exists uv; then
return
fi
local platform
platform="$(uname -s)"
if [[ "$platform" == "Linux" ]]; then
local distro
distro="$(detect_linux_distro)"
echo "Installing uv for Linux (${distro})..."
else
echo "Installing uv for ${platform}..."
fi
if command_exists curl; then
curl -LsSf https://astral.sh/uv/install.sh | sh
elif command_exists wget; then
wget -qO- https://astral.sh/uv/install.sh | sh
else
missing_fetcher_help "${distro:-unknown}"
exit 1
fi
export PATH="$HOME/.local/bin:$HOME/.cargo/bin:$PATH"
if ! command_exists uv; then
echo "uv was installed, but it is not on PATH. Add ~/.local/bin to PATH and try again."
exit 1
fi
}
ensure_environment() {
install_uv
if ! uv python find 3.12 >/dev/null 2>&1; then
uv python install 3.12
fi
if [[ ! -d .venv ]]; then
uv venv --python 3.12 .venv
fi
uv sync --frozen --no-default-groups --inexact
}
launch_in_new_terminal() {
local quoted_root
local quoted_python
printf -v quoted_root "%q" "$ROOT_DIR"
printf -v quoted_python "%q" "${ROOT_DIR}/.venv/bin/python"
local command="cd ${quoted_root} && ${quoted_python} app.py"
if command_exists gnome-terminal; then
gnome-terminal -- bash -lc "${command}; exec bash"
elif command_exists konsole; then
konsole -e bash -lc "${command}; exec bash"
elif command_exists xterm; then
xterm -e bash -lc "${command}; exec bash"
else
echo "No supported terminal emulator found; running in this terminal instead."
"${ROOT_DIR}/.venv/bin/python" app.py
fi
}
ensure_environment
if [[ "${1:-}" == "--new-terminal" ]]; then
launch_in_new_terminal
else
"${ROOT_DIR}/.venv/bin/python" app.py
fi