-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
116 lines (96 loc) · 2.58 KB
/
Copy pathinstall.sh
File metadata and controls
116 lines (96 loc) · 2.58 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
#!/usr/bin/env sh
set -eu
REPO="francis-du/wcode"
INSTALL_DIR="${WCODE_INSTALL_DIR:-$HOME/.local/bin}"
TMP_DIR="${TMPDIR:-/tmp}/wcode-install-$$"
cleanup() {
rm -rf "$TMP_DIR"
}
trap cleanup EXIT INT TERM
command_exists() {
command -v "$1" >/dev/null 2>&1
}
fail() {
printf 'wcode install: %s\n' "$1" >&2
exit 1
}
version="${WCODE_VERSION:-latest}"
case "$version" in
latest)
BASE_URL="https://github.com/${REPO}/releases/latest/download"
;;
*[!A-Za-z0-9._-]*|'')
fail "invalid WCODE_VERSION: $version"
;;
*)
BASE_URL="https://github.com/${REPO}/releases/download/${version}"
;;
esac
if ! command_exists curl; then
fail "curl is required"
fi
os=$(uname -s)
arch=$(uname -m)
case "$os" in
Linux)
case "$arch" in
x86_64|amd64)
archive="wcode-linux-x86_64.tar.gz"
;;
*)
fail "unsupported Linux architecture: $arch"
;;
esac
;;
Darwin)
case "$arch" in
arm64|aarch64)
archive="wcode-macos-aarch64.tar.gz"
;;
x86_64|amd64)
archive="wcode-macos-x86_64.tar.gz"
;;
*)
fail "unsupported macOS architecture: $arch"
;;
esac
;;
*)
fail "unsupported operating system: $os (use install.ps1 on Windows)"
;;
esac
mkdir -p "$TMP_DIR" "$INSTALL_DIR"
printf 'Downloading %s...\n' "$archive"
curl -fL --retry 3 --connect-timeout 10 \
"$BASE_URL/$archive" \
-o "$TMP_DIR/$archive"
printf 'Downloading checksums...\n'
curl -fL --retry 3 --connect-timeout 10 \
"$BASE_URL/SHA256SUMS" \
-o "$TMP_DIR/SHA256SUMS"
expected=$(awk -v name="$archive" '$2 == name || $2 == "*" name { print $1; exit }' "$TMP_DIR/SHA256SUMS")
[ -n "$expected" ] || fail "checksum for $archive was not found"
if command_exists sha256sum; then
actual=$(sha256sum "$TMP_DIR/$archive" | awk '{print $1}')
elif command_exists shasum; then
actual=$(shasum -a 256 "$TMP_DIR/$archive" | awk '{print $1}')
else
fail "sha256sum or shasum is required to verify the download"
fi
[ "$actual" = "$expected" ] || fail "SHA-256 checksum mismatch"
mkdir -p "$TMP_DIR/package"
tar -xzf "$TMP_DIR/$archive" -C "$TMP_DIR/package"
binary=$(find "$TMP_DIR/package" -type f -name wcode -print | head -n 1)
[ -n "$binary" ] || fail "wcode binary was not found in the release archive"
install_path="$INSTALL_DIR/wcode"
cp "$binary" "$install_path"
chmod 755 "$install_path"
printf '\nInstalled wcode to %s\n' "$install_path"
case ":${PATH:-}:" in
*":$INSTALL_DIR:"*)
;;
*)
printf '\nAdd this directory to PATH if needed:\n %s\n' "$INSTALL_DIR"
;;
esac
"$install_path" --version