-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·111 lines (103 loc) · 4.19 KB
/
install.sh
File metadata and controls
executable file
·111 lines (103 loc) · 4.19 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
#!/usr/bin/env bash
# mcpp/install.sh — one-line installer.
#
# Usage:
# curl -fsSL https://github.com/mcpp-community/mcpp/releases/latest/download/install.sh | bash
#
# Optional env knobs:
# MCPP_VERSION — pin a specific version (default: latest)
# MCPP_PREFIX — install root (default: $HOME/.mcpp)
# MCPP_NO_PATH — set to skip shell-rc PATH editing
#
# Layout afterwards (PREFIX = $HOME/.mcpp by default):
# $PREFIX/bin/{mcpp,xlings} ← binary + pinned bundled xlings
# $PREFIX/registry/ ← seeded on first `mcpp` invocation
# $PREFIX/... ← mcpp's full self-contained tree
#
# mcpp resolves MCPP_HOME from the binary's location, so $PREFIX IS the
# home — no env var is required after install.
set -euo pipefail
REPO="mcpp-community/mcpp"
VERSION="${MCPP_VERSION:-latest}"
PREFIX="${MCPP_PREFIX:-$HOME/.mcpp}"
# ---- platform detection ---------------------------------------------------
uname_s=$(uname -s)
uname_m=$(uname -m)
case "${uname_s}-${uname_m}" in
Linux-x86_64) PLAT="linux-x86_64" ;;
*)
echo "error: unsupported platform ${uname_s}-${uname_m}." >&2
echo " v0.0.3 ships only linux-x86_64. Build from source instead:" >&2
echo " https://github.com/${REPO}#从源码构建开发者" >&2
exit 1
;;
esac
# ---- resolve download URLs ------------------------------------------------
if [[ "$VERSION" == "latest" ]]; then
BASE="https://github.com/${REPO}/releases/latest/download"
ASSET_NAME_GLOB="mcpp-*-${PLAT}.tar.gz" # `latest` redirect uses fixed asset name
TARBALL_URL="${BASE}/mcpp-${PLAT}.tar.gz" # versionless alias served by the release
else
BASE="https://github.com/${REPO}/releases/download/v${VERSION}"
TARBALL_URL="${BASE}/mcpp-${VERSION}-${PLAT}.tar.gz"
fi
SHA_URL="${TARBALL_URL}.sha256"
# ---- fetch ----------------------------------------------------------------
WORK=$(mktemp -d)
trap 'rm -rf "$WORK"' EXIT
echo ":: Downloading ${TARBALL_URL}"
curl --fail --location --silent --show-error -o "$WORK/mcpp.tar.gz" "$TARBALL_URL"
curl --fail --location --silent --show-error -o "$WORK/mcpp.sha256" "$SHA_URL" || {
echo "warning: no .sha256 sidecar found, skipping verification" >&2
}
# ---- verify ---------------------------------------------------------------
if [[ -s "$WORK/mcpp.sha256" ]]; then
expected=$(awk '{print $1}' "$WORK/mcpp.sha256")
actual=$(sha256sum "$WORK/mcpp.tar.gz" | awk '{print $1}')
if [[ "$expected" != "$actual" ]]; then
echo "error: sha256 mismatch" >&2
echo " expected: $expected" >&2
echo " actual: $actual" >&2
exit 1
fi
echo ":: sha256 verified"
fi
# ---- install --------------------------------------------------------------
# Tarball entries live under a single `<tarball-stem>/` directory so
# extraction lands a self-contained tree. We strip that wrapper here so
# files end up directly under $PREFIX (not $PREFIX/<stem>/...).
mkdir -p "$PREFIX"
echo ":: Extracting to $PREFIX"
tar -xzf "$WORK/mcpp.tar.gz" -C "$PREFIX" --strip-components=1
# ---- PATH integration -----------------------------------------------------
if [[ -z "${MCPP_NO_PATH:-}" ]]; then
rc=""
case "${SHELL##*/}" in
bash) rc="$HOME/.bashrc" ;;
zsh) rc="${ZDOTDIR:-$HOME}/.zshrc" ;;
fish) rc="$HOME/.config/fish/config.fish" ;;
esac
if [[ -n "$rc" ]]; then
if [[ "${SHELL##*/}" == "fish" ]]; then
line="set -gx PATH \"$PREFIX/bin\" \$PATH"
else
line="export PATH=\"$PREFIX/bin:\$PATH\""
fi
mkdir -p "$(dirname "$rc")"
if ! grep -Fqs "$PREFIX/bin" "$rc" 2>/dev/null; then
printf '\n# mcpp\n%s\n' "$line" >> "$rc"
echo ":: Added $PREFIX/bin to PATH via $rc"
else
echo ":: $PREFIX/bin already on PATH in $rc"
fi
else
echo ":: Unknown shell — add this to your shell rc manually:"
echo " export PATH=\"$PREFIX/bin:\$PATH\""
fi
fi
# ---- verify install -------------------------------------------------------
echo
"$PREFIX/bin/mcpp" --version
echo
echo "✓ mcpp installed at $PREFIX"
echo " Open a new shell (or 'source $rc') and run: mcpp --help"