-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·195 lines (166 loc) · 4.85 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·195 lines (166 loc) · 4.85 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/bin/bash
# MayR Labs CLI Installation Script
# Usage: curl -sSL https://raw.githubusercontent.com/MayR-Labs/mayrlabs-go/main/install.sh | bash
# or: wget -qO- https://raw.githubusercontent.com/MayR-Labs/mayrlabs-go/main/install.sh | bash
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Detect OS and architecture
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
# Convert architecture names
case "$ARCH" in
x86_64)
ARCH="amd64"
;;
aarch64|arm64)
ARCH="arm64"
;;
*)
echo -e "${RED}Unsupported architecture: $ARCH${NC}"
exit 1
;;
esac
# Map OS names
case "$OS" in
linux)
OS="linux"
;;
darwin)
OS="darwin"
;;
mingw*|msys*|cygwin*)
OS="windows"
;;
*)
echo -e "${RED}Unsupported operating system: $OS${NC}"
exit 1
;;
esac
# Set binary name
BINARY_NAME="mayrlabs"
if [ "$OS" = "windows" ]; then
BINARY_NAME="mayrlabs.exe"
fi
# GitHub repository details
REPO="MayR-Labs/mayrlabs-go"
RELEASE_URL="https://api.github.com/repos/$REPO/releases/latest"
echo -e "${GREEN}🧰 MayR Labs CLI Installer${NC}"
echo ""
echo "Detected system: $OS-$ARCH"
echo ""
# Get latest release version
echo "Fetching latest release..."
if command -v jq >/dev/null 2>&1; then
# Use jq if available for robust JSON parsing
LATEST_VERSION=$(curl -s "$RELEASE_URL" | jq -r '.tag_name')
else
# Fallback to grep/sed parsing
LATEST_VERSION=$(curl -s "$RELEASE_URL" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
fi
if [ -z "$LATEST_VERSION" ] || [ "$LATEST_VERSION" = "null" ]; then
echo -e "${RED}Failed to fetch latest release version${NC}"
echo "Please check your internet connection and try again."
exit 1
fi
echo "Latest version: $LATEST_VERSION"
# Construct download URL
DOWNLOAD_FILE="mayrlabs-${OS}-${ARCH}"
if [ "$OS" = "windows" ]; then
DOWNLOAD_FILE="${DOWNLOAD_FILE}.exe"
fi
DOWNLOAD_URL="https://github.com/$REPO/releases/download/$LATEST_VERSION/$DOWNLOAD_FILE"
echo ""
echo "Downloading $DOWNLOAD_FILE..."
# Download the binary
TMP_DIR=$(mktemp -d)
TMP_FILE="$TMP_DIR/$BINARY_NAME"
if command -v curl >/dev/null 2>&1; then
curl -L -o "$TMP_FILE" "$DOWNLOAD_URL"
elif command -v wget >/dev/null 2>&1; then
wget -O "$TMP_FILE" "$DOWNLOAD_URL"
else
echo -e "${RED}Error: curl or wget is required but not found${NC}"
exit 1
fi
# Make executable
chmod +x "$TMP_FILE"
# Determine installation directory
INSTALL_DIR=""
if [ "$OS" = "windows" ]; then
# On Windows, install to user's local bin
INSTALL_DIR="$HOME/bin"
mkdir -p "$INSTALL_DIR"
else
# Try to install to /usr/local/bin (requires sudo)
if [ -w "/usr/local/bin" ]; then
INSTALL_DIR="/usr/local/bin"
else
# Fallback to user's local bin
INSTALL_DIR="$HOME/.local/bin"
mkdir -p "$INSTALL_DIR"
fi
fi
# Install the binary
echo ""
echo "Installing to $INSTALL_DIR..."
if [ "$INSTALL_DIR" = "/usr/local/bin" ] && [ ! -w "$INSTALL_DIR" ]; then
# Need sudo for /usr/local/bin
echo -e "${YELLOW}Installing to $INSTALL_DIR requires sudo privileges${NC}"
sudo mv "$TMP_FILE" "$INSTALL_DIR/$BINARY_NAME"
else
mv "$TMP_FILE" "$INSTALL_DIR/$BINARY_NAME"
fi
# Clean up
rm -rf "$TMP_DIR"
echo ""
echo -e "${GREEN}✅ MayR Labs CLI installed successfully!${NC}"
echo ""
# Check if installation directory is in PATH
if ! echo "$PATH" | grep -q "$INSTALL_DIR"; then
echo -e "${YELLOW}⚠️ Warning: $INSTALL_DIR is not in your PATH${NC}"
echo ""
echo "Add it to your PATH by adding this line to your shell configuration file:"
echo ""
if [ "$OS" = "darwin" ] || [ "$OS" = "linux" ]; then
SHELL_NAME=$(basename "$SHELL")
case "$SHELL_NAME" in
bash)
CONFIG_FILE="~/.bashrc"
;;
zsh)
CONFIG_FILE="~/.zshrc"
;;
fish)
CONFIG_FILE="~/.config/fish/config.fish"
echo " set -gx PATH $INSTALL_DIR \$PATH"
;;
*)
CONFIG_FILE="~/.profile"
;;
esac
if [ "$SHELL_NAME" != "fish" ]; then
echo " export PATH=\"$INSTALL_DIR:\$PATH\""
fi
echo ""
echo "Then run:"
echo " source $CONFIG_FILE"
fi
echo ""
fi
# Verify installation
echo "Verifying installation..."
if command -v mayrlabs >/dev/null 2>&1; then
VERSION=$(mayrlabs version 2>&1 || echo "unknown")
echo -e "${GREEN}$VERSION${NC}"
echo ""
echo "Run 'mayrlabs --help' to get started!"
else
echo -e "${YELLOW}mayrlabs command not found. Please add $INSTALL_DIR to your PATH${NC}"
fi
echo ""
echo "📚 Documentation: https://github.com/$REPO"
echo "🌐 Website: https://mayrlabs.com"