-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
144 lines (122 loc) · 4.06 KB
/
Copy pathinstall.sh
File metadata and controls
144 lines (122 loc) · 4.06 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
#!/bin/bash
set -e
# Detect OS and architecture
detect_os() {
case "$(uname -s)" in
Darwin*) echo "darwin" ;;
Linux*) echo "linux" ;;
MINGW64*|MSYS*|CYGWIN*) echo "windows" ;;
*) echo "unknown" ;;
esac
}
detect_arch() {
case "$(uname -m)" in
x86_64|amd64) echo "amd64" ;;
arm64|aarch64) echo "arm64" ;;
*) echo "unknown" ;;
esac
}
OS=$(detect_os)
ARCH=$(detect_arch)
if [ "$OS" = "unknown" ] || [ "$ARCH" = "unknown" ]; then
echo "Unsupported operating system or architecture"
exit 1
fi
# Set installation directories based on OS
if [ "$OS" = "windows" ]; then
INSTALL_DIR="$USERPROFILE/.base"
BIN_DIR="$USERPROFILE/bin"
BINARY_NAME="base.exe"
else
INSTALL_DIR="$HOME/.base"
BIN_DIR="/usr/local/bin"
BINARY_NAME="base"
fi
# Create installation directories
mkdir -p "$INSTALL_DIR"
mkdir -p "$BIN_DIR" 2>/dev/null || {
echo "Error: Unable to create $BIN_DIR directory. Please run with sudo:"
echo "curl -sSL https://raw.githubusercontent.com/base-go/cmd/main/install.sh | sudo bash"
exit 1
}
echo "Installing Base CLI..."
echo "OS: $OS"
echo "Architecture: $ARCH"
# Get the latest release version
echo "Fetching latest release information..."
API_RESPONSE=$(curl -s https://api.github.com/repos/base-go/cmd/releases/latest)
if [ $? -ne 0 ]; then
echo "Error: Failed to fetch release information"
exit 1
fi
LATEST_RELEASE=$(echo "$API_RESPONSE" | grep '"tag_name"' | head -n1 | cut -d '"' -f 4)
if [ -z "$LATEST_RELEASE" ]; then
echo "Error: Could not determine latest version"
echo "API Response debug info:"
echo "$API_RESPONSE" | head -n 10
echo "Please check if the repository exists and has releases"
echo "Repository: https://github.com/base-go/cmd"
exit 1
fi
echo "Latest version: $LATEST_RELEASE"
# Download the appropriate binary
DOWNLOAD_URL="https://github.com/base-go/cmd/releases/download/$LATEST_RELEASE/base_${OS}_${ARCH}.tar.gz"
if [ "$OS" = "windows" ]; then
DOWNLOAD_URL="https://github.com/base-go/cmd/releases/download/$LATEST_RELEASE/base_${OS}_${ARCH}.zip"
fi
echo "Downloading from: $DOWNLOAD_URL"
TMP_DIR=$(mktemp -d)
cd "$TMP_DIR"
if [ "$OS" = "windows" ]; then
curl -sL "$DOWNLOAD_URL" -o base.zip
unzip base.zip
else
curl -sL "$DOWNLOAD_URL" | tar xz
fi
# Install the binary
mv "$BINARY_NAME" "$INSTALL_DIR/"
chmod +x "$INSTALL_DIR/$BINARY_NAME"
# Create symlink
if [ "$OS" = "windows" ]; then
# On Windows, copy to bin directory
cp "$INSTALL_DIR/$BINARY_NAME" "$BIN_DIR/"
else
# On Unix systems, create symlink with sudo
echo "Creating symlink in $BIN_DIR (requires sudo)..."
if ! sudo ln -sf "$INSTALL_DIR/$BINARY_NAME" "$BIN_DIR/$BINARY_NAME"; then
echo "Error: Failed to create symlink. Please run the install script with sudo:"
echo "curl -sSL https://raw.githubusercontent.com/base-go/cmd/main/install.sh | sudo bash"
exit 1
fi
fi
# Cleanup
cd - > /dev/null
rm -rf "$TMP_DIR"
echo "Base CLI has been installed successfully!"
# Install Go dependencies
echo ""
echo "Installing Base CLI dependencies..."
# Check if Go is installed
if command -v go >/dev/null 2>&1; then
echo "Installing swag (API documentation generator)..."
if ! go install github.com/swaggo/swag/cmd/swag@latest 2>/dev/null; then
echo "Warning: Failed to install swag. You can install it manually later with:"
echo " go install github.com/swaggo/swag/cmd/swag@latest"
else
echo "✓ swag installed successfully"
fi
else
echo "Warning: Go is not installed or not in PATH."
echo "Base CLI dependencies (swag) will be installed automatically when needed."
echo "To install Go, visit: https://golang.org/dl/"
fi
echo ""
echo "Run 'base --help' to get started"
# Add to PATH for Windows if needed
if [ "$OS" = "windows" ]; then
if [[ ":$PATH:" != *":$BIN_DIR:"* ]]; then
echo "Please add $BIN_DIR to your PATH to use the 'base' command"
echo "You can do this by running:"
echo " setx PATH \"%PATH%;$BIN_DIR\""
fi
fi