forked from JohanSjoblom/picochess
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-engines.sh
More file actions
executable file
·470 lines (398 loc) · 16.5 KB
/
install-engines.sh
File metadata and controls
executable file
·470 lines (398 loc) · 16.5 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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
#!/bin/sh
# install-engines.sh – Download and extract chess engines if missing
# POSIX-compliant
#
# Run this as normal user, not as sudo
#
usage() {
cat <<EOF
Usage: $0 [small|lite]
Options:
small Install the smaller engine bundle for your architecture (aarch64 or x86_64).
lite Install the lite/DGT-focused engine bundle for your architecture (aarch64 or x86_64).
Notes:
- Script only installs engines when the target directories are missing.
- To force a reinstall, first run move-engines-to-backup.sh.
- You must specify either "small" or "lite".
Example:
./install-engines.sh lite
EOF
exit "${1:-0}"
}
if [ $# -eq 0 ]; then
usage 1
fi
case "$1" in
-h|--help|help)
usage 0
;;
esac
ENGINE_VARIANT=$1
ENGINE_VARIANT=$(printf "%s" "$ENGINE_VARIANT" | tr '[:upper:]' '[:lower:]')
if [ "$ENGINE_VARIANT" != "small" ] && [ "$ENGINE_VARIANT" != "lite" ]; then
usage 1
fi
INSTALL_USER="${SUDO_USER:-${USER:-}}"
if [ -z "$INSTALL_USER" ] || [ "$INSTALL_USER" = "root" ]; then
INSTALL_USER=$(logname 2>/dev/null || true)
fi
if [ -z "$INSTALL_USER" ] || [ "$INSTALL_USER" = "root" ]; then
INSTALL_USER=$(id -un 2>/dev/null || true)
fi
if [ -z "$INSTALL_USER" ] || [ "$INSTALL_USER" = "root" ]; then
if getent passwd pi >/dev/null 2>&1; then
INSTALL_USER="pi"
echo "Warning: using fallback install user 'pi'." >&2
else
echo "Error: could not determine non-root install user. Set INSTALL_USER and retry." >&2
exit 1
fi
fi
INSTALL_USER_HOME=${HOME:-$(getent passwd "$INSTALL_USER" | cut -d: -f6)}
if [ -z "$INSTALL_USER_HOME" ]; then
echo "Error: could not determine home directory for $INSTALL_USER." >&2
exit 1
fi
BACKUP_DIR_BASE="$INSTALL_USER_HOME/pico_backups"
TMP_DIR="$BACKUP_DIR_BASE/current/tmp"
REPO_DIR=${REPO_DIR:-/opt/picochess}
RESTORE_SCRIPT="$REPO_DIR/restore-engines-from-backup.sh"
ENGINES_DIR="$REPO_DIR/engines"
if [ ! -d "$REPO_DIR" ]; then
echo "Repository directory $REPO_DIR not found. Aborting." 1>&2
exit 1
fi
cd "$REPO_DIR" || {
echo "Failed to enter repository directory $REPO_DIR." 1>&2
exit 1
}
echo "Checking architecture..."
ARCH=$(uname -m)
# --- Unsupported -------------------------------------------------------------
if [ "$ARCH" != "aarch64" ] && [ "$ARCH" != "x86_64" ]; then
echo "Unsupported architecture: $ARCH"
exit 2
fi
# Ensure top-level engines folder and tmp folder exist
mkdir -p "$ENGINES_DIR" || exit 1
mkdir -p "$TMP_DIR" || exit 1
# --- aarch64 -----------------------------------------------------------------
if [ "$ARCH" = "aarch64" ]; then
echo "Detected architecture: aarch64 (variant: $ENGINE_VARIANT)"
if [ ! -d "$ENGINES_DIR/aarch64" ]; then
echo "No engines found for aarch64. Installing requested engine package..."
mkdir -p "$ENGINES_DIR/aarch64" || exit 1
if [ "$ENGINE_VARIANT" = "lite" ]; then
ENGINE_URL="https://github.com/JohanSjoblom/picochess/releases/download/v4.1.6/aarch64_engines_lite.tar.gz"
TMPFILE="$TMP_DIR/aarch64_engines_lite.tar.gz"
ENGINE_DESC="aarch64 lite engine package"
else
ENGINE_URL="https://github.com/JohanSjoblom/picochess/releases/download/v4.1.5/engines-aarch64-small.tar.gz"
TMPFILE="$TMP_DIR/engines-aarch64-small.tar.gz"
ENGINE_DESC="aarch64 small engine package"
fi
echo "Downloading $ENGINE_DESC..."
if command -v curl >/dev/null 2>&1; then
curl -L -o "$TMPFILE" "$ENGINE_URL" || exit 1
elif command -v wget >/dev/null 2>&1; then
wget -O "$TMPFILE" "$ENGINE_URL" || exit 1
else
echo "Error: need curl or wget to download" 1>&2
exit 1
fi
echo "Extracting $ENGINE_DESC..."
tar -xzf "$TMPFILE" -C "$ENGINES_DIR/aarch64" || {
echo "Extraction failed for $ENGINE_DESC." 1>&2
sh "$RESTORE_SCRIPT" arch "$ARCH"
rm -f "$TMPFILE"
exit 1
}
rm -f "$TMPFILE"
echo "$ENGINE_DESC installed successfully."
else
echo "Engines for aarch64 already present."
fi
if [ "$ENGINE_VARIANT" = "lite" ]; then
if [ ! -d "$ENGINES_DIR/mame_emulation" ]; then
echo "No MAME emulation files found. Installing package..."
mkdir -p "$ENGINES_DIR/mame_emulation" || exit 1
MAME_URL="https://github.com/JohanSjoblom/picochess/releases/download/v4.1.6/aarch64_mame_lite.tar.gz"
MAME_TMP="$TMP_DIR/aarch64_mame_lite.tar.gz"
echo "Downloading MAME emulation package..."
if command -v curl >/dev/null 2>&1; then
curl -L -o "$MAME_TMP" "$MAME_URL" || exit 1
elif command -v wget >/dev/null 2>&1; then
wget -O "$MAME_TMP" "$MAME_URL" || exit 1
else
echo "Error: need curl or wget to download" 1>&2
exit 1
fi
echo "Extracting MAME emulation package..."
tar -xzf "$MAME_TMP" -C "$ENGINES_DIR/mame_emulation" || {
echo "Extraction failed for MAME emulation package." 1>&2
rm -f "$MAME_TMP"
exit 1
}
rm -f "$MAME_TMP"
echo "MAME emulation package installed successfully."
else
echo "MAME emulation files already present."
fi
else
echo "Skipping MAME emulation package for small variant."
fi
if [ "$ENGINE_VARIANT" = "lite" ]; then
if [ ! -d "$ENGINES_DIR/rodent3" ]; then
echo "No Rodent III files found. Installing package..."
mkdir -p "$ENGINES_DIR/rodent3" || exit 1
RODENT3_URL="https://github.com/JohanSjoblom/picochess/releases/download/v4.1.6/aarch64_rodent3_lite.tar.gz"
RODENT3_TMP="$TMP_DIR/aarch64_rodent3_lite.tar.gz"
echo "Downloading Rodent III package..."
if command -v curl >/dev/null 2>&1; then
curl -L -o "$RODENT3_TMP" "$RODENT3_URL" || exit 1
elif command -v wget >/dev/null 2>&1; then
wget -O "$RODENT3_TMP" "$RODENT3_URL" || exit 1
else
echo "Error: need curl or wget to download" 1>&2
exit 1
fi
echo "Extracting Rodent III package..."
tar -xzf "$RODENT3_TMP" -C "$ENGINES_DIR/rodent3" || {
echo "Extraction failed for Rodent III package." 1>&2
rm -f "$RODENT3_TMP"
exit 1
}
rm -f "$RODENT3_TMP"
echo "Rodent III package installed successfully."
else
echo "Rodent III files already present."
fi
if [ ! -d "$ENGINES_DIR/rodent4" ]; then
echo "No Rodent IV files found. Installing package..."
mkdir -p "$ENGINES_DIR/rodent4" || exit 1
RODENT4_URL="https://github.com/JohanSjoblom/picochess/releases/download/v4.1.6/aarch64_rodent4_lite.tar.gz"
RODENT4_TMP="$TMP_DIR/aarch64_rodent4_lite.tar.gz"
echo "Downloading Rodent IV package..."
if command -v curl >/dev/null 2>&1; then
curl -L -o "$RODENT4_TMP" "$RODENT4_URL" || exit 1
elif command -v wget >/dev/null 2>&1; then
wget -O "$RODENT4_TMP" "$RODENT4_URL" || exit 1
else
echo "Error: need curl or wget to download" 1>&2
exit 1
fi
echo "Extracting Rodent IV package..."
tar -xzf "$RODENT4_TMP" -C "$ENGINES_DIR/rodent4" || {
echo "Extraction failed for Rodent IV package." 1>&2
rm -f "$RODENT4_TMP"
exit 1
}
rm -f "$RODENT4_TMP"
echo "Rodent IV package installed successfully."
else
echo "Rodent IV files already present."
fi
else
echo "Skipping Rodent III and IV packages for small variant."
fi
fi
# --- x86_64 ------------------------------------------------------------------
if [ "$ARCH" = "x86_64" ]; then
echo "Detected architecture: x86_64 (variant: $ENGINE_VARIANT)"
if [ ! -d "$ENGINES_DIR/x86_64" ]; then
echo "No engines found for x86_64. Installing requested engine package..."
mkdir -p "$ENGINES_DIR/x86_64" || exit 1
if [ "$ENGINE_VARIANT" = "lite" ]; then
ENGINE_URL="https://github.com/JohanSjoblom/picochess/releases/download/v4.1.9/x86_64_engines_lite.tar.gz"
TMPFILE="$TMP_DIR/x86_64_engines_lite.tar.gz"
ENGINE_DESC="x86_64 lite engine package"
else
ENGINE_URL="https://github.com/JohanSjoblom/picochess/releases/download/v4.1.5/engines-x86_64-small.tar.gz"
TMPFILE="$TMP_DIR/engines-x86_64-small.tar.gz"
ENGINE_DESC="x86_64 small engine package"
fi
echo "Downloading $ENGINE_DESC..."
if command -v curl >/dev/null 2>&1; then
curl -L -o "$TMPFILE" "$ENGINE_URL" || exit 1
elif command -v wget >/dev/null 2>&1; then
wget -O "$TMPFILE" "$ENGINE_URL" || exit 1
else
echo "Error: need curl or wget to download" 1>&2
exit 1
fi
echo "Extracting $ENGINE_DESC..."
tar -xzf "$TMPFILE" -C "$ENGINES_DIR/x86_64" || {
echo "Extraction failed for $ENGINE_DESC." 1>&2
sh "$RESTORE_SCRIPT" arch "$ARCH"
rm -f "$TMPFILE"
exit 1
}
rm -f "$TMPFILE"
echo "$ENGINE_DESC installed successfully."
else
echo "Engines for x86_64 already present."
fi
if [ "$ENGINE_VARIANT" = "lite" ]; then
if [ ! -d "$ENGINES_DIR/mame_emulation" ]; then
echo "No MAME emulation files found. Installing package..."
mkdir -p "$ENGINES_DIR/mame_emulation" || exit 1
MAME_URL="https://github.com/JohanSjoblom/picochess/releases/download/v4.1.9/x86_64_mame_lite.tar.gz"
MAME_TMP="$TMP_DIR/x86_64_mame_lite.tar.gz"
echo "Downloading MAME emulation package..."
if command -v curl >/dev/null 2>&1; then
curl -L -o "$MAME_TMP" "$MAME_URL" || exit 1
elif command -v wget >/dev/null 2>&1; then
wget -O "$MAME_TMP" "$MAME_URL" || exit 1
else
echo "Error: need curl or wget to download" 1>&2
exit 1
fi
echo "Extracting MAME emulation package..."
tar -xzf "$MAME_TMP" -C "$ENGINES_DIR/mame_emulation" || {
echo "Extraction failed for MAME emulation package." 1>&2
rm -f "$MAME_TMP"
exit 1
}
rm -f "$MAME_TMP"
echo "MAME emulation package installed successfully."
else
echo "MAME emulation files already present."
fi
else
echo "Skipping MAME emulation package for small variant."
fi
if [ "$ENGINE_VARIANT" = "lite" ]; then
if [ ! -d "$ENGINES_DIR/rodent3" ]; then
echo "No Rodent III files found. Installing package..."
mkdir -p "$ENGINES_DIR/rodent3" || exit 1
RODENT3_URL="https://github.com/JohanSjoblom/picochess/releases/download/v4.1.9/x86_64_rodent3_lite.tar.gz"
RODENT3_TMP="$TMP_DIR/x86_64_rodent3_lite.tar.gz"
echo "Downloading Rodent III package..."
if command -v curl >/dev/null 2>&1; then
curl -L -o "$RODENT3_TMP" "$RODENT3_URL" || exit 1
elif command -v wget >/dev/null 2>&1; then
wget -O "$RODENT3_TMP" "$RODENT3_URL" || exit 1
else
echo "Error: need curl or wget to download" 1>&2
exit 1
fi
echo "Extracting Rodent III package..."
tar -xzf "$RODENT3_TMP" -C "$ENGINES_DIR/rodent3" || {
echo "Extraction failed for Rodent III package." 1>&2
rm -f "$RODENT3_TMP"
exit 1
}
rm -f "$RODENT3_TMP"
echo "Rodent III package installed successfully."
else
echo "Rodent III files already present."
fi
if [ ! -d "$ENGINES_DIR/rodent4" ]; then
echo "No Rodent IV files found. Installing package..."
mkdir -p "$ENGINES_DIR/rodent4" || exit 1
RODENT4_URL="https://github.com/JohanSjoblom/picochess/releases/download/v4.1.9/x86_64_rodent4_lite.tar.gz"
RODENT4_TMP="$TMP_DIR/x86_64_rodent4_lite.tar.gz"
echo "Downloading Rodent IV package..."
if command -v curl >/dev/null 2>&1; then
curl -L -o "$RODENT4_TMP" "$RODENT4_URL" || exit 1
elif command -v wget >/dev/null 2>&1; then
wget -O "$RODENT4_TMP" "$RODENT4_URL" || exit 1
else
echo "Error: need curl or wget to download" 1>&2
exit 1
fi
echo "Extracting Rodent IV package..."
tar -xzf "$RODENT4_TMP" -C "$ENGINES_DIR/rodent4" || {
echo "Extraction failed for Rodent IV package." 1>&2
rm -f "$RODENT4_TMP"
exit 1
}
rm -f "$RODENT4_TMP"
echo "Rodent IV package installed successfully."
else
echo "Rodent IV files already present."
fi
else
echo "Skipping Rodent III and IV packages for small variant."
fi
fi
# --- Common LC0 weights ------------------------------------------------------
if [ ! -d "$ENGINES_DIR/lc0_weights" ]; then
echo "Installing LC0 weights..."
mkdir -p "$ENGINES_DIR/lc0_weights" || exit 1
WEIGHTS_URL="https://github.com/JohanSjoblom/picochess/releases/download/v4.1.6/lc0_weights.tar.gz"
TMPFILE="$TMP_DIR/lc0_weights.tar.gz"
echo "Downloading LC0 weights..."
if command -v curl >/dev/null 2>&1; then
curl -L -o "$TMPFILE" "$WEIGHTS_URL" || exit 1
elif command -v wget >/dev/null 2>&1; then
wget -O "$TMPFILE" "$WEIGHTS_URL" || exit 1
else
echo "Error: need curl or wget to download" 1>&2
exit 1
fi
echo "Extracting LC0 weights..."
tar -xzf "$TMPFILE" -C "$ENGINES_DIR/lc0_weights" || {
echo "Extraction failed for LC0 weights." 1>&2
sh "$RESTORE_SCRIPT" lc0
rm -f "$TMPFILE"
exit 1
}
rm -f "$TMPFILE"
echo "LC0 weights installed successfully."
else
echo "LC0 weights already present in engines folder."
fi
# --- Script engines ----------------------------------------------------------
if [ ! -d "$ENGINES_DIR/script_engines" ]; then
echo "Installing script engines..."
mkdir -p "$ENGINES_DIR/script_engines" || exit 1
SCRIPTS_URL="https://github.com/JohanSjoblom/picochess/releases/download/v4.1.6/script_engines.tar.gz"
TMPFILE="$TMP_DIR/script_engines.tar.gz"
echo "Downloading script engines..."
if command -v curl >/dev/null 2>&1; then
curl -L -o "$TMPFILE" "$SCRIPTS_URL" || exit 1
elif command -v wget >/dev/null 2>&1; then
wget -O "$TMPFILE" "$SCRIPTS_URL" || exit 1
else
echo "Error: need curl or wget to download" 1>&2
exit 1
fi
echo "Extracting script engines..."
tar -xzf "$TMPFILE" -C "$ENGINES_DIR/script_engines" || {
echo "Extraction failed for script engines." 1>&2
rm -f "$TMPFILE"
exit 1
}
rm -f "$TMPFILE"
echo "Script engines installed successfully."
else
echo "Script engines already present in engines folder."
fi
# --- pgn_audio files ---------------------------------------------------
if [ "$ENGINE_VARIANT" = "lite" ]; then
if [ ! -d "$ENGINES_DIR/pgn_engine/pgn_audio" ]; then
echo "Installing pgn_audio files..."
mkdir -p "$ENGINES_DIR/pgn_engine/pgn_audio" || exit 1
AUDIO_URL="https://github.com/JohanSjoblom/picochess/releases/download/v4.1.5/pgn_audio.tar.gz"
TMPFILE="$TMP_DIR/pgn_audio.tar.gz"
echo "Downloading pgn_audio files..."
if command -v curl >/dev/null 2>&1; then
curl -L -o "$TMPFILE" "$AUDIO_URL" || exit 1
elif command -v wget >/dev/null 2>&1; then
wget -O "$TMPFILE" "$AUDIO_URL" || exit 1
else
echo "Error: need curl or wget to download" 1>&2
exit 1
fi
echo "Extracting pgn_audio files..."
tar -xzf "$TMPFILE" -C "$ENGINES_DIR/pgn_engine/pgn_audio" || { rm -f "$TMPFILE"; exit 1; }
rm -f "$TMPFILE"
echo "pgn_audio files installed successfully."
else
echo "pgn_audio files already present in engines folder."
fi
else
echo "Skipping pgn_audio files for small variant."
fi
exit 0