-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·262 lines (226 loc) · 7.82 KB
/
install.sh
File metadata and controls
executable file
·262 lines (226 loc) · 7.82 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
#!/bin/sh
# Sango Install Script
# Usage: curl -fsSL https://raw.githubusercontent.com/raskell-io/sango/main/install.sh | sh
#
# This script detects your OS and architecture, downloads the appropriate
# pre-built binary, and installs it to /usr/local/bin (or ~/.local/bin if
# /usr/local/bin is not writable).
set -e
# Configuration
REPO="raskell-io/sango"
BINARY_NAME="sango"
INSTALL_DIR="/usr/local/bin"
FALLBACK_DIR="$HOME/.local/bin"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
MAGENTA='\033[0;35m'
NC='\033[0m' # No Color
# Print functions
info() {
printf "${BLUE}info${NC}: %s\n" "$1"
}
success() {
printf "${GREEN}success${NC}: %s\n" "$1"
}
warn() {
printf "${YELLOW}warning${NC}: %s\n" "$1"
}
error() {
printf "${RED}error${NC}: %s\n" "$1" >&2
exit 1
}
# Detect OS
detect_os() {
case "$(uname -s)" in
Linux*) echo "linux" ;;
Darwin*) echo "darwin" ;;
MINGW*|MSYS*|CYGWIN*) error "Windows is not yet supported. Please use WSL or build from source." ;;
*) error "Unsupported operating system: $(uname -s)" ;;
esac
}
# Detect architecture
detect_arch() {
case "$(uname -m)" in
x86_64|amd64) echo "amd64" ;;
aarch64|arm64) echo "arm64" ;;
*) error "Unsupported architecture: $(uname -m)" ;;
esac
}
# Check for required commands
check_dependencies() {
for cmd in curl tar; do
if ! command -v "$cmd" >/dev/null 2>&1; then
error "Required command not found: $cmd"
fi
done
}
# Get the latest release version
get_latest_version() {
curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" |
grep '"tag_name"' |
sed -E 's/.*"([^"]+)".*/\1/'
}
# Download and verify the binary
download_binary() {
local version="$1"
local os="$2"
local arch="$3"
local tmp_dir="$4"
# Build artifact name
local artifact="sango-${version}-${os}-${arch}.tar.gz"
local url="https://github.com/${REPO}/releases/download/${version}/${artifact}"
local checksum_url="${url}.sha256"
info "Downloading ${artifact}..."
# Download the tarball
if ! curl -fsSL -o "${tmp_dir}/${artifact}" "$url"; then
error "Failed to download ${artifact}. Check if the release exists for your platform."
fi
# Download and verify checksum
info "Verifying checksum..."
if curl -fsSL -o "${tmp_dir}/${artifact}.sha256" "$checksum_url" 2>/dev/null; then
cd "$tmp_dir"
if command -v sha256sum >/dev/null 2>&1; then
if ! sha256sum -c "${artifact}.sha256" >/dev/null 2>&1; then
error "Checksum verification failed!"
fi
elif command -v shasum >/dev/null 2>&1; then
expected=$(cat "${artifact}.sha256" | awk '{print $1}')
actual=$(shasum -a 256 "${artifact}" | awk '{print $1}')
if [ "$expected" != "$actual" ]; then
error "Checksum verification failed!"
fi
else
warn "No checksum tool available, skipping verification"
fi
cd - >/dev/null
else
warn "Checksum file not available, skipping verification"
fi
# Extract the tarball
info "Extracting..."
tar -xzf "${tmp_dir}/${artifact}" -C "$tmp_dir"
}
# Install the binary
install_binary() {
local tmp_dir="$1"
local install_dir="$2"
# Find the binary in the extracted files
local binary_path=""
if [ -f "${tmp_dir}/${BINARY_NAME}" ]; then
binary_path="${tmp_dir}/${BINARY_NAME}"
elif [ -f "${tmp_dir}/bin/${BINARY_NAME}" ]; then
binary_path="${tmp_dir}/bin/${BINARY_NAME}"
else
# Search for it
binary_path=$(find "$tmp_dir" -name "$BINARY_NAME" -type f | head -n 1)
fi
if [ -z "$binary_path" ] || [ ! -f "$binary_path" ]; then
error "Could not find ${BINARY_NAME} binary in the downloaded archive"
fi
# Check if we can write to the install directory
if [ ! -d "$install_dir" ]; then
if ! mkdir -p "$install_dir" 2>/dev/null; then
if [ "$install_dir" = "$INSTALL_DIR" ]; then
install_dir="$FALLBACK_DIR"
mkdir -p "$install_dir" 2>/dev/null || true
fi
fi
fi
# Try to install
if ! cp "$binary_path" "${install_dir}/${BINARY_NAME}" 2>/dev/null; then
if [ "$install_dir" = "$INSTALL_DIR" ]; then
# Try with sudo
if command -v sudo >/dev/null 2>&1; then
info "Installing to ${install_dir}/${BINARY_NAME} (requires sudo)..."
sudo cp "$binary_path" "${install_dir}/${BINARY_NAME}"
sudo chmod +x "${install_dir}/${BINARY_NAME}"
else
install_dir="$FALLBACK_DIR"
mkdir -p "$install_dir"
info "Installing to ${install_dir}/${BINARY_NAME}..."
cp "$binary_path" "${install_dir}/${BINARY_NAME}"
chmod +x "${install_dir}/${BINARY_NAME}"
fi
else
error "Failed to install to ${install_dir}"
fi
else
info "Installing to ${install_dir}/${BINARY_NAME}..."
chmod +x "${install_dir}/${BINARY_NAME}"
fi
# Return the install directory via a file to avoid stdout pollution
echo "$install_dir" > "${tmp_dir}/.install_dir"
}
# Check if directory is in PATH
check_path() {
local dir="$1"
case ":$PATH:" in
*":$dir:"*) return 0 ;;
*) return 1 ;;
esac
}
# Main installation
main() {
echo ""
printf "${MAGENTA}┌─────────────────────────────────────┐${NC}\n"
printf "${MAGENTA}│${NC} ${GREEN}Sango${NC} Installer ${MAGENTA}│${NC}\n"
printf "${MAGENTA}│${NC} Edge diagnostics CLI ${MAGENTA}│${NC}\n"
printf "${MAGENTA}└─────────────────────────────────────┘${NC}\n"
echo ""
# Check dependencies
check_dependencies
# Detect platform
local os=$(detect_os)
local arch=$(detect_arch)
info "Detected platform: ${os}-${arch}"
# Get latest version
info "Fetching latest release..."
local version=$(get_latest_version)
if [ -z "$version" ]; then
error "Could not determine latest version. Check if releases exist at https://github.com/${REPO}/releases"
fi
info "Latest version: ${version}"
# Create temporary directory
local tmp_dir=$(mktemp -d)
trap "rm -rf '$tmp_dir'" EXIT
# Download and extract
download_binary "$version" "$os" "$arch" "$tmp_dir"
# Install
install_binary "$tmp_dir" "$INSTALL_DIR"
local final_dir=$(cat "${tmp_dir}/.install_dir")
# Success!
echo ""
success "Sango ${version} installed successfully!"
echo ""
# Check if in PATH
if ! check_path "$final_dir"; then
warn "${final_dir} is not in your PATH"
echo ""
echo "Add it to your PATH by running:"
echo ""
if [ -f "$HOME/.zshrc" ]; then
printf " ${YELLOW}echo 'export PATH=\"%s:\$PATH\"' >> ~/.zshrc && source ~/.zshrc${NC}\n" "$final_dir"
elif [ -f "$HOME/.bashrc" ]; then
printf " ${YELLOW}echo 'export PATH=\"%s:\$PATH\"' >> ~/.bashrc && source ~/.bashrc${NC}\n" "$final_dir"
else
printf " ${YELLOW}export PATH=\"%s:\$PATH\"${NC}\n" "$final_dir"
fi
echo ""
fi
# Verify installation
if command -v sango >/dev/null 2>&1; then
info "Verifying installation..."
sango --version 2>/dev/null || true
else
echo "Run 'sango --help' to get started"
fi
echo ""
printf "Documentation: ${BLUE}https://sango.raskell.io${NC}\n"
printf "GitHub: ${BLUE}https://github.com/${REPO}${NC}\n"
echo ""
}
# Run main
main "$@"