-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·179 lines (142 loc) · 4.39 KB
/
install.sh
File metadata and controls
executable file
·179 lines (142 loc) · 4.39 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
#!/bin/sh
set -e
REPO="dcodesdev/clawd"
INSTALL_DIR="${CLAWD_INSTALL_DIR:-$HOME/.local/bin}"
BINARY_NAME="clawd"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
info() {
printf "${GREEN}[INFO]${NC} %s\n" "$1" >&2
}
warn() {
printf "${YELLOW}[WARN]${NC} %s\n" "$1" >&2
}
error() {
printf "${RED}[ERROR]${NC} %s\n" "$1" >&2
exit 1
}
detect_os() {
case "$(uname -s)" in
Darwin*) echo "darwin" ;;
Linux*) echo "linux" ;;
MINGW*|MSYS*|CYGWIN*) echo "windows" ;;
*) error "Unsupported operating system: $(uname -s)" ;;
esac
}
detect_arch() {
case "$(uname -m)" in
x86_64|amd64) echo "amd64" ;;
arm64|aarch64) echo "arm64" ;;
*) error "Unsupported architecture: $(uname -m)" ;;
esac
}
get_latest_version() {
curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" |
grep '"tag_name":' |
sed -E 's/.*"([^"]+)".*/\1/'
}
download_binary() {
local os="$1"
local arch="$2"
local version="$3"
local ext=""
if [ "$os" = "windows" ]; then
ext=".exe"
fi
local filename="${BINARY_NAME}-${os}-${arch}${ext}"
local url="https://github.com/${REPO}/releases/download/${version}/${filename}"
printf "${GREEN}[INFO]${NC} Downloading ${filename} (${version})...\n" >&2
local tmp_dir
tmp_dir=$(mktemp -d)
local tmp_file="${tmp_dir}/${BINARY_NAME}${ext}"
if ! curl -fsSL "$url" -o "$tmp_file"; then
rm -rf "$tmp_dir"
error "Failed to download from ${url}"
fi
# Verify checksum
local checksum_url="https://github.com/${REPO}/releases/download/${version}/checksums.sha256"
local checksums_file="${tmp_dir}/checksums.sha256"
if curl -fsSL "$checksum_url" -o "$checksums_file" 2>/dev/null; then
printf "${GREEN}[INFO]${NC} Verifying checksum...\n" >&2
local expected_checksum
expected_checksum=$(grep "$filename" "$checksums_file" | awk '{print $1}')
if [ -n "$expected_checksum" ]; then
local actual_checksum
if command -v sha256sum >/dev/null 2>&1; then
actual_checksum=$(sha256sum "$tmp_file" | awk '{print $1}')
elif command -v shasum >/dev/null 2>&1; then
actual_checksum=$(shasum -a 256 "$tmp_file" | awk '{print $1}')
else
warn "No sha256 tool found, skipping checksum verification"
actual_checksum="$expected_checksum"
fi
if [ "$expected_checksum" != "$actual_checksum" ]; then
rm -rf "$tmp_dir"
error "Checksum verification failed!"
fi
printf "${GREEN}[INFO]${NC} Checksum verified!\n" >&2
fi
else
warn "Could not download checksums, skipping verification"
fi
printf '%s' "$tmp_file"
}
install_binary() {
local tmp_file="$1"
local install_path="${INSTALL_DIR}/${BINARY_NAME}"
# Create install directory if it doesn't exist
if [ ! -d "$INSTALL_DIR" ]; then
mkdir -p "$INSTALL_DIR"
fi
chmod +x "$tmp_file"
if [ -w "$INSTALL_DIR" ]; then
mv "$tmp_file" "$install_path"
else
info "Installing to ${INSTALL_DIR} requires elevated permissions..."
sudo mv "$tmp_file" "$install_path"
fi
info "Installed to ${install_path}"
# Check if install directory is in PATH
case ":$PATH:" in
*":$INSTALL_DIR:"*) ;;
*)
warn "${INSTALL_DIR} is not in your PATH"
info "Add it by running: export PATH=\"\$PATH:${INSTALL_DIR}\""
;;
esac
}
main() {
info "Clawd Installer"
echo ""
local os
local arch
local version
os=$(detect_os)
arch=$(detect_arch)
info "Detected OS: ${os}"
info "Detected architecture: ${arch}"
# Check for version argument or get latest
if [ -n "$1" ]; then
version="$1"
else
info "Fetching latest version..."
version=$(get_latest_version)
fi
if [ -z "$version" ]; then
error "Could not determine version to install"
fi
info "Version: ${version}"
echo ""
local tmp_file
tmp_file=$(download_binary "$os" "$arch" "$version")
install_binary "$tmp_file"
# Cleanup temp directory
rm -rf "$(dirname "$tmp_file")"
echo ""
info "Installation complete!"
info "Run 'clawd --help' to get started"
}
main "$@"