-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathvoxd.wrapper
More file actions
129 lines (114 loc) · 4.49 KB
/
voxd.wrapper
File metadata and controls
129 lines (114 loc) · 4.49 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
#!/usr/bin/env bash
set -euo pipefail
# Optional debug tracing for troubleshooting wrapper path decisions
if [[ -n "${VOXD_WRAPPER_DEBUG:-}" ]]; then
set -x
fi
log() {
if [[ -n "${VOXD_WRAPPER_DEBUG:-}" ]]; then
echo "[voxd.wrapper] $*"
fi
}
APPDIR=/opt/voxd
USER_VENV="$HOME/.local/share/voxd/.venv"
log "APPDIR=$APPDIR USER_VENV=$USER_VENV"
# Ensure ydotool picks up our user-scoped socket (matches our user service)
export YDOTOOL_SOCKET="${YDOTOOL_SOCKET:-$HOME/.ydotool_socket}"
log "YDOTOOL_SOCKET=$YDOTOOL_SOCKET"
# Ensure user-local bin is on PATH so ~/.local/bin tools are found
export PATH="$HOME/.local/bin:$PATH"
log "PATH=$PATH"
log "Checking for app venv python at $APPDIR/.venv/bin/python"
if [[ -x "$APPDIR/.venv/bin/python" ]]; then
PY="$APPDIR/.venv/bin/python"
log "Using app venv Python: $PY"
elif [[ -x "$USER_VENV/bin/python" ]]; then
PY="$USER_VENV/bin/python"
log "Using user venv Python: $PY"
else
PY="$(command -v python3 || command -v python)"
log "Using system Python candidate: $PY"
fi
# Guard against too-old system Python (e.g., Leap 15.x ships 3.6)
if [[ "$PY" != "$APPDIR/.venv/bin/python" && "$PY" != "$USER_VENV/bin/python" ]]; then
ver="$($PY - <<'PY'
import sys
print(f"{sys.version_info.major}.{sys.version_info.minor}")
PY
)"
log "System Python version: $ver"
# Check if version is >= 3.9
IFS='.' read -r major minor <<< "$ver"
if [[ "$major" -gt 3 ]] || [[ "$major" -eq 3 && "$minor" -ge 9 ]]; then
: # version is acceptable
else
# Attempt to create a user-local venv with any newer Python found
pick_python() {
for c in python3.12 python3.11 python3.10 python3.9 python3; do
if command -v "$c" >/dev/null 2>&1; then
v="$($c - <<'PY'
import sys
print(f"{sys.version_info.major}.{sys.version_info.minor}")
PY
)"
# Check if version is >= 3.9
IFS='.' read -r v_major v_minor <<< "$v"
if [[ "$v_major" -gt 3 ]] || [[ "$v_major" -eq 3 && "$v_minor" -ge 9 ]]; then
echo "$c"
return 0
fi
fi
done
echo ""
}
log "Attempting to locate newer system Python (>=3.9)"
CAND="$(pick_python)"
if [[ -n "$CAND" ]]; then
log "Found newer interpreter: $CAND"
mkdir -p "$(dirname "$USER_VENV")"
log "Creating user venv at $USER_VENV"
"$CAND" -m venv --system-site-packages "$USER_VENV" || true
if [[ -x "$USER_VENV/bin/python" ]]; then
PY="$USER_VENV/bin/python"
# Ensure required runtime deps are present in user venv
log "Upgrading pip in user venv"
"$PY" -m pip install --disable-pip-version-check -q --upgrade pip || true
log "Installing runtime deps in user venv"
"$PY" -m pip install --disable-pip-version-check -q platformdirs importlib-resources PyQt6 pyqtgraph sounddevice psutil numpy requests pyyaml tqdm pyperclip || true
else
echo "[voxd] System Python $ver is unsupported and user venv creation failed. Use 'bash packaging/install_voxd.sh <rpm>' or create $APPDIR/.venv with Python >= 3.9." >&2
exit 1
fi
else
echo "[voxd] System Python $ver is unsupported and no newer Python was found. Use 'bash packaging/install_voxd.sh <rpm>' to provision a newer Python, or create $APPDIR/.venv with Python >= 3.9." >&2
exit 1
fi
fi
fi
# Ensure Python can import the embedded source tree
export PYTHONPATH="$APPDIR/src${PYTHONPATH:+:$PYTHONPATH}"
log "PYTHONPATH=$PYTHONPATH"
# If the managed venv exists, prefer it entirely to guarantee deps
if [[ -x "$APPDIR/.venv/bin/python" ]]; then
PY="$APPDIR/.venv/bin/python"
export PYTHONPATH="$APPDIR/src${PYTHONPATH:+:$PYTHONPATH}"
log "Preferring app venv Python: $PY"
elif [[ -x "$USER_VENV/bin/python" ]]; then
PY="$USER_VENV/bin/python"
export PYTHONPATH="$APPDIR/src${PYTHONPATH:+:$PYTHONPATH}"
log "Preferring user venv Python: $PY"
fi
log "Final interpreter: $PY"
# First-run per-user setup if config missing
CFG_FILE="${XDG_CONFIG_HOME:-$HOME/.config}/voxd/config.yaml"
if [[ ! -f "$CFG_FILE" ]]; then
log "First-run: running --setup"
"$PY" -m voxd --setup || true
fi
# After setup, (Wayland) ensure ydotoold user service is enabled/started
if [[ ${XDG_SESSION_TYPE:-} == wayland* ]]; then
log "Wayland session detected; ensuring ydotoold user service"
systemctl --user is-active --quiet ydotoold.service || systemctl --user enable --now ydotoold.service || true
fi
log "Exec: $PY -m voxd $*"
exec "$PY" -m voxd "$@"