-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
244 lines (205 loc) · 5.76 KB
/
Copy pathinstall.sh
File metadata and controls
244 lines (205 loc) · 5.76 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#!/bin/bash
#
# Matrix Install Script
# Downloads and installs the Matrix CLI binary for your platform
#
# Usage:
# curl -fsSL https://raw.githubusercontent.com/your-org/matrix-releases/main/install.sh | bash
#
# Or download and run locally:
# chmod +x install.sh && ./install.sh
#
set -e
# Configuration
REPO="CoreBunch/matrix-releases"
BINARY_NAME="matrix"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Helper functions
info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
error() {
echo -e "${RED}[ERROR]${NC} $1"
exit 1
}
# Detect OS
detect_os() {
local os
case "$(uname -s)" in
Darwin*)
os="darwin"
;;
Linux*)
os="linux"
;;
MINGW*|MSYS*|CYGWIN*|Windows_NT)
os="win32"
;;
*)
error "Unsupported operating system: $(uname -s)"
;;
esac
echo "$os"
}
# Detect architecture
detect_arch() {
local arch
case "$(uname -m)" in
x86_64|amd64)
arch="x64"
;;
arm64|aarch64)
arch="arm64"
;;
*)
error "Unsupported architecture: $(uname -m)"
;;
esac
echo "$arch"
}
# Get the latest release version from GitHub
get_latest_version() {
local version
version=$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "$version" ]; then
error "Failed to fetch latest version from GitHub"
fi
echo "$version"
}
# Determine install directory
get_install_dir() {
local install_dir
# Check if we can write to /usr/local/bin
if [ -w "/usr/local/bin" ]; then
install_dir="/usr/local/bin"
elif [ -d "$HOME/.local/bin" ] || mkdir -p "$HOME/.local/bin" 2>/dev/null; then
install_dir="$HOME/.local/bin"
else
error "Cannot find suitable installation directory. Please create ~/.local/bin or run with sudo."
fi
echo "$install_dir"
}
# Download and install the binary
install_binary() {
local os="$1"
local arch="$2"
local version="$3"
local install_dir="$4"
# Construct binary name
local binary_filename="${BINARY_NAME}-${os}-${arch}"
if [ "$os" = "win32" ]; then
binary_filename="${binary_filename}.exe"
fi
# Construct download URL
local download_url="https://github.com/${REPO}/releases/download/${version}/${binary_filename}"
info "Downloading ${binary_filename} from ${download_url}..."
# Create temp directory
local tmp_dir
tmp_dir=$(mktemp -d)
trap "rm -rf $tmp_dir" EXIT
# Download binary
local tmp_binary="$tmp_dir/$binary_filename"
if ! curl -fsSL -o "$tmp_binary" "$download_url"; then
error "Failed to download binary from $download_url"
fi
# Determine final binary name
local final_name="$BINARY_NAME"
if [ "$os" = "win32" ]; then
final_name="${BINARY_NAME}.exe"
fi
# Move to install directory
local final_path="$install_dir/$final_name"
# Check if existing binary and back it up
if [ -f "$final_path" ]; then
warning "Existing installation found. Creating backup..."
mv "$final_path" "${final_path}.backup" || true
fi
info "Installing to $final_path..."
mv "$tmp_binary" "$final_path"
# Make executable (not needed on Windows but doesn't hurt)
chmod +x "$final_path"
success "Matrix installed successfully!"
}
# Verify installation
verify_installation() {
local install_dir="$1"
local binary_path="$install_dir/$BINARY_NAME"
# Check if binary exists and is executable
if [ ! -x "$binary_path" ]; then
error "Installation verification failed: binary not found or not executable"
fi
# Try to get version
info "Verifying installation..."
if "$binary_path" --version 2>/dev/null; then
success "Installation verified!"
else
warning "Binary installed but version check failed. This might be expected for first-time installs."
fi
}
# Check if install directory is in PATH
check_path() {
local install_dir="$1"
if [[ ":$PATH:" != *":$install_dir:"* ]]; then
echo ""
warning "Installation directory is not in your PATH!"
echo ""
echo "Add the following to your shell profile (~/.bashrc, ~/.zshrc, etc.):"
echo ""
echo " export PATH=\"\$PATH:$install_dir\""
echo ""
echo "Then restart your shell or run:"
echo ""
echo " source ~/.bashrc # or ~/.zshrc"
echo ""
fi
}
# Main installation flow
main() {
echo ""
echo "=================================="
echo " Matrix CLI Installer"
echo "=================================="
echo ""
# Detect platform
local os
local arch
os=$(detect_os)
arch=$(detect_arch)
info "Detected platform: ${os}-${arch}"
# Get latest version
info "Fetching latest release version..."
local version
version=$(get_latest_version)
info "Latest version: $version"
# Get install directory
local install_dir
install_dir=$(get_install_dir)
info "Install directory: $install_dir"
# Install binary
install_binary "$os" "$arch" "$version" "$install_dir"
# Verify installation
verify_installation "$install_dir"
# Check PATH
check_path "$install_dir"
echo ""
success "Matrix is ready to use!"
echo ""
echo "Get started:"
echo " matrix init # Initialize Matrix in your project"
echo " matrix # Open the dashboard"
echo " matrix --help # Show all commands"
echo ""
}
# Run main
main "$@"