-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·125 lines (101 loc) · 3.72 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·125 lines (101 loc) · 3.72 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
#!/bin/bash
set -euo pipefail
REPO="vericontext/snact"
INSTALL_DIR="/usr/local/bin"
BINARY="snact"
TMPDIR_INSTALL=""
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
info() { echo -e "${GREEN}==>${NC} $1"; }
warn() { echo -e "${YELLOW}==>${NC} $1"; }
error() { echo -e "${RED}error:${NC} $1" >&2; exit 1; }
# Detect platform
detect_platform() {
local os arch
case "$(uname -s)" in
Darwin) os="darwin" ;;
Linux) os="linux" ;;
*) error "Unsupported OS: $(uname -s). snact supports macOS and Linux." ;;
esac
case "$(uname -m)" in
x86_64|amd64) arch="x86_64" ;;
arm64|aarch64) arch="aarch64" ;;
*) error "Unsupported architecture: $(uname -m)" ;;
esac
echo "snact-${os}-${arch}"
}
# Get latest release tag
get_latest_version() {
local version
# Method 1: GitHub redirect (no API rate limit)
if command -v curl &>/dev/null; then
version=$(curl -fsSLI -o /dev/null -w '%{url_effective}' "https://github.com/${REPO}/releases/latest" | sed 's|.*/||')
fi
# Method 2: GitHub API (fallback, subject to rate limits)
if [ -z "$version" ] || [ "$version" = "latest" ]; then
local api_url="https://api.github.com/repos/${REPO}/releases/latest"
if command -v curl &>/dev/null; then
version=$(curl -fsSL "$api_url" 2>/dev/null | grep '"tag_name"' | head -1 | sed 's/.*"tag_name": *"//;s/".*//')
elif command -v wget &>/dev/null; then
version=$(wget -qO- "$api_url" 2>/dev/null | grep '"tag_name"' | head -1 | sed 's/.*"tag_name": *"//;s/".*//')
else
error "Neither curl nor wget found. Please install one of them."
fi
fi
if [ -z "$version" ]; then
error "Could not determine latest version. Check https://github.com/${REPO}/releases"
fi
echo "$version"
}
# Download and install
install() {
local platform version url
platform=$(detect_platform)
info "Detected platform: ${platform}"
# Use provided version or fetch latest
version="${SNACT_VERSION:-$(get_latest_version)}"
info "Installing snact ${version}"
url="https://github.com/${REPO}/releases/download/${version}/${platform}.tar.gz"
TMPDIR_INSTALL=$(mktemp -d)
trap 'rm -rf "$TMPDIR_INSTALL"' EXIT
info "Downloading ${url}"
if command -v curl &>/dev/null; then
curl -fsSL "$url" -o "${TMPDIR_INSTALL}/snact.tar.gz"
else
wget -qO "${TMPDIR_INSTALL}/snact.tar.gz" "$url"
fi
info "Extracting"
tar xzf "${TMPDIR_INSTALL}/snact.tar.gz" -C "$TMPDIR_INSTALL"
# Install binary
if [ -w "$INSTALL_DIR" ]; then
mv "${TMPDIR_INSTALL}/${BINARY}" "${INSTALL_DIR}/${BINARY}"
else
info "Installing to ${INSTALL_DIR} (requires sudo)"
sudo mv "${TMPDIR_INSTALL}/${BINARY}" "${INSTALL_DIR}/${BINARY}"
fi
chmod +x "${INSTALL_DIR}/${BINARY}"
info "snact ${version} installed to ${INSTALL_DIR}/${BINARY}"
echo ""
# Verify and show onboarding
if command -v snact &>/dev/null; then
echo " Quick start:"
echo ""
echo " snact browser launch --background # start Chrome"
echo " snact snap https://example.com # extract page elements"
echo " snact click @e1 # interact (auto re-snap)"
echo " snact browser stop # stop Chrome"
echo ""
echo " Project setup (optional):"
echo ""
echo " cd your-project && snact init # create .snact/ + AGENTS.md"
echo ""
echo " Full docs: snact --help"
else
warn "${INSTALL_DIR} is not in your PATH."
echo " Add it with: export PATH=\"${INSTALL_DIR}:\$PATH\""
fi
}
install