forked from PotLock/zerobuild
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·277 lines (231 loc) · 6.89 KB
/
install.sh
File metadata and controls
executable file
·277 lines (231 loc) · 6.89 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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#!/usr/bin/env bash
#
# ZeroBuild One-Click Installer
#
# Install ZeroBuild quickly using:
# curl -fsSL https://raw.githubusercontent.com/PotLock/zerobuild/main/install.sh | bash
#
# Or with wget:
# wget -qO- https://raw.githubusercontent.com/PotLock/zerobuild/main/install.sh | bash
set -euo pipefail
REPO="PotLock/zerobuild"
REGISTRY="ghcr.io"
IMAGE="$REGISTRY/$REPO"
INSTALL_DIR="${INSTALL_DIR:-$HOME/.local/bin}"
info() {
echo -e "\033[34m==>\033[0m $*"
}
error() {
echo -e "\033[31merror:\033[0m $*" >&2
}
success() {
echo -e "\033[32m✓\033[0m $*"
}
have_cmd() {
command -v "$1" >/dev/null 2>&1
}
detect_platform() {
local os arch
os="$(uname -s | tr '[:upper:]' '[:lower:]')"
arch="$(uname -m)"
case "$os:$arch" in
linux:x86_64)
echo "linux-amd64"
;;
linux:aarch64|linux:arm64)
echo "linux-arm64"
;;
darwin:x86_64)
echo "darwin-amd64"
;;
darwin:arm64|darwin:aarch64)
echo "darwin-arm64"
;;
*)
echo ""
;;
esac
}
install_docker() {
info "Installing ZeroBuild via Docker..."
if ! have_cmd docker && ! have_cmd podman; then
error "Docker or Podman is required but not installed."
error "Please install Docker: https://docs.docker.com/get-docker/"
exit 1
fi
local container_cmd="docker"
if ! have_cmd docker && have_cmd podman; then
container_cmd="podman"
info "Using Podman instead of Docker"
fi
# Pull the latest image
info "Pulling ZeroBuild image from GitHub Container Registry..."
$container_cmd pull "$IMAGE:latest"
# Create data directory
local data_dir="$HOME/.zerobuild"
mkdir -p "$data_dir"/{workspace,.zerobuild}
# Create wrapper script
cat > "$INSTALL_DIR/zerobuild" <<EOF
#!/usr/bin/env bash
# ZeroBuild Docker wrapper
exec $container_cmd run --rm -it \\
-v "$data_dir/.zerobuild:/zerobuild-data/.zerobuild" \\
-v "$data_dir/workspace:/zerobuild-data/workspace" \\
-e HOME=/zerobuild-data \\
-e ZEROBUILD_WORKSPACE=/zerobuild-data/workspace \\
-p 42617:42617 \\
$IMAGE:latest \\
"\$@"
EOF
chmod +x "$INSTALL_DIR/zerobuild"
success "ZeroBuild installed successfully!"
info "Data directory: $data_dir"
info "Usage: zerobuild <command>"
info "Example: zerobuild --help"
# Check if in PATH
if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
info ""
info "Add to your PATH:"
echo "export PATH=\"$INSTALL_DIR:\$PATH\""
info "Or run: echo 'export PATH=\"$INSTALL_DIR:\$PATH\"' >> ~/.bashrc"
fi
}
install_binary() {
local platform="$(detect_platform)"
if [[ -z "$platform" ]]; then
error "Unsupported platform: $(uname -s) $(uname -m)"
error "Try Docker installation instead:"
echo " curl -fsSL https://raw.githubusercontent.com/$REPO/main/install.sh | bash -s -- --docker"
exit 1
fi
info "Installing ZeroBuild binary for $platform..."
# Create temp directory
local tmp_dir="$(mktemp -d)"
trap "rm -rf $tmp_dir" EXIT
# Download binary
local download_url="https://github.com/$REPO/releases/latest/download/zerobuild-$platform.tar.gz"
info "Downloading from $download_url..."
if ! curl -fsSL "$download_url" -o "$tmp_dir/zerobuild.tar.gz"; then
error "Failed to download binary"
error "The binary may not be available yet. Try Docker installation:"
echo " curl -fsSL https://raw.githubusercontent.com/$REPO/main/install.sh | bash -s -- --docker"
exit 1
fi
# Extract
tar -xzf "$tmp_dir/zerobuild.tar.gz" -C "$tmp_dir"
# Install
mkdir -p "$INSTALL_DIR"
mv "$tmp_dir/zerobuild" "$INSTALL_DIR/zerobuild"
chmod +x "$INSTALL_DIR/zerobuild"
success "ZeroBuild binary installed to $INSTALL_DIR/zerobuild"
}
install_source() {
info "Building ZeroBuild from source..."
if ! have_cmd cargo; then
error "Rust/Cargo is required to build from source."
error "Install Rust: https://rustup.rs/"
error "Or use Docker installation:"
echo " curl -fsSL https://raw.githubusercontent.com/$REPO/main/install.sh | bash -s -- --docker"
exit 1
fi
# Clone repo
local tmp_dir="$(mktemp -d)"
trap "rm -rf $tmp_dir" EXIT
info "Cloning repository..."
git clone --depth 1 "https://github.com/$REPO.git" "$tmp_dir/zerobuild"
info "Building (this may take a few minutes)..."
cd "$tmp_dir/zerobuild"
cargo build --release --locked
# Install
mkdir -p "$INSTALL_DIR"
cp "$tmp_dir/zerobuild/target/release/zerobuild" "$INSTALL_DIR/zerobuild"
chmod +x "$INSTALL_DIR/zerobuild"
success "ZeroBuild built and installed to $INSTALL_DIR/zerobuild"
}
# Main installation logic
main() {
local method="${1:-auto}"
# Parse arguments
case "$method" in
--docker|-d)
method="docker"
;;
--binary|-b)
method="binary"
;;
--source|-s)
method="source"
;;
--help|-h)
cat <<'EOF'
ZeroBuild One-Click Installer
Usage:
curl -fsSL https://raw.githubusercontent.com/PotLock/zerobuild/main/install.sh | bash
Options:
--docker, -d Install using Docker (recommended, fastest)
--binary, -b Install pre-built binary
--source, -s Build and install from source
--help, -h Show this help message
Environment:
INSTALL_DIR Installation directory (default: ~/.local/bin)
Examples:
# Default: auto-detect best method
curl -fsSL ... | bash
# Force Docker installation
curl -fsSL ... | bash -s -- --docker
# Install to custom directory
INSTALL_DIR=/usr/local/bin curl -fsSL ... | bash
EOF
exit 0
;;
esac
echo ""
echo " ╔══════════════════════════════════════════╗"
echo " ║ ZeroBuild Installer ║"
echo " ║ Autonomous Software Factory Agent ║"
echo " ╚══════════════════════════════════════════╝"
echo ""
# Auto-detect method
if [[ "$method" == "auto" ]]; then
if have_cmd docker || have_cmd podman; then
method="docker"
info "Docker detected, using Docker installation method"
elif have_cmd cargo; then
method="source"
info "Cargo detected, building from source"
else
method="binary"
info "Attempting binary installation"
fi
fi
# Run installation
case "$method" in
docker)
install_docker
;;
binary)
install_binary
;;
source)
install_source
;;
*)
error "Unknown installation method: $method"
exit 1
;;
esac
# Verify installation
if [[ -x "$INSTALL_DIR/zerobuild" ]]; then
echo ""
success "Installation complete!"
echo ""
info "Next steps:"
echo " 1. Run: export PATH=\"$INSTALL_DIR:\$PATH\" (if not in PATH)"
echo " 2. Setup: zerobuild onboard"
echo " 3. Usage: zerobuild --help"
echo ""
info "Documentation: https://github.com/$REPO"
info "Support: https://github.com/$REPO/issues"
fi
}
main "$@"