-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
218 lines (183 loc) · 5.02 KB
/
install.sh
File metadata and controls
218 lines (183 loc) · 5.02 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
#!/bin/bash
set -e
# Ngent Installer Script
# Usage: curl -sSL https://raw.githubusercontent.com/beyond5959/ngent/master/install.sh | bash
REPO="beyond5959/ngent"
BINARY_NAME="ngent"
INSTALL_DIR="${INSTALL_DIR:-/usr/local/bin}"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Print functions
info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Detect OS
detect_os() {
local os
os=$(uname -s | tr '[:upper:]' '[:lower:]')
case "$os" in
linux)
echo "linux"
;;
darwin)
echo "darwin"
;;
mingw*|msys*|cygwin*)
echo "windows"
;;
*)
error "Unsupported operating system: $os"
exit 1
;;
esac
}
# Detect architecture
detect_arch() {
local arch
arch=$(uname -m)
case "$arch" in
x86_64|amd64)
echo "x86_64"
;;
arm64|aarch64)
echo "aarch64"
;;
*)
error "Unsupported architecture: $arch"
exit 1
;;
esac
}
# Get latest release version
get_latest_version() {
local version
version=$(curl -s "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "$version" ]; then
error "Failed to get latest version"
exit 1
fi
echo "$version"
}
# Download and install
download_and_install() {
local version="$1"
local os="$2"
local arch="$3"
local suffix="${arch}-${os}"
local filename
local extract_cmd
if [ "$os" = "windows" ]; then
filename="${BINARY_NAME}-${version}-${suffix}.zip"
extract_cmd="unzip -o"
else
filename="${BINARY_NAME}-${version}-${suffix}.tar.gz"
extract_cmd="tar -xzf"
fi
local download_url="https://github.com/${REPO}/releases/download/${version}/${filename}"
local tmp_dir
tmp_dir=$(mktemp -d)
info "Downloading ${BINARY_NAME} ${version} for ${os}/${arch}..."
info "URL: ${download_url}"
if ! curl -sSL -o "${tmp_dir}/${filename}" "$download_url"; then
error "Failed to download ${filename}"
rm -rf "$tmp_dir"
exit 1
fi
info "Extracting..."
cd "$tmp_dir"
if ! $extract_cmd "$filename" 2>/dev/null; then
error "Failed to extract ${filename}"
rm -rf "$tmp_dir"
exit 1
fi
# Check if binary exists
if [ ! -f "$BINARY_NAME" ]; then
error "Binary not found in archive"
rm -rf "$tmp_dir"
exit 1
fi
# Make executable
chmod +x "$BINARY_NAME"
# Install
info "Installing to ${INSTALL_DIR}..."
# Check if we need sudo
if [ -w "$INSTALL_DIR" ]; then
mv "$BINARY_NAME" "${INSTALL_DIR}/"
else
warn "Need sudo permission to install to ${INSTALL_DIR}"
if command -v sudo >/dev/null 2>&1; then
sudo mv "$BINARY_NAME" "${INSTALL_DIR}/"
else
error "sudo not found and cannot write to ${INSTALL_DIR}"
error "Please run with sudo or set INSTALL_DIR to a writable directory"
rm -rf "$tmp_dir"
exit 1
fi
fi
# Cleanup
rm -rf "$tmp_dir"
success "${BINARY_NAME} ${version} installed successfully!"
}
# Verify installation
verify_installation() {
if command -v "$BINARY_NAME" >/dev/null 2>&1; then
local version
version=$($BINARY_NAME --version 2>/dev/null || echo "unknown")
success "Installation verified: ${BINARY_NAME} is available in PATH"
info "Version: ${version}"
else
warn "${BINARY_NAME} is installed but not in your PATH"
info "Add ${INSTALL_DIR} to your PATH or run: export PATH=\"${INSTALL_DIR}:\$PATH\""
fi
}
# Main
main() {
echo "========================================"
echo " ${BINARY_NAME} Installer"
echo "========================================"
echo ""
# Check for required commands
if ! command -v curl >/dev/null 2>&1; then
error "curl is required but not installed"
exit 1
fi
# Detect system
local os
local arch
os=$(detect_os)
arch=$(detect_arch)
info "Detected OS: ${os}"
info "Detected Architecture: ${arch}"
# Check if Windows
if [ "$os" = "windows" ]; then
warn "Windows detected. Please download the .zip file manually from:"
info "https://github.com/${REPO}/releases"
exit 0
fi
# Get version
local version
version=$(get_latest_version)
info "Latest version: ${version}"
# Download and install
download_and_install "$version" "$os" "$arch"
# Verify
verify_installation
echo ""
success "Installation complete!"
info "Run '${BINARY_NAME} --help' to get started"
}
# Run main function
main "$@"