Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
official-stockfish
GitHub Repository: official-stockfish/Stockfish
Path: blob/master/scripts/net.sh
376 views
1
#!/bin/sh
2
3
wget_or_curl=$( (command -v wget > /dev/null 2>&1 && echo "wget -qO-") || \
4
(command -v curl > /dev/null 2>&1 && echo "curl -skL"))
5
6
7
sha256sum=$( (command -v shasum > /dev/null 2>&1 && echo "shasum -a 256") || \
8
(command -v sha256sum > /dev/null 2>&1 && echo "sha256sum"))
9
10
if [ -z "$sha256sum" ]; then
11
>&2 echo "sha256sum not found, NNUE files will be assumed valid."
12
fi
13
14
get_nnue_filename() {
15
grep "$1" evaluate.h | grep "#define" | sed "s/.*\(nn-[a-z0-9]\{12\}.nnue\).*/\1/"
16
}
17
18
validate_network() {
19
# If no sha256sum command is available, assume the file is always valid.
20
if [ -n "$sha256sum" ] && [ -f "$1" ]; then
21
if [ "$1" != "nn-$($sha256sum "$1" | cut -c 1-12).nnue" ]; then
22
rm -f "$1"
23
return 1
24
fi
25
fi
26
}
27
28
fetch_network() {
29
_filename="$(get_nnue_filename "$1")"
30
31
if [ -z "$_filename" ]; then
32
>&2 echo "NNUE file name not found for: $1"
33
return 1
34
fi
35
36
if [ -f "$_filename" ]; then
37
if validate_network "$_filename"; then
38
echo "Existing $_filename validated, skipping download"
39
return
40
else
41
echo "Removing invalid NNUE file: $_filename"
42
fi
43
fi
44
45
if [ -z "$wget_or_curl" ]; then
46
>&2 printf "%s\n" "Neither wget or curl is installed." \
47
"Install one of these tools to download NNUE files automatically."
48
exit 1
49
fi
50
51
for url in \
52
"https://tests.stockfishchess.org/api/nn/$_filename" \
53
"https://github.com/official-stockfish/networks/raw/master/$_filename"; do
54
echo "Downloading from $url ..."
55
if $wget_or_curl "$url" > "$_filename"; then
56
if validate_network "$_filename"; then
57
echo "Successfully validated $_filename"
58
else
59
echo "Downloaded $_filename is invalid"
60
continue
61
fi
62
else
63
echo "Failed to download from $url"
64
fi
65
if [ -f "$_filename" ]; then
66
return
67
fi
68
done
69
70
# Download was not successful in the loop, return false.
71
>&2 echo "Failed to download $_filename"
72
return 1
73
}
74
75
fetch_network EvalFileDefaultNameBig && \
76
fetch_network EvalFileDefaultNameSmall
77
78