-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinstall.sh
More file actions
189 lines (156 loc) · 4.66 KB
/
install.sh
File metadata and controls
189 lines (156 loc) · 4.66 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
#!/bin/bash
# install.sh - ops0 installation script
set -e
REPO="ops0-ai/ops0-cli" # Replace with your GitHub username
BINARY_NAME="ops0"
INSTALL_DIR="/usr/local/bin"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
# Check if running as root for installation
check_permissions() {
if [[ $EUID -eq 0 ]]; then
INSTALL_DIR="/usr/local/bin"
SUDO=""
else
# Check if we can write to /usr/local/bin
if [[ -w "/usr/local/bin" ]]; then
SUDO=""
else
SUDO="sudo"
print_warning "Will need sudo access to install to $INSTALL_DIR"
fi
fi
}
# Detect OS and architecture
detect_platform() {
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
case $ARCH in
x86_64) ARCH="x86_64" ;;
arm64|aarch64) ARCH="arm64" ;;
i386|i686) ARCH="i386" ;;
armv7l) ARCH="armv7" ;;
*)
print_error "Unsupported architecture: $ARCH"
exit 1
;;
esac
case $OS in
darwin) OS="Darwin" ;;
linux) OS="Linux" ;;
mingw*|msys*|cygwin*) OS="Windows" ;;
*)
print_error "Unsupported OS: $OS"
exit 1
;;
esac
print_status "Detected platform: $OS/$ARCH"
}
# Get latest release from GitHub API
get_latest_release() {
print_status "Fetching latest release information..."
LATEST_RELEASE=$(curl -s "https://api.github.com/repos/$REPO/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "$LATEST_RELEASE" ]; then
print_error "Failed to get latest release information"
print_error "Please check if the repository exists: https://github.com/$REPO"
exit 1
fi
print_status "Latest release: $LATEST_RELEASE"
}
# Download and install binary
install_binary() {
# Construct download URL
if [ "$OS" = "Windows" ]; then
ARCHIVE_NAME="${BINARY_NAME}_${OS}_${ARCH}.zip"
else
ARCHIVE_NAME="${BINARY_NAME}_${OS}_${ARCH}.tar.gz"
fi
DOWNLOAD_URL="https://github.com/$REPO/releases/download/$LATEST_RELEASE/$ARCHIVE_NAME"
print_status "Downloading $BINARY_NAME $LATEST_RELEASE..."
print_status "URL: $DOWNLOAD_URL"
# Create temporary directory
TMP_DIR=$(mktemp -d)
cd "$TMP_DIR"
# Download archive
if ! curl -L "$DOWNLOAD_URL" -o "$ARCHIVE_NAME"; then
print_error "Failed to download $ARCHIVE_NAME"
print_error "Please check if the release exists: $DOWNLOAD_URL"
exit 1
fi
# Extract archive
print_status "Extracting archive..."
if [ "$OS" = "Windows" ]; then
unzip -q "$ARCHIVE_NAME"
else
tar -xzf "$ARCHIVE_NAME"
fi
# Install binary
if [ "$OS" = "Windows" ]; then
BINARY_NAME="${BINARY_NAME}.exe"
INSTALL_DIR="/usr/bin" # For Git Bash/WSL
fi
print_status "Installing $BINARY_NAME to $INSTALL_DIR..."
if ! $SUDO mv "$BINARY_NAME" "$INSTALL_DIR/"; then
print_error "Failed to install $BINARY_NAME to $INSTALL_DIR"
print_error "Please check permissions or install manually"
exit 1
fi
# Make executable (not needed on Windows)
if [ "$OS" != "Windows" ]; then
$SUDO chmod +x "$INSTALL_DIR/$BINARY_NAME"
fi
# Cleanup
cd /
rm -rf "$TMP_DIR"
}
# Verify installation
verify_installation() {
print_status "Verifying installation..."
if command -v $BINARY_NAME >/dev/null 2>&1; then
VERSION_OUTPUT=$($BINARY_NAME --version 2>/dev/null || echo "version info not available")
print_success "$BINARY_NAME installed successfully!"
print_success "Location: $(which $BINARY_NAME)"
print_success "Version: $VERSION_OUTPUT"
else
print_error "Installation verification failed"
print_error "$BINARY_NAME not found in PATH"
exit 1
fi
}
# Main installation flow
main() {
echo "🚀 ops0 Installation Script"
echo "============================"
check_permissions
detect_platform
get_latest_release
install_binary
verify_installation
echo ""
print_success "Installation complete! 🎉"
echo ""
echo "Get started with:"
echo " $BINARY_NAME -m \"i want to plan my iac code\""
echo ""
echo "For more examples and documentation:"
echo " https://github.com/$REPO"
echo ""
}
# Run main function
main "$@"