-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·138 lines (113 loc) · 3.25 KB
/
install.sh
File metadata and controls
executable file
·138 lines (113 loc) · 3.25 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
#!/usr/bin/env bash
set -euo pipefail
# Apollo CLI Installer
# https://github.com/dipankar/apollo-io-cli
BINARY_NAME="apollo"
INSTALL_DIR="${INSTALL_DIR:-/usr/local/bin}"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
error() {
echo -e "${RED}[ERROR]${NC} $1"
exit 1
}
# Check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Check for required dependencies
check_dependencies() {
info "Checking dependencies..."
if ! command_exists cargo; then
error "Rust/Cargo is not installed. Please install Rust first:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh"
fi
info "Found cargo: $(cargo --version)"
}
# Build the project
build_project() {
info "Building Apollo CLI in release mode..."
cargo build --release
if [[ ! -f "target/release/${BINARY_NAME}" ]]; then
error "Build failed: binary not found at target/release/${BINARY_NAME}"
fi
info "Build successful!"
}
# Install the binary
install_binary() {
local target_path="${INSTALL_DIR}/${BINARY_NAME}"
info "Installing ${BINARY_NAME} to ${INSTALL_DIR}..."
# Create install directory if it doesn't exist
if [[ ! -d "${INSTALL_DIR}" ]]; then
if [[ "${INSTALL_DIR}" == /usr/local/bin ]]; then
sudo mkdir -p "${INSTALL_DIR}"
else
mkdir -p "${INSTALL_DIR}"
fi
fi
# Copy binary to install directory
if [[ "${INSTALL_DIR}" == /usr/local/bin ]] || [[ ! -w "${INSTALL_DIR}" ]]; then
sudo cp "target/release/${BINARY_NAME}" "${target_path}"
sudo chmod +x "${target_path}"
else
cp "target/release/${BINARY_NAME}" "${target_path}"
chmod +x "${target_path}"
fi
info "Installed ${BINARY_NAME} to ${target_path}"
}
# Verify installation
verify_installation() {
if command_exists "${BINARY_NAME}"; then
info "Installation verified! You can now use '${BINARY_NAME}'"
echo ""
"${BINARY_NAME}" --version 2>/dev/null || "${BINARY_NAME}" --help | head -5
else
warn "${BINARY_NAME} is installed but not in your PATH"
warn "Add ${INSTALL_DIR} to your PATH:"
echo ""
echo " export PATH=\"${INSTALL_DIR}:\$PATH\""
echo ""
echo "Add this to your ~/.bashrc or ~/.zshrc to make it permanent."
fi
}
# Print usage instructions
print_usage() {
echo ""
info "Quick Start:"
echo " 1. Set your API key:"
echo " export APOLLO_API_KEY=\"your_api_key_here\""
echo ""
echo " 2. Try a command:"
echo " ${BINARY_NAME} --help"
echo " ${BINARY_NAME} operations"
echo ""
}
# Main installation flow
main() {
echo ""
echo "======================================"
echo " Apollo CLI Installer"
echo "======================================"
echo ""
# Allow custom install directory
if [[ -n "${1:-}" ]]; then
INSTALL_DIR="$1"
info "Using custom install directory: ${INSTALL_DIR}"
fi
check_dependencies
build_project
install_binary
verify_installation
print_usage
echo ""
info "Installation complete!"
}
main "$@"