-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
312 lines (261 loc) · 8.65 KB
/
Copy pathinstall.sh
File metadata and controls
312 lines (261 loc) · 8.65 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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
#!/bin/bash
# PipeOps CLI Installation Script
# This script detects your platform and installs the latest version of PipeOps CLI
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# Configuration
REPO="PipeOpsHQ/pipeops-cli"
BINARY_NAME="pipeops"
INSTALL_DIR="${INSTALL_DIR:-/usr/local/bin}"
# Print colored output
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
print_header() {
echo -e "${PURPLE}"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🚀 PipeOps CLI Installer"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo -e "${NC}"
}
# Detect OS and architecture
detect_platform() {
local os=""
local arch=""
# Detect OS
case "$(uname -s)" in
Linux*) os="linux" ;;
Darwin*) os="darwin" ;;
CYGWIN*|MINGW*|MSYS*) os="windows" ;;
FreeBSD*) os="freebsd" ;;
*) print_error "Unsupported operating system: $(uname -s)" && exit 1 ;;
esac
# Detect architecture
case "$(uname -m)" in
x86_64|amd64) arch="x86_64" ;;
arm64|aarch64) arch="arm64" ;;
armv7*) arch="armv6" ;; # Map armv7 to armv6 (closest available)
armv6*) arch="armv6" ;;
i386|i686) arch="i386" ;;
*) print_error "Unsupported architecture: $(uname -m)" && exit 1 ;;
esac
# Format OS name for GitHub releases
case "$os" in
linux) os="Linux" ;;
darwin) os="Darwin" ;;
windows) os="Windows" ;;
freebsd) os="Freebsd" ;;
esac
PLATFORM="${os}"
ARCH="${arch}"
print_status "Detected platform: ${PLATFORM} ${ARCH}"
}
# Get the latest release version
get_latest_version() {
print_status "Fetching latest release information..."
local api_url="https://api.github.com/repos/${REPO}/releases/latest"
if command -v curl >/dev/null 2>&1; then
VERSION=$(curl -s "${api_url}" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
elif command -v wget >/dev/null 2>&1; then
VERSION=$(wget -qO- "${api_url}" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
else
print_error "Neither curl nor wget is available. Please install one of them."
exit 1
fi
if [ -z "$VERSION" ]; then
print_error "Failed to get latest version"
exit 1
fi
print_status "Latest version: ${VERSION}"
}
# Download and install binary
install_binary() {
local version="${VERSION#v}" # Remove 'v' prefix if present
local filename
local url
local temp_dir
# Construct filename based on platform
if [ "$PLATFORM" = "Windows" ]; then
filename="${BINARY_NAME}-cli_${PLATFORM}_${ARCH}.zip"
else
filename="${BINARY_NAME}-cli_${PLATFORM}_${ARCH}.tar.gz"
fi
url="https://github.com/${REPO}/releases/download/${VERSION}/${filename}"
print_status "Downloading ${filename}..."
# Create temporary directory
temp_dir=$(mktemp -d)
trap "rm -rf $temp_dir" EXIT
# Download the release
local download_path="${temp_dir}/${filename}"
if command -v curl >/dev/null 2>&1; then
if ! curl -fsSL -o "$download_path" "$url"; then
print_error "Failed to download from $url"
exit 1
fi
elif command -v wget >/dev/null 2>&1; then
if ! wget -q -O "$download_path" "$url"; then
print_error "Failed to download from $url"
exit 1
fi
fi
print_status "Extracting binary..."
# Extract the binary
cd "$temp_dir"
if [ "$PLATFORM" = "Windows" ]; then
if command -v unzip >/dev/null 2>&1; then
unzip -q "$filename"
else
print_error "unzip is required to extract Windows archives"
exit 1
fi
else
if command -v tar >/dev/null 2>&1; then
tar -xzf "$filename"
else
print_error "tar is required to extract archives"
exit 1
fi
fi
# Find the binary
local binary_path=""
if [ "$PLATFORM" = "Windows" ]; then
binary_path="${BINARY_NAME}.exe"
else
binary_path="${BINARY_NAME}"
fi
if [ ! -f "$binary_path" ]; then
print_error "Binary not found in extracted archive"
exit 1
fi
print_status "Installing to ${INSTALL_DIR}..."
# Create install directory if it doesn't exist
if [ ! -d "$INSTALL_DIR" ]; then
if ! mkdir -p "$INSTALL_DIR" 2>/dev/null; then
print_warning "Cannot create $INSTALL_DIR. Trying with sudo..."
sudo mkdir -p "$INSTALL_DIR"
fi
fi
# Install binary
local install_path="${INSTALL_DIR}/${BINARY_NAME}"
if [ "$PLATFORM" = "Windows" ]; then
install_path="${INSTALL_DIR}/${BINARY_NAME}.exe"
fi
if ! cp "$binary_path" "$install_path" 2>/dev/null; then
print_warning "Cannot write to $INSTALL_DIR. Trying with sudo..."
sudo cp "$binary_path" "$install_path"
fi
# Make executable
if [ "$PLATFORM" != "Windows" ]; then
if ! chmod +x "$install_path" 2>/dev/null; then
sudo chmod +x "$install_path"
fi
fi
print_success "PipeOps CLI installed successfully!"
}
# Verify installation
verify_installation() {
print_status "Verifying installation..."
if command -v "$BINARY_NAME" >/dev/null 2>&1; then
local installed_version
installed_version=$("$BINARY_NAME" version 2>/dev/null | head -n1 || echo "unknown")
print_success "Installation verified: $installed_version"
return 0
else
print_warning "Binary installed but not found in PATH."
print_warning "You may need to add ${INSTALL_DIR} to your PATH."
print_warning "Add this to your shell profile (.bashrc, .zshrc, etc.):"
echo " export PATH=\"${INSTALL_DIR}:\$PATH\""
return 1
fi
}
# Print post-installation information
print_completion() {
echo ""
echo -e "${GREEN}🎉 Installation Complete!${NC}"
echo ""
echo -e "${CYAN}Getting Started:${NC}"
echo " 1. Authenticate with PipeOps:"
echo " ${BINARY_NAME} login"
echo ""
echo " 2. List your projects:"
echo " ${BINARY_NAME} project list"
echo ""
echo " 3. Get help:"
echo " ${BINARY_NAME} --help"
echo ""
echo -e "${CYAN}Documentation:${NC}"
echo " 🌐 Website: https://pipeops.io"
echo " 📖 Docs: https://docs.pipeops.io"
echo " 💬 Discord: https://discord.gg/pipeops"
echo " 🐙 GitHub: https://github.com/${REPO}"
echo ""
}
# Main installation function
main() {
print_header
# Check if running as root
if [ "$EUID" -eq 0 ]; then
print_warning "Running as root. Consider running as a regular user."
fi
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
--install-dir)
INSTALL_DIR="$2"
shift 2
;;
--version)
VERSION="$2"
shift 2
;;
-h|--help)
echo "Usage: $0 [options]"
echo ""
echo "Options:"
echo " --install-dir DIR Install to specific directory (default: /usr/local/bin)"
echo " --version VERSION Install specific version (default: latest)"
echo " -h, --help Show this help message"
exit 0
;;
*)
print_error "Unknown option: $1"
exit 1
;;
esac
done
# Check for required tools
if ! command -v curl >/dev/null 2>&1 && ! command -v wget >/dev/null 2>&1; then
print_error "Either curl or wget is required for installation"
exit 1
fi
# Detect platform
detect_platform
# Get latest version if not specified
if [ -z "$VERSION" ]; then
get_latest_version
fi
# Install binary
install_binary
# Verify installation
verify_installation
# Print completion message
print_completion
}
# Run main function
main "$@"