Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·117 lines (97 loc) · 3.81 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·117 lines (97 loc) · 3.81 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
#!/bin/sh
# install.sh — Mithai binary installer
# Usage: curl -fsSL https://raw.githubusercontent.com/last9/mithai/master/install.sh | sh
#
# Environment variables:
# MITHAI_INSTALL_DIR — override install directory (default: /usr/local/bin)
# MITHAI_VERSION — override version (default: latest)
set -euf
REPO="last9/mithai"
INSTALL_DIR="${MITHAI_INSTALL_DIR:-/usr/local/bin}"
# ─── Helpers ──────────────────────────────────────────────────────────────────
info() { printf " %s\n" "$@"; }
error() { printf " ERROR: %s\n" "$@" >&2; exit 1; }
detect_platform() {
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
case "$ARCH" in
x86_64|amd64) ARCH="amd64" ;;
arm64|aarch64) ARCH="arm64" ;;
*) error "Unsupported architecture: $ARCH" ;;
esac
case "$OS" in
darwin|linux) ;;
*) error "Unsupported OS: $OS (only macOS and Linux are supported)" ;;
esac
echo "${OS}-${ARCH}"
}
has_cmd() { command -v "$1" >/dev/null 2>&1; }
# ─── Main ─────────────────────────────────────────────────────────────────────
PLATFORM=$(detect_platform)
echo ""
echo " Mithai Installer"
echo " ─────────────────"
info "Platform: ${PLATFORM}"
# Determine version
if [ -n "${MITHAI_VERSION:-}" ]; then
VERSION="$MITHAI_VERSION"
else
if has_cmd curl; then
VERSION=$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name"' | cut -d'"' -f4)
elif has_cmd wget; then
VERSION=$(wget -qO- "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name"' | cut -d'"' -f4)
else
error "curl or wget is required"
fi
fi
if [ -z "$VERSION" ]; then
error "Could not determine latest version. Set MITHAI_VERSION manually."
fi
info "Version: ${VERSION}"
URL="https://github.com/${REPO}/releases/download/${VERSION}/mithai-${PLATFORM}"
CHECKSUM_URL="https://github.com/${REPO}/releases/download/${VERSION}/checksums.txt"
info "Downloading mithai-${PLATFORM}..."
TMPDIR=$(mktemp -d)
trap 'rm -rf "$TMPDIR"' EXIT
if has_cmd curl; then
curl -fsSL "$URL" -o "${TMPDIR}/mithai"
curl -fsSL "$CHECKSUM_URL" -o "${TMPDIR}/checksums.txt" 2>/dev/null || true
elif has_cmd wget; then
wget -q "$URL" -O "${TMPDIR}/mithai"
wget -q "$CHECKSUM_URL" -O "${TMPDIR}/checksums.txt" 2>/dev/null || true
fi
# Verify checksum if available
if [ -f "${TMPDIR}/checksums.txt" ]; then
EXPECTED=$(grep "mithai-${PLATFORM}" "${TMPDIR}/checksums.txt" | awk '{print $1}')
if [ -n "$EXPECTED" ]; then
if has_cmd sha256sum; then
ACTUAL=$(sha256sum "${TMPDIR}/mithai" | awk '{print $1}')
elif has_cmd shasum; then
ACTUAL=$(shasum -a 256 "${TMPDIR}/mithai" | awk '{print $1}')
else
ACTUAL=""
fi
if [ -n "$ACTUAL" ] && [ "$EXPECTED" != "$ACTUAL" ]; then
error "Checksum mismatch! Expected: ${EXPECTED}, got: ${ACTUAL}"
fi
if [ -n "$ACTUAL" ]; then
info "Checksum: verified"
fi
fi
fi
chmod +x "${TMPDIR}/mithai"
# Install
if [ -w "$INSTALL_DIR" ]; then
mv "${TMPDIR}/mithai" "${INSTALL_DIR}/mithai"
else
info "Need sudo to install to ${INSTALL_DIR}"
sudo mv "${TMPDIR}/mithai" "${INSTALL_DIR}/mithai"
fi
info ""
info "✓ mithai ${VERSION} installed to ${INSTALL_DIR}/mithai"
info ""
info "Next steps:"
info " mithai init — interactive setup wizard"
info " mithai doctor — verify your configuration"
info " mithai --help — see all commands"
echo ""