-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
94 lines (77 loc) · 2.34 KB
/
install.sh
File metadata and controls
94 lines (77 loc) · 2.34 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
#!/usr/bin/env bash
set -euo pipefail
# Change this to your own owner/repo when forking (must match package.json "repository")
REPO="${AF_REPO:-miltonparedes/agentfiles}"
INSTALL_DIR="${HOME}/.local/bin"
BIN_NAME="af"
# Parse --version flag
VERSION=""
while [[ $# -gt 0 ]]; do
case "$1" in
--version) if [[ -z "${2:-}" ]]; then echo "Error: --version requires a value"; exit 1; fi; VERSION="$2"; shift 2 ;;
--version=*) VERSION="${1#*=}"; shift ;;
*) echo "Unknown option: $1"; exit 1 ;;
esac
done
detect_platform() {
local os arch
os="$(uname -s)"
arch="$(uname -m)"
case "$os" in
Linux) os="linux" ;;
Darwin) os="darwin" ;;
*) echo "Unsupported OS: $os" >&2; exit 1 ;;
esac
case "$arch" in
x86_64|amd64) arch="x64" ;;
arm64|aarch64) arch="arm64" ;;
*) echo "Unsupported architecture: $arch" >&2; exit 1 ;;
esac
local platform="${os}-${arch}"
if [[ "$platform" != "linux-x64" && "$platform" != "darwin-arm64" ]]; then
echo "Unsupported platform: ${platform} (only linux-x64 and darwin-arm64 have pre-built binaries)" >&2
exit 1
fi
echo "$platform"
}
get_download_url() {
local platform="$1"
local asset="af-${platform}"
local release_url
if [[ -n "$VERSION" ]]; then
release_url="https://github.com/${REPO}/releases/download/${VERSION}/${asset}"
else
local api_url="https://api.github.com/repos/${REPO}/releases/latest"
local tag
tag="$(curl -fsSL "$api_url" | grep '"tag_name"' | head -1 | cut -d'"' -f4)"
if [[ -z "$tag" ]]; then
echo "Failed to fetch latest release tag" >&2
exit 1
fi
release_url="https://github.com/${REPO}/releases/download/${tag}/${asset}"
fi
echo "$release_url"
}
main() {
local platform url
platform="$(detect_platform)"
echo "Detected platform: ${platform}"
url="$(get_download_url "$platform")"
echo "Downloading ${BIN_NAME} from ${url}..."
mkdir -p "$INSTALL_DIR"
curl -fsSL -o "${INSTALL_DIR}/${BIN_NAME}" "$url"
chmod +x "${INSTALL_DIR}/${BIN_NAME}"
echo "Installed ${BIN_NAME} to ${INSTALL_DIR}/${BIN_NAME}"
# Check PATH
case ":$PATH:" in
*":${INSTALL_DIR}:"*) ;;
*)
echo ""
echo "WARNING: ${INSTALL_DIR} is not in your PATH. Add it:"
echo " export PATH=\"${INSTALL_DIR}:\$PATH\""
;;
esac
echo ""
echo "Run 'af --version' to verify the installation."
}
main