-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·163 lines (136 loc) · 4.71 KB
/
install.sh
File metadata and controls
executable file
·163 lines (136 loc) · 4.71 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
# Installation script for Codebase Interface CLI
# Usage: curl -sSL https://raw.githubusercontent.com/codebase-interface/cli/main/install.sh | bash
set -e
# Default installation directory
INSTALL_DIR="/usr/local/bin"
BINARY_NAME="codebase-interface"
REPO_OWNER="codebase-interface"
REPO_NAME="cli"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Detect OS and architecture
detect_platform() {
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
case $OS in
linux)
OS="linux"
;;
darwin)
OS="darwin"
;;
msys*|mingw*|cygwin*)
OS="windows"
;;
*)
echo -e "${RED}Error: Unsupported operating system: $OS${NC}"
exit 1
;;
esac
case $ARCH in
x86_64|amd64)
ARCH="amd64"
;;
arm64|aarch64)
ARCH="arm64"
;;
*)
echo -e "${RED}Error: Unsupported architecture: $ARCH${NC}"
exit 1
;;
esac
}
# Get the latest release version
get_latest_version() {
echo -e "${BLUE}Fetching latest release...${NC}"
LATEST_VERSION=$(curl -s "https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "$LATEST_VERSION" ]; then
echo -e "${RED}Error: Could not fetch latest version${NC}"
exit 1
fi
echo -e "${GREEN}Latest version: $LATEST_VERSION${NC}"
}
# Download and install binary
install_binary() {
if [ "$OS" = "windows" ]; then
BINARY_NAME="${BINARY_NAME}.exe"
fi
DOWNLOAD_URL="https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/${LATEST_VERSION}/${BINARY_NAME}-${OS}-${ARCH}"
if [ "$OS" = "windows" ]; then
DOWNLOAD_URL="${DOWNLOAD_URL}.exe"
fi
echo -e "${BLUE}Downloading from: $DOWNLOAD_URL${NC}"
# Create temporary file
TMP_FILE=$(mktemp)
# Download binary
if ! curl -L "$DOWNLOAD_URL" -o "$TMP_FILE"; then
echo -e "${RED}Error: Failed to download binary${NC}"
exit 1
fi
# Check if we can write to install directory
if [ ! -w "$INSTALL_DIR" ]; then
echo -e "${YELLOW}Warning: Cannot write to $INSTALL_DIR, trying with sudo...${NC}"
SUDO="sudo"
else
SUDO=""
fi
# Install binary
$SUDO mv "$TMP_FILE" "$INSTALL_DIR/$BINARY_NAME"
$SUDO chmod +x "$INSTALL_DIR/$BINARY_NAME"
# Create symlink for short alias
if [ "$OS" != "windows" ]; then
$SUDO ln -sf "$INSTALL_DIR/$BINARY_NAME" "$INSTALL_DIR/cbi"
echo -e "${GREEN}Created alias: cbi -> $BINARY_NAME${NC}"
fi
echo -e "${GREEN}✅ Successfully installed $BINARY_NAME to $INSTALL_DIR${NC}"
}
# Verify installation
verify_installation() {
if command -v "$BINARY_NAME" >/dev/null 2>&1; then
VERSION_OUTPUT=$("$BINARY_NAME" version 2>/dev/null || echo "version command not available")
echo -e "${GREEN}✅ Installation verified${NC}"
echo -e "${BLUE}Run '$BINARY_NAME --help' or 'cbi --help' to get started!${NC}"
if [ "$VERSION_OUTPUT" != "version command not available" ]; then
echo -e "${BLUE}Installed version: $VERSION_OUTPUT${NC}"
fi
else
echo -e "${YELLOW}Warning: $BINARY_NAME not found in PATH${NC}"
echo -e "${YELLOW}You may need to add $INSTALL_DIR to your PATH${NC}"
echo -e "${YELLOW}Or run: export PATH=\"$INSTALL_DIR:\$PATH\"${NC}"
fi
}
# Main installation flow
main() {
echo -e "${BLUE}🚀 Installing Codebase Interface CLI...${NC}"
echo
# Allow custom install directory
if [ -n "$1" ]; then
INSTALL_DIR="$1"
echo -e "${BLUE}Custom install directory: $INSTALL_DIR${NC}"
fi
# Create install directory if it doesn't exist
if [ ! -d "$INSTALL_DIR" ]; then
echo -e "${BLUE}Creating install directory: $INSTALL_DIR${NC}"
mkdir -p "$INSTALL_DIR" 2>/dev/null || {
echo -e "${YELLOW}Creating directory with sudo...${NC}"
sudo mkdir -p "$INSTALL_DIR"
}
fi
detect_platform
echo -e "${BLUE}Detected platform: $OS-$ARCH${NC}"
get_latest_version
install_binary
verify_installation
echo
echo -e "${GREEN}🎉 Installation complete!${NC}"
echo -e "${BLUE}Quick start:${NC}"
echo -e " $BINARY_NAME init-config basic # Create a configuration file"
echo -e " $BINARY_NAME validate # Validate your codebase"
echo -e " $BINARY_NAME --help # See all available commands"
}
# Run main function with all arguments
main "$@"