forked from mammouth-ai/code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
175 lines (144 loc) · 4.18 KB
/
install.sh
File metadata and controls
175 lines (144 loc) · 4.18 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/bash
set -e
# Mammouth Code Installer
# Usage: curl -fsSL https://raw.githubusercontent.com/mammouth-ai/code/dev/install.sh | bash
REPO="mammouth-ai/code"
BINARY_NAME="mammouth"
INSTALL_DIR="$HOME/.mammouth/bin"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
info() { echo -e "${GREEN}[INFO]${NC} $1"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
error() { echo -e "${RED}[ERROR]${NC} $1" >&2; exit 1; }
# Detect OS and architecture
detect_platform() {
OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
ARCH="$(uname -m)"
case "$OS" in
linux) OS="linux" ;;
darwin) OS="darwin" ;;
mingw*|msys*|cygwin*) OS="windows" ;;
*) error "Unsupported OS: $OS" ;;
esac
case "$ARCH" in
x86_64|amd64) ARCH="x64" ;;
aarch64|arm64) ARCH="arm64" ;;
*) error "Unsupported architecture: $ARCH" ;;
esac
# Check for musl (Alpine Linux, etc.)
LIBC=""
if [ "$OS" = "linux" ]; then
if ldd --version 2>&1 | grep -qi musl || [ -f /etc/alpine-release ]; then
LIBC="-musl"
fi
fi
# Check for AVX2 support on Linux x64; fall back to baseline binary if absent
VARIANT=""
if [ "$OS" = "linux" ] && [ "$ARCH" = "x64" ]; then
if ! grep -q avx2 /proc/cpuinfo 2>/dev/null; then
VARIANT="-baseline"
fi
fi
PLATFORM="${BINARY_NAME}-${OS}-${ARCH}${LIBC}${VARIANT}"
}
# Get latest version from GitHub API
get_latest_version() {
if [ -n "$VERSION" ]; then
echo "$VERSION"
return
fi
VERSION=$(curl -sfL "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"v([^"]+)".*/\1/')
if [ -z "$VERSION" ]; then
error "Failed to get latest version"
fi
echo "$VERSION"
}
# Download and install
install() {
detect_platform
VERSION=$(get_latest_version)
info "Installing Mammouth Code v${VERSION} for ${PLATFORM}..."
# Create install directory
mkdir -p "$INSTALL_DIR"
# Determine archive extension
if [ "$OS" = "windows" ]; then
EXT="zip"
else
EXT="tar.gz"
fi
DOWNLOAD_URL="https://github.com/${REPO}/releases/download/v${VERSION}/${PLATFORM}.${EXT}"
TEMP_DIR=$(mktemp -d)
ARCHIVE_PATH="${TEMP_DIR}/${PLATFORM}.${EXT}"
info "Downloading from ${DOWNLOAD_URL}..."
if ! curl -fsSL "$DOWNLOAD_URL" -o "$ARCHIVE_PATH"; then
error "Failed to download. Check if the release exists for your platform."
fi
info "Extracting..."
if [ "$EXT" = "zip" ]; then
unzip -q "$ARCHIVE_PATH" -d "$TEMP_DIR"
else
tar -xzf "$ARCHIVE_PATH" -C "$TEMP_DIR"
fi
# Find and copy binary
BINARY_PATH=$(find "$TEMP_DIR" -name "$BINARY_NAME" -type f | head -n 1)
if [ -z "$BINARY_PATH" ]; then
BINARY_PATH=$(find "$TEMP_DIR" -name "${BINARY_NAME}.exe" -type f | head -n 1)
fi
if [ -z "$BINARY_PATH" ]; then
error "Binary not found in archive"
fi
rm -f "$INSTALL_DIR/$BINARY_NAME"
cp "$BINARY_PATH" "$INSTALL_DIR/$BINARY_NAME"
chmod +x "$INSTALL_DIR/$BINARY_NAME"
# Cleanup
rm -rf "$TEMP_DIR"
info "Installed to ${INSTALL_DIR}/${BINARY_NAME}"
# Add to PATH instructions
setup_path
}
setup_path() {
SHELL_NAME=$(basename "$SHELL")
EXPORT_LINE="export PATH=\"\$HOME/.mammouth/bin:\$PATH\""
case "$SHELL_NAME" in
bash)
PROFILE="$HOME/.bashrc"
[ -f "$HOME/.bash_profile" ] && PROFILE="$HOME/.bash_profile"
;;
zsh)
PROFILE="$HOME/.zshrc"
;;
fish)
EXPORT_LINE="set -gx PATH \$HOME/.mammouth/bin \$PATH"
PROFILE="$HOME/.config/fish/config.fish"
;;
*)
PROFILE="$HOME/.profile"
;;
esac
# Check if already in PATH
if echo "$PATH" | grep -q ".mammouth/bin"; then
info "Mammouth Code is ready! Run 'mammouth' to get started."
return
fi
# Add to profile if not already there
if [ -f "$PROFILE" ] && grep -q ".mammouth/bin" "$PROFILE"; then
info "PATH already configured in $PROFILE"
else
echo "" >> "$PROFILE"
echo "# Mammouth Code" >> "$PROFILE"
echo "$EXPORT_LINE" >> "$PROFILE"
info "Added to PATH in $PROFILE"
fi
echo ""
info "Installation complete!"
echo ""
echo "To start using Mammouth Code, either:"
echo " 1. Restart your terminal, or"
echo " 2. Run: source $PROFILE"
echo ""
echo "Then run: mammouth"
}
install