forked from jiro4989/setup-nim-action
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall_nimble.sh
executable file
·179 lines (152 loc) · 4.76 KB
/
install_nimble.sh
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
#!/bin/bash
set -eu
DATE_FORMAT="%Y-%m-%d %H:%M:%S"
info() {
echo "$(date +"$DATE_FORMAT") [INFO] $*"
}
err() {
echo "$(date +"$DATE_FORMAT") [ERR] $*"
}
fetch_tags() {
response=$(curl -sSL \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${repo_token}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/nim-lang/nimble/git/refs/tags)
version=$(echo "$response" | jq -r 'if type == "array" then .[].ref else empty end' |
sed -E 's:^refs/tags/v::' |
sed -E 's:^refs/tags/::' |
grep -E '^[0-9]+\.[0-9]+(\.[0-9]+)?$' |
sort -V | tail -n1)
if [[ -z "$version" ]]; then
err "Failed to extract version number"
exit 1
fi
echo "$version"
}
tag_regexp() {
version=$1
echo "$version" |
sed -E \
-e 's/\./\\./g' \
-e 's/^/^/' \
-e 's/x$//'
}
latest_version() {
# Get the highest version using sort -V
version=$(sort -V | tail -n1)
# Check if we got a version
if [[ -z "$version" ]]; then
err "No valid versions found"
exit 1
fi
echo "$version"
}
print_available_versions() {
info "Available Nimble versions:"
fetch_tags | while read -r version; do
echo " - $version"
done
}
# parse commandline args
nimble_version=""
nimble_install_dir=".nimble_runtime"
os="Linux"
repo_token=""
parent_nimble_install_dir=""
while ((0 < $#)); do
opt=$1
shift
case $opt in
--nimble-version)
nimble_version=$1
shift
;;
--nimble-install-directory)
nimble_install_dir=$1
shift
;;
--parent-nimble-install-directory)
parent_nimble_install_dir=$1
shift
;;
--os)
os=$1
shift
;;
--repo-token)
repo_token=$1
shift
;;
esac
done
if [[ "$parent_nimble_install_dir" = "" ]]; then
parent_nimble_install_dir="$PWD"
fi
cd "$parent_nimble_install_dir"
# get exact version
if [[ "$nimble_version" = "latest" || "$nimble_version" = "nightly" ]]; then
info "Finding latest version..."
if [[ "$nimble_version" = "nightly" ]]; then
# For nightly, use the 'latest' tag directly
nimble_version="latest"
info "Using nightly build from 'latest' tag"
else
# For 'latest', fetch the highest numbered version
nimble_version=$(fetch_tags)
if [[ -z "$nimble_version" ]]; then
err "Failed to determine latest version"
exit 1
fi
info "Latest stable version is: $nimble_version"
fi
elif [[ "$nimble_version" =~ ^[0-9]+\.[0-9]+\.x$ ]] || [[ "$nimble_version" =~ ^[0-9]+\.x$ ]]; then
nimble_version=$(fetch_tags | grep -E "$(tag_regexp "$nimble_version")" | latest_version)
fi
info "Installing nimble $nimble_version"
info "Current directory: $(pwd)"
info "Installing to: ${nimble_install_dir}/bin"
# Create installation directory
mkdir -p "${nimble_install_dir}/bin"
# Set architecture
arch="x64"
if [[ "$os" = "Windows" ]]; then
# Handle nightly/latest tag differently
if [[ "$nimble_version" = "latest" ]]; then
download_url="https://github.com/nim-lang/nimble/releases/download/latest/nimble-windows_${arch}.zip"
else
download_url="https://github.com/nim-lang/nimble/releases/download/v${nimble_version}/nimble-windows_${arch}.zip"
fi
info "Downloading from: ${download_url}"
# Download SSL certificates for Windows
info "Downloading SSL certificates..."
curl -sSL "https://curl.se/ca/cacert.pem" -o "${nimble_install_dir}/bin/cacert.pem"
info "Downloading Nimble..."
curl -sSL "${download_url}" > nimble.zip
# Try the new structure (direct exe)
unzip -j -o nimble.zip "nimble.exe" -d "${nimble_install_dir}/bin" ||
# If that fails, try the old structure (nested exe)
unzip -j -o nimble.zip "*/nimble.exe" -d "${nimble_install_dir}/bin"
rm -f nimble.zip
elif [[ "$os" = "macOS" || "$os" = "Darwin" ]]; then
nimble_version=$(echo "${nimble_version}" | tr -d '[:space:]')
if [[ "$nimble_version" = "latest" ]]; then
download_url="https://github.com/nim-lang/nimble/releases/download/latest/nimble-macosx_${arch}.tar.gz"
else
download_url="https://github.com/nim-lang/nimble/releases/download/v${nimble_version}/nimble-macosx_${arch}.tar.gz"
fi
info "Downloading from: ${download_url}"
curl -sSL "${download_url}" | tar xvz -C "${nimble_install_dir}/bin"
else
nimble_version=$(echo "${nimble_version}" | tr -d '[:space:]')
if [[ "$nimble_version" = "latest" ]]; then
download_url="https://github.com/nim-lang/nimble/releases/download/latest/nimble-linux_${arch}.tar.gz"
else
download_url="https://github.com/nim-lang/nimble/releases/download/v${nimble_version}/nimble-linux_${arch}.tar.gz"
fi
info "Downloading from: ${download_url}"
curl -sSL "${download_url}" | tar xvz -C "${nimble_install_dir}/bin"
fi
info "Contents of ${nimble_install_dir}/bin:"
ls -la "${nimble_install_dir}/bin"
info "Nimble installation complete"