-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinstall.sh
More file actions
220 lines (184 loc) · 6.02 KB
/
install.sh
File metadata and controls
220 lines (184 loc) · 6.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
219
220
#!/usr/bin/env bash
# geol Installation Script
# Usage: curl -fsSL https://raw.githubusercontent.com/opt-nc/geol/main/install.sh | bash
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# GitHub repository
REPO="opt-nc/geol"
BINARY_NAME="geol"
# Print colored output
print_info() {
echo -e "${BLUE}ℹ${NC} $1"
}
print_success() {
echo -e "${GREEN}✓${NC} $1"
}
print_error() {
echo -e "${RED}✗${NC} $1"
}
print_warning() {
echo -e "${YELLOW}⚠${NC} $1"
}
# Detect OS
detect_os() {
case "$(uname -s)" in
Linux*) OS="Linux";;
Darwin*) OS="Darwin";;
CYGWIN*|MINGW*|MSYS*) OS="Windows";;
FreeBSD*) OS="FreeBSD";;
OpenBSD*) OS="OpenBSD";;
*) OS="UNKNOWN";;
esac
echo "$OS"
}
# Detect architecture
detect_arch() {
ARCH=$(uname -m)
case $ARCH in
x86_64) echo "x86_64";;
amd64) echo "x86_64";;
arm64) echo "arm64";;
aarch64) echo "arm64";;
armv7l) echo "armv7";;
armv6l) echo "armv6";;
i386|i686) echo "i386";;
*) echo "unknown";;
esac
}
# Get latest release version from GitHub API
get_latest_version() {
if command -v curl &> /dev/null; then
VERSION=$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
elif command -v wget &> /dev/null; then
VERSION=$(wget -qO- "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
else
print_error "Neither curl nor wget found. Please install one of them."
exit 1
fi
if [ -z "$VERSION" ]; then
print_error "Failed to get latest version from GitHub"
exit 1
fi
echo "$VERSION"
}
# Download file
download_file() {
URL=$1
OUTPUT=$2
if command -v curl &> /dev/null; then
curl -fsSL "$URL" -o "$OUTPUT"
elif command -v wget &> /dev/null; then
wget -qO "$OUTPUT" "$URL"
else
print_error "Neither curl nor wget found"
exit 1
fi
}
# Main installation
main() {
print_info "Installing geol..."
echo ""
# Detect system
OS=$(detect_os)
ARCH=$(detect_arch)
print_info "Detected OS: $OS"
print_info "Detected Architecture: $ARCH"
# Check if OS/arch is supported
if [ "$OS" = "UNKNOWN" ] || [ "$ARCH" = "unknown" ]; then
print_error "Unsupported OS or architecture: $OS/$ARCH"
exit 1
fi
if [ "$OS" = "Windows" ]; then
print_error "Windows is not supported by this script. Please download the binary manually from:"
print_info "https://github.com/${REPO}/releases/latest"
exit 1
fi
# Get latest version
print_info "Fetching latest release..."
VERSION=$(get_latest_version)
print_success "Latest version: $VERSION"
# Fetch asset list from GitHub API
print_info "Fetching asset list for release $VERSION..."
ASSET_API_URL="https://api.github.com/repos/${REPO}/releases/tags/${VERSION}"
if command -v curl &> /dev/null; then
ASSET_LIST=$(curl -fsSL "$ASSET_API_URL")
elif command -v wget &> /dev/null; then
ASSET_LIST=$(wget -qO- "$ASSET_API_URL")
else
print_error "Neither curl nor wget found. Please install one of them."
exit 1
fi
# Find correct asset name for OS/ARCH
ASSET_NAME=$(echo "$ASSET_LIST" | grep '"name":' | grep "$OS" | grep "$ARCH" | sed -E 's/.*"name": "([^"]+)".*/\1/' | head -n 1)
if [ -z "$ASSET_NAME" ]; then
print_error "Could not find a release asset for $OS/$ARCH."
print_info "Please check the release page: https://github.com/${REPO}/releases/tag/${VERSION}"
exit 1
fi
DOWNLOAD_URL="https://github.com/${REPO}/releases/download/${VERSION}/${ASSET_NAME}"
# Create temporary directory
TMP_DIR=$(mktemp -d)
trap 'rm -rf -- $TMP_DIR' EXIT
print_info "Downloading $ASSET_NAME..."
if ! download_file "$DOWNLOAD_URL" "$TMP_DIR/$ASSET_NAME"; then
print_error "Failed to download release"
print_info "URL: $DOWNLOAD_URL"
exit 1
fi
print_success "Downloaded successfully"
# Extract archive
print_info "Extracting archive..."
tar -xzf "$TMP_DIR/$ASSET_NAME" -C "$TMP_DIR"
print_success "Extracted successfully"
# Determine installation directory
if [ -w "/usr/local/bin" ]; then
INSTALL_DIR="/usr/local/bin"
elif [ -w "$HOME/.local/bin" ]; then
INSTALL_DIR="$HOME/.local/bin"
mkdir -p "$INSTALL_DIR"
else
INSTALL_DIR="$HOME/bin"
mkdir -p "$INSTALL_DIR"
fi
# Install binary
print_info "Installing to $INSTALL_DIR..."
if [ -w "$INSTALL_DIR" ]; then
mv "$TMP_DIR/$BINARY_NAME" "$INSTALL_DIR/$BINARY_NAME"
chmod +x "$INSTALL_DIR/$BINARY_NAME"
else
print_info "Need sudo permissions to install to $INSTALL_DIR"
sudo mv "$TMP_DIR/$BINARY_NAME" "$INSTALL_DIR/$BINARY_NAME"
sudo chmod +x "$INSTALL_DIR/$BINARY_NAME"
fi
print_success "Installed $BINARY_NAME to $INSTALL_DIR"
# Check if directory is in PATH
if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
print_warning "$INSTALL_DIR is not in your PATH"
echo ""
print_info "Add it to your PATH by adding this line to your shell config:"
print_info " export PATH=\"\$PATH:$INSTALL_DIR\""
echo ""
fi
# Verify installation
if command -v "$BINARY_NAME" &> /dev/null; then
print_success "Installation complete!"
echo ""
print_info "Run '$BINARY_NAME version' to verify"
echo ""
"$BINARY_NAME" version
else
print_success "Binary installed at $INSTALL_DIR/$BINARY_NAME"
print_info "You may need to restart your shell or run:"
print_info " source ~/.bashrc # or ~/.zshrc, etc."
fi
echo ""
print_info "To start geol, simply run: $BINARY_NAME"
print_info "For help, run: $BINARY_NAME help"
}
# Run main installation
main