-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·183 lines (150 loc) · 4.8 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·183 lines (150 loc) · 4.8 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
#!/usr/bin/env bash
set -euo pipefail
# VectorCode installer for macOS and Linux
# Usage: curl -fsSL https://raw.githubusercontent.com/alejandro-technology/vectorcode/main/install.sh | bash
REPO="alejandro-technology/vectorcode"
BINARY_NAME="vectorcode"
INSTALL_DIR="/usr/local/bin"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
info() {
echo -e "${GREEN}✓${NC} $1"
}
warn() {
echo -e "${YELLOW}⚠${NC} $1"
}
error() {
echo -e "${RED}✗${NC} $1"
exit 1
}
detect_os() {
local os
os="$(uname -s)"
case "$os" in
Linux*) echo "linux" ;;
Darwin*) echo "darwin" ;;
*) error "Unsupported OS: $os. VectorCode supports macOS and Linux." ;;
esac
}
detect_arch() {
local arch
arch="$(uname -m)"
case "$arch" in
x86_64|amd64) echo "x86_64" ;;
aarch64|arm64) echo "aarch64" ;;
*) error "Unsupported architecture: $arch" ;;
esac
}
check_dependencies() {
local missing=()
if ! command -v curl &>/dev/null; then
missing+=("curl")
fi
if [[ ${#missing[@]} -gt 0 ]]; then
error "Missing dependencies: ${missing[*]}. Please install them first."
fi
}
install_from_source() {
info "Building from source..."
if ! command -v cargo &>/dev/null; then
error "Rust/Cargo not found. Install from https://rustup.rs or use the binary release."
fi
local tmpdir
tmpdir="$(mktemp -d)"
trap 'rm -rf "$tmpdir"' EXIT
info "Cloning repository..."
git clone --depth 1 "https://github.com/${REPO}.git" "$tmpdir/vectorcode" 2>/dev/null || \
error "Failed to clone repository. Check the REPO variable or your network."
info "Building release binary (this may take a few minutes)..."
cargo build --release --manifest-path "$tmpdir/vectorcode/Cargo.toml" 2>/dev/null || \
error "Build failed. Check the error messages above."
install_binary "$tmpdir/vectorcode/target/release/$BINARY_NAME"
}
install_binary() {
local binary_path="$1"
if [[ ! -f "$binary_path" ]]; then
error "Binary not found at: $binary_path"
fi
# Check if install dir is writable
if [[ -w "$INSTALL_DIR" ]]; then
cp "$binary_path" "$INSTALL_DIR/$BINARY_NAME"
chmod +x "$INSTALL_DIR/$BINARY_NAME"
else
info "Installing to $INSTALL_DIR requires sudo"
sudo cp "$binary_path" "$INSTALL_DIR/$BINARY_NAME"
sudo chmod +x "$INSTALL_DIR/$BINARY_NAME"
fi
info "Installed $BINARY_NAME to $INSTALL_DIR/$BINARY_NAME"
}
download_release() {
local os="$1"
local arch="$2"
local version="${3:-latest}"
local download_url
if [[ "$version" == "latest" ]]; then
download_url="https://github.com/${REPO}/releases/latest/download/${BINARY_NAME}-${os}-${arch}"
else
download_url="https://github.com/${REPO}/releases/download/${version}/${BINARY_NAME}-${os}-${arch}"
fi
local tmpdir
tmpdir="$(mktemp -d)"
trap 'rm -rf "$tmpdir"' EXIT
info "Downloading $BINARY_NAME for $os/$arch..."
if curl -fsSL -o "$tmpdir/$BINARY_NAME" "$download_url" 2>/dev/null; then
chmod +x "$tmpdir/$BINARY_NAME"
install_binary "$tmpdir/$BINARY_NAME"
else
warn "Binary release not available for $os/$arch. Falling back to source build."
install_from_source
fi
}
main() {
echo ""
echo " VectorCode Installer"
echo " ════════════════════"
echo ""
check_dependencies
local os arch
os="$(detect_os)"
arch="$(detect_arch)"
info "Detected: $os/$arch"
# Parse arguments
local method="auto"
for arg in "$@"; do
case "$arg" in
--source) method="source" ;;
--binary) method="binary" ;;
--version=*) version="${arg#--version=}" ;;
--help|-h)
echo "Usage: install.sh [--source|--binary] [--version=TAG]"
echo ""
echo "Options:"
echo " --source Build from source (requires Rust/Cargo)"
echo " --binary Download pre-built binary (default: auto)"
echo " --version Specific version tag (default: latest)"
echo " --help Show this help"
exit 0
;;
esac
done
case "$method" in
source)
install_from_source
;;
binary)
download_release "$os" "$arch" "${version:-latest}"
;;
auto)
# Try binary first, fall back to source
download_release "$os" "$arch" "${version:-latest}"
;;
esac
echo ""
info "VectorCode installed successfully!"
info "Run 'vectorcode init' in your project to get started."
echo ""
}
main "$@"