-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·331 lines (273 loc) · 9 KB
/
install.sh
File metadata and controls
executable file
·331 lines (273 loc) · 9 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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
#!/bin/sh
set -e
# AGFS Installation Script
# This script downloads and installs the latest daily build of agfs-server and agfs-shell
REPO="c4pt0r/agfs"
INSTALL_DIR="${INSTALL_DIR:-$HOME/.local/bin}"
AGFS_SHELL_DIR="${AGFS_SHELL_DIR:-$HOME/.local/agfs-shell}"
INSTALL_SERVER="${INSTALL_SERVER:-yes}"
INSTALL_CLIENT="${INSTALL_CLIENT:-yes}"
# 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"
;;
*)
echo "Error: Unsupported operating system: $OS"
exit 1
;;
esac
case "$ARCH" in
x86_64 | amd64)
ARCH="amd64"
;;
aarch64 | arm64)
ARCH="arm64"
;;
*)
echo "Error: Unsupported architecture: $ARCH"
exit 1
;;
esac
echo "Detected platform: $OS-$ARCH"
}
# Get the nightly build tag
get_latest_tag() {
echo "Fetching nightly build..."
LATEST_TAG="nightly"
echo "Using nightly build"
}
# Check Python version
check_python() {
if ! command -v python3 >/dev/null 2>&1; then
echo "Warning: python3 not found. agfs-shell requires Python 3.10+"
return 1
fi
PYTHON_VERSION=$(python3 -c 'import sys; print(".".join(map(str, sys.version_info[:2])))')
PYTHON_MAJOR=$(echo "$PYTHON_VERSION" | cut -d. -f1)
PYTHON_MINOR=$(echo "$PYTHON_VERSION" | cut -d. -f2)
if [ "$PYTHON_MAJOR" -lt 3 ] || { [ "$PYTHON_MAJOR" -eq 3 ] && [ "$PYTHON_MINOR" -lt 10 ]; }; then
echo "Warning: Python $PYTHON_VERSION found, but agfs-shell requires Python 3.10+"
return 1
fi
echo "Found Python $PYTHON_VERSION"
return 0
}
# Install agfs-server
install_server() {
echo ""
echo "Installing agfs-server..."
# Get the date from the nightly release
DATE=$(curl -sL "https://api.github.com/repos/$REPO/releases/tags/$LATEST_TAG" | \
grep '"name":' | \
head -n 1 | \
sed -E 's/.*\(([0-9]+)\).*/\1/')
if [ -z "$DATE" ]; then
echo "Error: Could not determine build date from nightly release"
exit 1
fi
if [ "$OS" = "windows" ]; then
ARCHIVE="agfs-${OS}-${ARCH}-${DATE}.zip"
BINARY="agfs-server-${OS}-${ARCH}.exe"
else
ARCHIVE="agfs-${OS}-${ARCH}-${DATE}.tar.gz"
BINARY="agfs-server-${OS}-${ARCH}"
fi
DOWNLOAD_URL="https://github.com/$REPO/releases/download/$LATEST_TAG/$ARCHIVE"
echo "Downloading from: $DOWNLOAD_URL"
TMP_DIR=$(mktemp -d)
cd "$TMP_DIR"
if ! curl -fsSL -o "$ARCHIVE" "$DOWNLOAD_URL"; then
echo "Error: Failed to download $ARCHIVE"
rm -rf "$TMP_DIR"
exit 1
fi
echo "Extracting archive..."
if [ "$OS" = "windows" ]; then
unzip -q "$ARCHIVE"
else
tar -xzf "$ARCHIVE"
fi
if [ ! -f "$BINARY" ]; then
echo "Error: Binary $BINARY not found in archive"
rm -rf "$TMP_DIR"
exit 1
fi
# Create install directory if it doesn't exist
mkdir -p "$INSTALL_DIR"
# Install binary
mv "$BINARY" "$INSTALL_DIR/agfs-server"
chmod +x "$INSTALL_DIR/agfs-server"
# Clean up
cd - > /dev/null
rm -rf "$TMP_DIR"
echo "✓ agfs-server installed to $INSTALL_DIR/agfs-server"
# Install systemd service on Linux systems
if [ "$OS" = "linux" ] && command -v systemctl >/dev/null 2>&1; then
install_systemd_service
fi
}
# Install systemd service
install_systemd_service() {
echo ""
echo "Installing systemd service..."
# Download service file template (use master branch, not release tag)
SERVICE_URL="https://raw.githubusercontent.com/$REPO/master/agfs-server/agfs-server.service"
TMP_SERVICE=$(mktemp)
if ! curl -fsSL -o "$TMP_SERVICE" "$SERVICE_URL" 2>/dev/null; then
echo "Warning: Could not download systemd service file, skipping service installation"
rm -f "$TMP_SERVICE"
return 1
fi
# Get current user and group
CURRENT_USER=$(whoami)
CURRENT_GROUP=$(id -gn)
# Replace placeholders
sed -e "s|%USER%|$CURRENT_USER|g" \
-e "s|%GROUP%|$CURRENT_GROUP|g" \
-e "s|%INSTALL_DIR%|$INSTALL_DIR|g" \
"$TMP_SERVICE" > "$TMP_SERVICE.processed"
# Install systemd service (requires root/sudo)
if [ "$CURRENT_USER" = "root" ]; then
# Running as root
cp "$TMP_SERVICE.processed" /etc/systemd/system/agfs-server.service
systemctl daemon-reload
echo "✓ systemd service installed to /etc/systemd/system/agfs-server.service"
echo ""
echo "To enable and start the service:"
echo " systemctl enable agfs-server"
echo " systemctl start agfs-server"
else
# Require sudo with password prompt
echo "Installing systemd service requires root privileges."
if ! sudo cp "$TMP_SERVICE.processed" /etc/systemd/system/agfs-server.service; then
echo "Error: Failed to install systemd service (sudo required)"
rm -f "$TMP_SERVICE" "$TMP_SERVICE.processed"
return 1
fi
sudo systemctl daemon-reload
echo "✓ systemd service installed to /etc/systemd/system/agfs-server.service"
echo ""
echo "To enable and start the service:"
echo " sudo systemctl enable agfs-server"
echo " sudo systemctl start agfs-server"
fi
rm -f "$TMP_SERVICE" "$TMP_SERVICE.processed"
}
# Install agfs-shell
install_client() {
echo ""
echo "Installing agfs-shell..."
# Check Python
if ! check_python; then
echo "Skipping agfs-shell installation (Python requirement not met)"
return 1
fi
# Only build for supported platforms
if [ "$OS" = "windows" ]; then
if [ "$ARCH" != "amd64" ] && [ "$ARCH" != "arm64" ]; then
echo "Skipping agfs-shell: Not available for $OS-$ARCH"
return 1
fi
SHELL_ARCHIVE="agfs-shell-${OS}-${ARCH}.zip"
else
if [ "$ARCH" != "amd64" ] && ! { [ "$OS" = "darwin" ] && [ "$ARCH" = "arm64" ]; } && ! { [ "$OS" = "linux" ] && [ "$ARCH" = "arm64" ]; }; then
echo "Skipping agfs-shell: Not available for $OS-$ARCH"
return 1
fi
SHELL_ARCHIVE="agfs-shell-${OS}-${ARCH}.tar.gz"
fi
SHELL_URL="https://github.com/$REPO/releases/download/$LATEST_TAG/$SHELL_ARCHIVE"
echo "Downloading from: $SHELL_URL"
TMP_DIR=$(mktemp -d)
cd "$TMP_DIR"
if ! curl -fsSL -o "$SHELL_ARCHIVE" "$SHELL_URL"; then
echo "Warning: Failed to download agfs-shell, skipping client installation"
rm -rf "$TMP_DIR"
return 1
fi
echo "Extracting archive..."
if [ "$OS" = "windows" ]; then
unzip -q "$SHELL_ARCHIVE"
else
tar -xzf "$SHELL_ARCHIVE"
fi
if [ ! -d "agfs-shell-portable" ]; then
echo "Error: agfs-shell-portable directory not found in archive"
rm -rf "$TMP_DIR"
return 1
fi
# Remove old installation
rm -rf "$AGFS_SHELL_DIR"
mkdir -p "$AGFS_SHELL_DIR"
# Copy portable directory
cp -r agfs-shell-portable/* "$AGFS_SHELL_DIR/"
# Create symlink (rename to 'agfs' for convenience)
mkdir -p "$INSTALL_DIR"
ln -sf "$AGFS_SHELL_DIR/agfs-shell" "$INSTALL_DIR/agfs"
# Clean up
cd - > /dev/null
rm -rf "$TMP_DIR"
echo "✓ agfs-shell installed to $AGFS_SHELL_DIR"
echo " Symlink created: $INSTALL_DIR/agfs"
}
show_completion() {
echo ""
echo "----------------------------------"
echo " Installation completed!"
echo "----------------------------------"
echo ""
if [ "$INSTALL_SERVER" = "yes" ]; then
echo "Server: agfs-server"
echo " Location: $INSTALL_DIR/agfs-server"
echo " Usage: agfs-server --help"
echo ""
fi
if [ "$INSTALL_CLIENT" = "yes" ] && [ -f "$INSTALL_DIR/agfs" ]; then
echo "Client: agfs"
echo " Location: $INSTALL_DIR/agfs"
echo " Usage: agfs --help"
echo " Interactive: agfs"
echo ""
fi
# Check if install dir is in PATH
case ":$PATH:" in
*":$INSTALL_DIR:"*)
;;
*)
echo "Note: $INSTALL_DIR is not in your PATH."
echo "Add it to your PATH by adding this to ~/.bashrc or ~/.zshrc:"
echo " export PATH=\"\$PATH:$INSTALL_DIR\""
echo ""
;;
esac
echo "Quick Start:"
echo " 1. Start server: agfs-server"
echo " 2. Use client: agfs"
}
main() {
echo ""
echo "----------------------------------"
echo " AGFS Installer "
echo "----------------------------------"
echo ""
detect_platform
get_latest_tag
if [ "$INSTALL_SERVER" = "yes" ]; then
install_server
fi
if [ "$INSTALL_CLIENT" = "yes" ]; then
install_client || true # Don't fail if client install fails
fi
show_completion
}
main