Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·263 lines (240 loc) · 10.6 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·263 lines (240 loc) · 10.6 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#!/bin/bash
# install.sh - One-liner installer for interpreter-v2
# Usage: curl -LsSf https://raw.githubusercontent.com/bquenin/interpreter/main/install.sh | bash
#
# To install somewhere other than your home directory (for example on a second
# drive), set INTERPRETER_HOME first. The choice is remembered for upgrades:
# curl -LsSf https://raw.githubusercontent.com/bquenin/interpreter/main/install.sh | INTERPRETER_HOME=/mnt/data/interpreter bash
set -e
# Colors
CYAN='\033[0;36m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
GRAY='\033[0;90m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Determine total steps (Linux has extra steps)
if [[ "$(uname)" == "Linux" ]]; then
TOTAL_STEPS=5
else
TOTAL_STEPS=3
fi
echo ""
echo -e "${CYAN}=== interpreter-v2 Installer ===${NC}"
echo "Offline screen translator for Japanese retro games"
echo -e "${GRAY}Plan for at least 6 GB of free disk space, including first-run model downloads.${NC}"
echo ""
# Resolve the install location. INTERPRETER_HOME wins; otherwise reuse the
# location recorded by a previous run so plain re-runs upgrade in place. The
# layout under the root mirrors src/interpreter/paths.py; keep them in sync:
# <root>/uv/tools tool environment <root>/uv-cache install downloads
# <root>/uv/python uv-managed Python <root>/models HuggingFace cache
CONFIG_DIR="$HOME/.interpreter"
INSTALL_ROOT_FILE="$CONFIG_DIR/install-dir"
PREVIOUS_ROOT=""
if [ -f "$INSTALL_ROOT_FILE" ]; then
PREVIOUS_ROOT=$(tr -d '\r\n' <"$INSTALL_ROOT_FILE")
PREVIOUS_ROOT="${PREVIOUS_ROOT%/}"
fi
INSTALL_ROOT="${INTERPRETER_HOME:-$PREVIOUS_ROOT}"
UV_CACHE_ARGS=()
if [ -n "$INSTALL_ROOT" ]; then
# Expand a leading ~ and make relative paths absolute.
INSTALL_ROOT="${INSTALL_ROOT/#\~/$HOME}"
case "$INSTALL_ROOT" in
/*) ;;
*) INSTALL_ROOT="$PWD/$INSTALL_ROOT" ;;
esac
INSTALL_ROOT="${INSTALL_ROOT%/}"
if [ -z "$INSTALL_ROOT" ]; then
echo -e "${RED}Error: INTERPRETER_HOME must be a directory, not the filesystem root. Try /opt/interpreter${NC}"
exit 1
fi
mkdir -p "$INSTALL_ROOT"
# The uninstaller only removes folders next to this marker, so a mistyped
# or shared INTERPRETER_HOME never has unrelated content deleted.
echo "Created by the interpreter-v2 installer. The uninstaller removes the uv, uv-cache and models folders next to this file." >"$INSTALL_ROOT/.interpreter-v2"
export UV_TOOL_DIR="$INSTALL_ROOT/uv/tools"
export UV_PYTHON_INSTALL_DIR="$INSTALL_ROOT/uv/python"
# Keep the multi-gigabyte package downloads off the home drive too, and
# remove them after the install instead of leaving them in uv's cache.
INSTALL_CACHE_DIR="$INSTALL_ROOT/uv-cache"
UV_CACHE_ARGS=(--cache-dir "$INSTALL_CACHE_DIR")
MODELS_DIR="$INSTALL_ROOT/models"
echo -e "${GRAY}Install location: $INSTALL_ROOT${NC}"
else
INSTALL_CACHE_DIR=""
MODELS_DIR=""
echo -e "${GRAY}Install location: home directory (set INTERPRETER_HOME to choose another drive)${NC}"
fi
echo ""
# Check if uv is installed
if ! command -v uv &>/dev/null; then
echo -e "${YELLOW}[1/${TOTAL_STEPS}] Installing uv package manager...${NC}"
curl -LsSf https://astral.sh/uv/install.sh | sh
# Add uv to PATH for this session
export PATH="$HOME/.local/bin:$PATH"
# Verify uv is now available
if ! command -v uv &>/dev/null; then
echo -e "${RED}Error: uv installation failed. Please restart your terminal and try again.${NC}"
exit 1
fi
echo -e "${GREEN}uv installed successfully!${NC}"
else
echo -e "${GREEN}[1/${TOTAL_STEPS}] uv is already installed${NC}"
fi
# Install or upgrade interpreter-v2
echo -e "${YELLOW}[2/${TOTAL_STEPS}] Installing interpreter-v2 from PyPI...${NC}"
echo -e "${GRAY} (this may take a minute on first install)${NC}"
# Use Python 3.12 - uv-managed Python includes tkinter, system Python 3.13+ often doesn't
# When the install location changes, the launcher from the old location still
# exists in the shared bin directory; --force lets uv replace it.
PREVIOUS_TOOL_ENV=""
if [ "$PREVIOUS_ROOT" != "$INSTALL_ROOT" ]; then
if [ -n "$PREVIOUS_ROOT" ]; then
PREVIOUS_TOOL_ENV="$PREVIOUS_ROOT/uv/tools/interpreter-v2"
else
PREVIOUS_TOOL_ENV="${XDG_DATA_HOME:-$HOME/.local/share}/uv/tools/interpreter-v2"
fi
fi
UV_FORCE_ARGS=()
if [ -n "$PREVIOUS_TOOL_ENV" ] && [ -d "$PREVIOUS_TOOL_ENV" ]; then
UV_FORCE_ARGS=(--force)
fi
INSTALL_OK=1
uv tool install "${UV_FORCE_ARGS[@]}" --upgrade --python 3.12 "${UV_CACHE_ARGS[@]}" interpreter-v2 2>&1 || INSTALL_OK=0
if [ -n "$INSTALL_CACHE_DIR" ]; then
uv cache clean --cache-dir "$INSTALL_CACHE_DIR" >/dev/null 2>&1 || true
rm -rf "$INSTALL_CACHE_DIR"
fi
if [ "$INSTALL_OK" -ne 1 ]; then
echo ""
echo -e "${RED}Installation failed!${NC}"
echo -e "${YELLOW}This may be due to missing dependencies. Try:${NC}"
echo -e " uv python install 3.12"
echo -e " Then run this installer again."
exit 1
fi
uv tool update-shell >/dev/null 2>&1 || true
# Record the install location so upgrades, the app, and the uninstaller find it.
if [ -n "$INSTALL_ROOT" ]; then
mkdir -p "$CONFIG_DIR"
printf '%s' "$INSTALL_ROOT" >"$INSTALL_ROOT_FILE"
fi
# The install location changed: now that the new installation works, remove
# the tool environment left in the old location so a multi-gigabyte orphan is
# not left behind. Only the directory is deleted. Running `uv tool uninstall`
# there would also remove the launcher the new installation just created in
# the shared bin directory.
if [ -n "$PREVIOUS_TOOL_ENV" ] && [ -d "$PREVIOUS_TOOL_ENV" ]; then
echo -e "${YELLOW} Removing the previous installation from $(dirname "$PREVIOUS_TOOL_ENV")${NC}"
rm -rf "$PREVIOUS_TOOL_ENV"
if [ -n "$PREVIOUS_ROOT" ]; then
echo -e "${GRAY} Models downloaded by the previous installation remain in $PREVIOUS_ROOT/models${NC}"
echo -e "${GRAY} Delete that folder once the new installation works.${NC}"
else
echo -e "${GRAY} Models downloaded by the previous installation remain in the HuggingFace cache${NC}"
echo -e "${GRAY} (~/.cache/huggingface/hub). Delete the models--rtr46--* and models--entai2965--*${NC}"
echo -e "${GRAY} folders there once the new installation works.${NC}"
fi
fi
# Pre-compile bytecode and warm up OS caches
echo -e "${YELLOW}[3/${TOTAL_STEPS}] Optimizing for fast startup...${NC}"
TOOL_DIR="${UV_TOOL_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/uv/tools}/interpreter-v2"
if [ -d "$TOOL_DIR" ]; then
# Compile bytecode (exclude .tmpl.py template files that aren't valid Python)
"$TOOL_DIR/bin/python" -m compileall -q -x '\.tmpl\.py$' "$TOOL_DIR/lib" 2>/dev/null || true
# Warm up OS caches by running once
interpreter-v2 --list-windows >/dev/null 2>&1 || true
fi
# Check Linux runtime dependencies (Linux only)
# Always check regardless of WAYLAND_DISPLAY - some compositors like gamescope don't set it
if [[ "$(uname)" == "Linux" ]]; then
echo -e "${YELLOW}[4/${TOTAL_STEPS}] Checking Linux runtime dependencies...${NC}"
if ldconfig -p 2>/dev/null | grep -q libpipewire-0.3; then
echo -e "${GREEN} PipeWire library available${NC}"
else
echo -e "${YELLOW} libpipewire-0.3 not found. Wayland capture may not work.${NC}"
echo -e "${GRAY} Install with: apt install libpipewire-0.3-0 (Debian/Ubuntu)${NC}"
echo -e "${GRAY} dnf install pipewire (Fedora)${NC}"
echo -e "${GRAY} pacman -S pipewire (Arch)${NC}"
fi
# Qt Multimedia links the PulseAudio client library even on PipeWire desktops.
# The cache does not include every loader path (e.g. LD_LIBRARY_PATH), so a
# missing entry is advisory and must not abort an otherwise usable installation.
if ldconfig -p 2>/dev/null | grep 'libpulse\.so\.0' >/dev/null; then
echo -e "${GREEN} PulseAudio client library available${NC}"
else
echo -e "${YELLOW} libpulse.so.0 is not listed in the system library cache.${NC}"
echo -e "${GRAY} If Qt Multimedia fails to load, install the PulseAudio client library:${NC}"
echo -e "${CYAN} sudo apt install libpulse0 ${GRAY}(Debian/Ubuntu/Mint)${NC}"
echo -e "${GRAY} Only the client library is needed; keep your current audio server.${NC}"
fi
# Qt 6.5+ requires libxcb-cursor for the xcb platform plugin used on X11/XWayland.
# The GUI cannot launch without it, so treat this as a hard failure rather than a warning.
if ldconfig -p 2>/dev/null | grep -q libxcb-cursor; then
echo -e "${GREEN} libxcb-cursor available${NC}"
else
echo -e "${RED} libxcb-cursor not found. The Qt GUI cannot launch without it.${NC}"
echo -e "${YELLOW} Install it and re-run this installer:${NC}"
echo -e "${CYAN} sudo apt install libxcb-cursor0 ${GRAY}(Debian/Ubuntu/Mint)${NC}"
echo -e "${CYAN} sudo dnf install xcb-util-cursor ${GRAY}(Fedora)${NC}"
echo -e "${CYAN} sudo pacman -S xcb-util-cursor ${GRAY}(Arch)${NC}"
exit 1
fi
fi
# Install desktop entry and icon (Linux only)
if [[ "$(uname)" == "Linux" ]]; then
echo -e "${YELLOW}[5/${TOTAL_STEPS}] Installing desktop entry...${NC}"
# Find the installed icon
ICON_SRC=$(find "$TOOL_DIR/lib" -name "icon.png" -path "*/resources/icons/*" 2>/dev/null | head -1)
if [ -n "$ICON_SRC" ]; then
# Install icon using xdg-icon-resource if available, otherwise fall back to manual copy
if command -v xdg-icon-resource &>/dev/null; then
xdg-icon-resource install --novendor --size 256 "$ICON_SRC" interpreter-v2
else
mkdir -p "$HOME/.local/share/icons/hicolor/256x256/apps"
cp "$ICON_SRC" "$HOME/.local/share/icons/hicolor/256x256/apps/interpreter-v2.png"
gtk-update-icon-cache -f "$HOME/.local/share/icons/hicolor" 2>/dev/null || true
fi
# Install desktop entry
mkdir -p "$HOME/.local/share/applications"
cat >"$HOME/.local/share/applications/interpreter-v2.desktop" <<'EOF'
[Desktop Entry]
Name=Interpreter
Comment=Offline screen translator for Japanese games
Exec=interpreter-v2
Icon=interpreter-v2
Type=Application
Categories=Utility;Translation;
StartupWMClass=interpreter-v2
EOF
update-desktop-database "$HOME/.local/share/applications" 2>/dev/null || true
echo -e "${GREEN}Desktop entry installed${NC}"
else
echo -e "${GRAY}Skipping desktop entry (icon not found)${NC}"
fi
fi
echo ""
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN} Installation complete!${NC}"
echo -e "${GREEN}========================================${NC}"
echo ""
if [ -n "$INSTALL_ROOT" ]; then
echo -e "${GRAY}Installed to $INSTALL_ROOT (models will download to $MODELS_DIR)${NC}"
echo ""
fi
echo "To start, run:"
echo ""
echo -e " ${CYAN}interpreter-v2${NC}"
echo ""
if [[ "$(uname)" == "Linux" ]]; then
echo -e "${YELLOW}Hotkeys:${NC} To use global hotkeys, add yourself to the input group:"
echo ""
echo -e " ${CYAN}sudo usermod -aG input \$USER${NC}"
echo ""
echo "Then log out and back in."
echo ""
fi
echo "You may need to restart your terminal first."
echo ""