-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·120 lines (101 loc) · 2.96 KB
/
install.sh
File metadata and controls
executable file
·120 lines (101 loc) · 2.96 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
#!/bin/bash
set -e
# Craft CLI Installer
# Usage: curl -sSL https://raw.githubusercontent.com/nerveband/craft-cli/main/install.sh | bash
REPO="nerveband/craft-cli"
BINARY_NAME="craft"
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
}
# Detect OS
detect_os() {
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
case "$OS" in
darwin) OS="Darwin" ;;
linux) OS="Linux" ;;
mingw*|msys*|cygwin*) OS="Windows" ;;
*) error "Unsupported operating system: $OS" ;;
esac
}
# Detect architecture
detect_arch() {
ARCH=$(uname -m)
case "$ARCH" in
x86_64|amd64) ARCH="x86_64" ;;
arm64|aarch64) ARCH="arm64" ;;
*) error "Unsupported architecture: $ARCH" ;;
esac
}
# Get latest release version from GitHub
get_latest_version() {
LATEST_VERSION=$(curl -sS "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "$LATEST_VERSION" ]; then
error "Failed to get latest version. Check your internet connection."
fi
}
# Download and install
install() {
detect_os
detect_arch
get_latest_version
info "Installing Craft CLI ${LATEST_VERSION} for ${OS}/${ARCH}..."
# Construct download URL
if [ "$OS" = "Windows" ]; then
ARCHIVE_NAME="craft-cli_${OS}_${ARCH}.zip"
else
ARCHIVE_NAME="craft-cli_${OS}_${ARCH}.tar.gz"
fi
DOWNLOAD_URL="https://github.com/${REPO}/releases/download/${LATEST_VERSION}/${ARCHIVE_NAME}"
# Create temp directory
TMP_DIR=$(mktemp -d)
trap "rm -rf $TMP_DIR" EXIT
info "Downloading from ${DOWNLOAD_URL}..."
if ! curl -sSL "$DOWNLOAD_URL" -o "${TMP_DIR}/${ARCHIVE_NAME}"; then
error "Failed to download. Release may not exist yet."
fi
# Extract
info "Extracting..."
cd "$TMP_DIR"
if [ "$OS" = "Windows" ]; then
unzip -q "$ARCHIVE_NAME"
else
tar -xzf "$ARCHIVE_NAME"
fi
# Install
if [ -w "$INSTALL_DIR" ]; then
mv "$BINARY_NAME" "$INSTALL_DIR/"
else
info "Installing to ${INSTALL_DIR} (requires sudo)..."
sudo mv "$BINARY_NAME" "$INSTALL_DIR/"
fi
# Verify installation
if command -v "$BINARY_NAME" &> /dev/null; then
info "Successfully installed Craft CLI!"
echo ""
"$BINARY_NAME" version
echo ""
info "Run 'craft --help' to get started"
info "Run 'craft upgrade' to update to the latest version"
else
warn "Installation complete, but '$BINARY_NAME' not found in PATH"
warn "You may need to add ${INSTALL_DIR} to your PATH"
echo ""
echo "Add this to your shell profile:"
echo " export PATH=\"${INSTALL_DIR}:\$PATH\""
fi
}
# Run installer
install