-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
225 lines (195 loc) · 6.25 KB
/
Copy pathinstall.sh
File metadata and controls
225 lines (195 loc) · 6.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
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#!/usr/bin/env sh
set -e
REPO="graphit-labs/graphit-code"
BIN_NAME="graphit"
INSTALL_DIR="${HOME}/.local/bin"
VERSION="${VERSION:-}"
while [ "$#" -gt 0 ]; do
case "$1" in
--dir)
if [ -z "$2" ]; then
printf "Error: --dir requires a path argument\n" >&2
exit 1
fi
INSTALL_DIR="$2"
shift 2
;;
--dir=*)
INSTALL_DIR="${1#--dir=}"
shift
;;
--version)
if [ -z "$2" ]; then
printf "Error: --version requires a release tag argument\n" >&2
exit 1
fi
VERSION="$2"
shift 2
;;
--version=*)
VERSION="${1#--version=}"
shift
;;
--help|-h)
printf "Usage: install.sh [--dir <install-dir>] [--version <release-tag>]\n"
printf "\n"
printf " --dir <path> Install graphit to this directory (default: \$HOME/.local/bin)\n"
printf " --version <tag> Install this release tag instead of the latest (env: VERSION)\n"
exit 0
;;
*)
printf "Unknown option: %s\n" "$1" >&2
exit 1
;;
esac
done
if [ -t 1 ]; then
BOLD='\033[1m'
GREEN='\033[0;32m'
CYAN='\033[0;36m'
YELLOW='\033[0;33m'
RED='\033[0;31m'
RESET='\033[0m'
else
BOLD=''; GREEN=''; CYAN=''; YELLOW=''; RED=''; RESET=''
fi
info() { printf "${CYAN} →${RESET} %s\n" "$*"; }
success() { printf "${GREEN} ✓${RESET} %s\n" "$*"; }
warn() { printf "${YELLOW} ⚠${RESET} %s\n" "$*"; }
error() { printf "${RED} ✗${RESET} %s\n" "$*" >&2; exit 1; }
detect_platform() {
OS="$(uname -s)"
ARCH="$(uname -m)"
case "$OS" in
Linux)
case "$ARCH" in
x86_64) PLATFORM="linux-amd64" ;;
aarch64|arm64) PLATFORM="linux-arm64" ;;
*) error "Unsupported architecture: $ARCH" ;;
esac
;;
Darwin)
case "$ARCH" in
arm64) PLATFORM="darwin-arm64" ;;
x86_64) PLATFORM="darwin-amd64" ;;
*) error "Unsupported architecture: $ARCH" ;;
esac
;;
*) error "Unsupported OS: $OS. Please install manually from https://github.com/$REPO/releases" ;;
esac
}
check_deps() {
for cmd in curl tar; do
if ! command -v "$cmd" >/dev/null 2>&1; then
error "Required tool not found: $cmd. Please install it and retry."
fi
done
}
fetch_latest_version() {
LATEST_URL="https://api.github.com/repos/${REPO}/releases/latest"
VERSION="$(curl -fsSL "$LATEST_URL" | grep '"tag_name"' | sed 's/.*"tag_name": *"\([^"]*\)".*/\1/')"
if [ -z "$VERSION" ]; then
error "Could not determine latest version. Check your internet connection."
fi
}
check_path() {
_dir="$1"
case ":${PATH}:" in
*":${_dir}:"*) return 0 ;;
*) return 1 ;;
esac
}
printf "\n${BOLD}Graphit Code Installer${RESET}\n"
printf "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\n"
check_deps
detect_platform
if [ -n "$VERSION" ]; then
success "Pinned version: $VERSION"
else
info "Fetching latest version..."
fetch_latest_version
success "Latest version: $VERSION"
fi
ARCHIVE_NAME="${BIN_NAME}-${PLATFORM}.tar.gz"
BASE_URL="https://github.com/${REPO}/releases/download/${VERSION}"
ARCHIVE_URL="${BASE_URL}/${ARCHIVE_NAME}"
CHECKSUM_URL="${BASE_URL}/checksums.sha256"
TMP_DIR="$(mktemp -d)"
TMP_ARCHIVE="${TMP_DIR}/${ARCHIVE_NAME}"
TMP_CHECKSUM="${TMP_DIR}/checksums.sha256"
trap 'rm -rf "$TMP_DIR"' EXIT
info "Downloading ${ARCHIVE_NAME}..."
curl -fsSL --progress-bar "$ARCHIVE_URL" -o "$TMP_ARCHIVE" || \
error "Failed to download archive from: $ARCHIVE_URL"
success "Downloaded archive"
info "Downloading checksums..."
curl -fsSL "$CHECKSUM_URL" -o "$TMP_CHECKSUM" || \
error "Failed to download checksums from: $CHECKSUM_URL"
info "Verifying checksum..."
EXPECTED="$(grep "${ARCHIVE_NAME}" "$TMP_CHECKSUM" | awk '{print $1}')"
if [ -z "$EXPECTED" ]; then
error "Checksum for ${ARCHIVE_NAME} not found in checksums.sha256"
fi
if command -v sha256sum >/dev/null 2>&1; then
ACTUAL="$(sha256sum "$TMP_ARCHIVE" | awk '{print $1}')"
elif command -v shasum >/dev/null 2>&1; then
ACTUAL="$(shasum -a 256 "$TMP_ARCHIVE" | awk '{print $1}')"
else
warn "No sha256sum or shasum found — skipping checksum verification"
ACTUAL="$EXPECTED"
fi
if [ "$ACTUAL" != "$EXPECTED" ]; then
error "Checksum mismatch! Expected: $EXPECTED Got: $ACTUAL"
fi
success "Checksum verified"
info "Extracting archive..."
tar -xzf "$TMP_ARCHIVE" -C "$TMP_DIR"
TMP_BIN=""
for candidate in "${TMP_DIR}/${BIN_NAME}-${PLATFORM}" "${TMP_DIR}/${BIN_NAME}"; do
if [ -f "$candidate" ]; then
TMP_BIN="$candidate"
break
fi
done
if [ -z "$TMP_BIN" ]; then
error "Could not find binary in extracted archive"
fi
chmod +x "$TMP_BIN"
success "Archive extracted"
DLBIN="${INSTALL_DIR}/${BIN_NAME}"
info "Installing to ${DLBIN}..."
if [ ! -d "$INSTALL_DIR" ]; then
mkdir -p "$INSTALL_DIR" || sudo mkdir -p "$INSTALL_DIR"
fi
if [ -w "$INSTALL_DIR" ]; then
mv "$TMP_BIN" "$DLBIN"
else
sudo mv "$TMP_BIN" "$DLBIN"
fi
success "Installed to ${DLBIN}"
if [ "$(uname -s)" = "Darwin" ]; then
xattr -d com.apple.quarantine "$DLBIN" 2>/dev/null || true
codesign --sign - --force "$DLBIN" 2>/dev/null || true
fi
if command -v graphit >/dev/null 2>&1; then
INSTALLED_VER="$(graphit version 2>/dev/null | head -1 || echo "$VERSION")"
success "Verified: $INSTALLED_VER"
fi
printf "\n"
if ! check_path "$INSTALL_DIR"; then
warn "${INSTALL_DIR} is not in your PATH."
printf "\n"
printf " Add it by running one of the following (then restart your shell):\n\n"
printf " ${CYAN}bash/zsh:${RESET}\n"
printf " ${BOLD}echo 'export PATH=\"\$PATH:${INSTALL_DIR}\"' >> ~/.bashrc${RESET}\n"
printf " ${BOLD}echo 'export PATH=\"\$PATH:${INSTALL_DIR}\"' >> ~/.zshrc${RESET}\n\n"
printf " ${CYAN}fish:${RESET}\n"
printf " ${BOLD}fish_add_path ${INSTALL_DIR}${RESET}\n\n"
fi
printf "${BOLD}${GREEN}Installation complete!${RESET}\n\n"
printf " Next steps:\n\n"
printf " ${CYAN}1.${RESET} Run initial setup:\n"
printf " ${BOLD}graphit setup${RESET}\n\n"
printf " ${CYAN}2.${RESET} Initialize your project:\n"
printf " ${BOLD}graphit init --agent <antigravity|gemini|claude|cursor|kiro|codex|opencode|qwen|kimi|deepcode>${RESET}\n\n"
printf " ${CYAN}3.${RESET} Docs: ${BOLD}https://github.com/${REPO}/tree/main/docs${RESET}\n\n"