-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·78 lines (67 loc) · 1.91 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·78 lines (67 loc) · 1.91 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
#!/usr/bin/env bash
set -euo pipefail
REPO="${CONTD_REPO:-werifu/contd}"
VERSION="${CONTD_VERSION:-latest}"
INSTALL_DIR="${CONTD_INSTALL_DIR:-$HOME/.local/bin}"
os="$(uname -s | tr '[:upper:]' '[:lower:]')"
arch="$(uname -m)"
case "$os" in
linux|darwin) ;;
*)
echo "contd installer supports Linux and macOS only (detected: $os)." >&2
exit 1
;;
esac
case "$arch" in
x86_64) arch="x86_64" ;;
aarch64|arm64) arch="aarch64" ;;
*)
echo "unsupported architecture: $arch" >&2
exit 1
;;
esac
asset="contd-${os}-${arch}.tar.gz"
checksums="SHA256SUMS"
base_url="https://github.com/${REPO}/releases"
if [[ "$VERSION" == "latest" ]]; then
asset_url="${base_url}/latest/download/${asset}"
checksum_url="${base_url}/latest/download/${checksums}"
else
tag="$VERSION"
if [[ "$tag" != v* ]]; then
tag="v${tag}"
fi
asset_url="${base_url}/download/${tag}/${asset}"
checksum_url="${base_url}/download/${tag}/${checksums}"
fi
tmpdir="$(mktemp -d)"
cleanup() {
rm -rf "$tmpdir"
}
trap cleanup EXIT
echo "Downloading ${asset} from ${REPO}..."
curl -fL "$asset_url" -o "${tmpdir}/${asset}"
curl -fL "$checksum_url" -o "${tmpdir}/${checksums}"
if command -v sha256sum >/dev/null 2>&1; then
(
cd "$tmpdir"
grep " ${asset}\$" "$checksums" | sha256sum -c -
)
elif command -v shasum >/dev/null 2>&1; then
expected="$(grep " ${asset}\$" "${tmpdir}/${checksums}" | awk '{print $1}')"
actual="$(shasum -a 256 "${tmpdir}/${asset}" | awk '{print $1}')"
if [[ "$expected" != "$actual" ]]; then
echo "checksum mismatch for ${asset}" >&2
exit 1
fi
else
echo "no sha256 tool found (need sha256sum or shasum)" >&2
exit 1
fi
mkdir -p "$INSTALL_DIR"
tar -xzf "${tmpdir}/${asset}" -C "$tmpdir"
install -m 0755 "${tmpdir}/contd" "${INSTALL_DIR}/contd"
echo "Installed: ${INSTALL_DIR}/contd"
if ! command -v contd >/dev/null 2>&1; then
echo "Note: add ${INSTALL_DIR} to PATH, then open a new shell."
fi