Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·314 lines (264 loc) · 9.41 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·314 lines (264 loc) · 9.41 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
#!/bin/sh
# NeverC installer
# Usage: curl -fsSL https://raw.githubusercontent.com/NeverSight/NeverC/HEAD/install.sh | sh
#
# Environment variables:
# NEVERC_INSTALL_DIR Override install directory (default: ~/.neverc)
# NEVERC_VERSION Install a specific version tag (default: latest)
# NEVERC_NO_MODIFY_PATH Set to 1 to skip shell profile modification
set -eu
REPO="NeverSight/NeverC"
DEFAULT_INSTALL_DIR="$HOME/.neverc"
TMP_DIR=""
# ── Helpers ──────────────────────────────────────────────────────────
say() { printf '%s\n' "$*"; }
err() { say "error: $*" >&2; exit 1; }
need_cmd() {
if ! command -v "$1" > /dev/null 2>&1; then
err "need '$1' (command not found)"
fi
}
cleanup() {
if [ -n "$TMP_DIR" ] && [ -d "$TMP_DIR" ]; then
rm -rf "$TMP_DIR"
fi
}
trap cleanup EXIT
trap 'exit 1' HUP INT TERM
# ── Detect platform ─────────────────────────────────────────────────
detect_os() {
case "$(uname -s)" in
Darwin) echo "macos" ;;
Linux) echo "linux" ;;
*) err "unsupported OS: $(uname -s) — on Windows, run in PowerShell: irm https://raw.githubusercontent.com/NeverSight/NeverC/HEAD/install.ps1 | iex" ;;
esac
}
detect_arch() {
case "$(uname -m)" in
x86_64|amd64) echo "x64" ;;
aarch64|arm64) echo "arm64" ;;
*) err "unsupported architecture: $(uname -m)" ;;
esac
}
validate_platform() {
platform_os=$1
platform_arch=$2
case "${platform_os}-${platform_arch}" in
linux-x64|linux-arm64|macos-arm64) ;;
*) err "unsupported platform: ${platform_os}-${platform_arch} — use a manual release archive if available" ;;
esac
}
# ── Resolve latest release tag via GitHub API ────────────────────────
normalize_version() {
normalized_version=$1
case "$normalized_version" in
v*) ;;
*) normalized_version="v${normalized_version}" ;;
esac
if ! printf '%s\n' "$normalized_version" \
| awk '/^v[0-9]+\.[0-9]+\.[0-9]+$/ { valid = 1 } END { exit !valid }'; then
err "invalid version '${normalized_version}' — expected vMAJOR.MINOR.PATCH"
fi
echo "$normalized_version"
}
resolve_version() {
resolve_asset=$1
resolve_requested=${NEVERC_VERSION:-}
if [ -n "$resolve_requested" ]; then
normalize_version "$resolve_requested"
return
fi
need_cmd curl
resolve_url="https://api.github.com/repos/${REPO}/releases?per_page=100"
resolved_tag=$(curl -fsSL \
-H 'Accept: application/vnd.github+json' \
-H 'X-GitHub-Api-Version: 2022-11-28' \
"$resolve_url" 2>/dev/null | awk -v target="$resolve_asset" '
/"tag_name"[[:space:]]*:/ {
line = $0
sub(/^.*"tag_name"[[:space:]]*:[[:space:]]*"/, "", line)
sub(/".*$/, "", line)
tag = line
}
/"draft"[[:space:]]*:/ {
draft = ($0 ~ /"draft"[[:space:]]*:[[:space:]]*true/)
}
/"prerelease"[[:space:]]*:/ {
prerelease = ($0 ~ /"prerelease"[[:space:]]*:[[:space:]]*true/)
}
/"name"[[:space:]]*:/ {
line = $0
sub(/^.*"name"[[:space:]]*:[[:space:]]*"/, "", line)
sub(/".*$/, "", line)
if (line == target && !draft && !prerelease) {
print tag
exit
}
}
')
if [ -z "$resolved_tag" ]; then
err "failed to determine latest release — set NEVERC_VERSION=vX.Y.Z manually"
fi
echo "$resolved_tag"
}
# ── Download & extract ───────────────────────────────────────────────
verify_checksum() {
checksum_archive=$1
checksum_manifest=$2
checksum_asset=$3
checksum_expected=$(awk -v target="$checksum_asset" '
$2 == target || $2 == "*" target { print $1; exit }
' "$checksum_manifest")
if [ -z "$checksum_expected" ]; then
err "checksum manifest has no entry for '${checksum_asset}'"
fi
if command -v sha256sum > /dev/null 2>&1; then
checksum_actual=$(sha256sum "$checksum_archive" | awk '{ print $1 }')
elif command -v shasum > /dev/null 2>&1; then
checksum_actual=$(shasum -a 256 "$checksum_archive" | awk '{ print $1 }')
else
err "need 'sha256sum' or 'shasum' to verify the release archive"
fi
if [ "$checksum_actual" != "$checksum_expected" ]; then
err "checksum verification failed for '${checksum_asset}'"
fi
say "Checksum verified."
}
download_and_install() {
download_os=$1
download_arch=$2
download_version=$3
download_install_dir=$4
download_asset="neverc-${download_os}-${download_arch}.zip"
download_url="https://github.com/${REPO}/releases/download/${download_version}/${download_asset}"
download_checksum_url="https://github.com/${REPO}/releases/download/${download_version}/SHA256SUMS"
say ""
say " NeverC installer"
say " ────────────────"
say " Version: ${download_version}"
say " Platform: ${download_os}-${download_arch}"
say " Install: ${download_install_dir}"
say ""
need_cmd curl
need_cmd unzip
need_cmd mkdir
need_cmd cp
need_cmd mktemp
say "Downloading ${download_asset}..."
TMP_DIR=$(mktemp -d)
download_archive="${TMP_DIR}/${download_asset}"
download_manifest="${TMP_DIR}/SHA256SUMS"
download_extract_dir="${TMP_DIR}/extract"
if ! curl -fSL --progress-bar "$download_url" -o "$download_archive"; then
err "download failed — check that version '${download_version}' exists and has asset '${download_asset}'"
fi
say "Downloading SHA256SUMS..."
if ! curl -fsSL "$download_checksum_url" -o "$download_manifest"; then
err "failed to download checksum manifest for version '${download_version}'"
fi
verify_checksum "$download_archive" "$download_manifest" "$download_asset"
say "Extracting and validating archive..."
mkdir -p "$download_extract_dir"
unzip -q -o "$download_archive" -d "$download_extract_dir"
if [ ! -f "${download_extract_dir}/bin/neverc" ]; then
err "archive is valid but bin/neverc was not found"
fi
chmod +x "${download_extract_dir}/bin/neverc"
mkdir -p "$download_install_dir"
cp -R "${download_extract_dir}/." "$download_install_dir/"
say "Installed neverc to ${download_install_dir}/bin/neverc"
}
# ── PATH setup ───────────────────────────────────────────────────────
add_to_path() {
path_bin_dir=$1
if [ "${NEVERC_NO_MODIFY_PATH:-0}" = "1" ]; then
return
fi
# Already on PATH?
case ":${PATH}:" in
*":${path_bin_dir}:"*) return ;;
esac
path_profile=""
path_shell_name=$(basename "${SHELL:-/bin/sh}")
case "$path_shell_name" in
zsh)
if [ -f "$HOME/.zshrc" ]; then
path_profile="$HOME/.zshrc"
elif [ -f "$HOME/.zprofile" ]; then
path_profile="$HOME/.zprofile"
else
path_profile="$HOME/.zshrc"
fi
;;
bash)
if [ -f "$HOME/.bashrc" ]; then
path_profile="$HOME/.bashrc"
elif [ -f "$HOME/.bash_profile" ]; then
path_profile="$HOME/.bash_profile"
else
path_profile="$HOME/.bashrc"
fi
;;
fish)
path_profile="$HOME/.config/fish/conf.d/neverc.fish"
;;
*)
path_profile="$HOME/.profile"
;;
esac
if [ -z "$path_profile" ]; then
return
fi
# Don't add duplicate entries
if [ -f "$path_profile" ] && grep -F "$path_bin_dir" "$path_profile" > /dev/null 2>&1; then
return
fi
say "Adding ${path_bin_dir} to PATH in ${path_profile}"
if [ "$path_shell_name" = "fish" ]; then
mkdir -p "$(dirname "$path_profile")"
printf '\n# NeverC\nfish_add_path -- "%s"\n' "$path_bin_dir" >> "$path_profile"
else
# Keep $PATH literal so the profile expands it when the shell starts.
# shellcheck disable=SC2016
printf '\n# NeverC\nexport PATH="%s:$PATH"\n' "$path_bin_dir" >> "$path_profile"
fi
}
# ── Main ─────────────────────────────────────────────────────────────
main() {
main_os=$(detect_os)
main_arch=$(detect_arch)
validate_platform "$main_os" "$main_arch"
main_asset="neverc-${main_os}-${main_arch}.zip"
main_version=$(resolve_version "$main_asset")
main_install_dir=${NEVERC_INSTALL_DIR:-${DEFAULT_INSTALL_DIR}}
download_and_install "$main_os" "$main_arch" "$main_version" "$main_install_dir"
add_to_path "${main_install_dir}/bin"
say ""
say "Done! NeverC ${main_version} is installed."
say ""
main_needs_source=0
case ":${PATH}:" in
*":${main_install_dir}/bin:"*) ;;
*) main_needs_source=1 ;;
esac
if [ "$main_needs_source" = "1" ]; then
say "Restart your shell or run:"
say " export PATH=\"${main_install_dir}/bin:\$PATH\""
say ""
fi
say "Quick start:"
say " neverc --version"
say " neverc hello.c -o hello -fbuiltin-string"
say ""
say "Cross-compilation runtimes (optional):"
say " neverc runtime install all"
say " neverc runtime install windows-x64"
say " neverc runtime install windows-arm64"
say " neverc runtime install linux-x64"
say " neverc runtime install linux-arm64"
say " neverc runtime install macos-arm64"
say " neverc runtime install android-arm64"
say " neverc runtime install android-kernel-arm64"
say " neverc runtime list"
}
main "$@"