-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·86 lines (72 loc) · 2.47 KB
/
install.sh
File metadata and controls
executable file
·86 lines (72 loc) · 2.47 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
#!/usr/bin/env bash
# microcode installer.
#
# curl -fsSL https://raw.githubusercontent.com/microclaw/microcode/main/install.sh | bash
#
# Detects OS/arch, downloads the matching binary from the latest GitHub
# release, and installs it. Honors:
# MICROCODE_VERSION Override the version to install (default: latest)
# MICROCODE_INSTALL_DIR Install directory (default: ~/.local/bin or /usr/local/bin)
# MICROCODE_REPO "owner/repo" override for forks (default: microclaw/microcode)
set -euo pipefail
REPO="${MICROCODE_REPO:-microclaw/microcode}"
VERSION="${MICROCODE_VERSION:-latest}"
red() { printf '\033[31m%s\033[0m' "$*"; }
green() { printf '\033[32m%s\033[0m' "$*"; }
dim() { printf '\033[2m%s\033[0m' "$*"; }
err() { echo "$(red error:) $*" >&2; exit 1; }
info() { echo "$(green ::) $*"; }
note() { echo " $(dim "$*")"; }
need() {
command -v "$1" >/dev/null 2>&1 || err "missing required tool: $1"
}
need uname
need curl
need tar
need install || true # not strictly required
OS="$(uname -s)"
ARCH="$(uname -m)"
case "$OS" in
Darwin) os_tag="apple-darwin" ;;
Linux) os_tag="unknown-linux-gnu" ;;
*) err "unsupported OS: $OS" ;;
esac
case "$ARCH" in
arm64|aarch64) arch_tag="aarch64" ;;
x86_64|amd64) arch_tag="x86_64" ;;
*) err "unsupported arch: $ARCH" ;;
esac
TARGET="${arch_tag}-${os_tag}"
info "detected target: $TARGET"
if [ "$VERSION" = "latest" ]; then
api_url="https://api.github.com/repos/${REPO}/releases/latest"
VERSION="$(curl -fsSL "$api_url" 2>/dev/null \
| sed -n 's/.*"tag_name": *"\([^"]*\)".*/\1/p' | head -n1)"
[ -n "$VERSION" ] || err "could not resolve latest release at $api_url"
fi
info "installing $REPO @ $VERSION"
asset="microcode-${VERSION#v}-${TARGET}.tar.gz"
url="https://github.com/${REPO}/releases/download/${VERSION}/${asset}"
note "$url"
if [ -n "${MICROCODE_INSTALL_DIR:-}" ]; then
DEST="$MICROCODE_INSTALL_DIR"
elif [ -w /usr/local/bin ]; then
DEST="/usr/local/bin"
else
DEST="$HOME/.local/bin"
mkdir -p "$DEST"
fi
info "install dir: $DEST"
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
( cd "$tmp" && curl -fSL --progress-bar "$url" -o "$asset" )
( cd "$tmp" && tar -xzf "$asset" )
[ -f "$tmp/microcode" ] || err "archive did not contain microcode binary"
mv "$tmp/microcode" "$DEST/microcode"
chmod +x "$DEST/microcode"
info "$(green installed) $DEST/microcode"
case ":$PATH:" in
*":$DEST:"*) ;;
*) note "(add $DEST to your PATH if it isn't already)" ;;
esac
"$DEST/microcode" --version