-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·279 lines (239 loc) · 9.17 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·279 lines (239 loc) · 9.17 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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#!/usr/bin/env bash
set -euo pipefail
GITHUB_REPO="glauberlima/claude-code-statusline"
GITHUB_API="https://api.github.com/repos/${GITHUB_REPO}/releases/latest"
GITHUB_DL_BASE="https://github.com/${GITHUB_REPO}/releases/download"
MAX_RETRIES=3
# ── Colors ─────────────────────────────────────────────────────────────────────
GREEN='\033[0;32m'
CYAN='\033[0;36m'
YELLOW='\033[0;33m'
RED='\033[0;31m'
MUTED='\033[0;90m'
NC='\033[0m'
# ── Output helpers ─────────────────────────────────────────────────────────────
success() { echo -e "${GREEN}✓${NC} $*"; }
info() { echo -e "${CYAN}→${NC} $*"; }
warn() { echo -e "${YELLOW}⚠${NC} $*" >&2; }
error() { echo -e "${RED}✗${NC} $*" >&2; }
muted() { echo -e "${MUTED} $*${NC}"; }
step() { echo -e "\n${CYAN}[$1/3]${NC} $2"; }
# ── Argument parsing ───────────────────────────────────────────────────────────
INSTALL_DIR="${HOME}/.claude"
VERSION_ARG=""
while [[ $# -gt 0 ]]; do
case "$1" in
--install-dir)
if [[ -z "${2:-}" ]]; then
error "--install-dir requires an argument."
exit 1
fi
INSTALL_DIR="$2"
shift 2
;;
--version)
if [[ -z "${2:-}" ]]; then
error "--version requires an argument."
exit 1
fi
VERSION_ARG="$2"
shift 2
;;
*) shift ;;
esac
done
BINARY_DEST="${INSTALL_DIR}/statusline"
SETTINGS_FILE="${HOME}/.claude/settings.json"
TOML_FILE="${INSTALL_DIR}/statusline.toml"
if [[ "${INSTALL_DIR}" == "${HOME}/.claude" ]]; then
COMMAND_PATH="~/.claude/statusline"
else
COMMAND_PATH="${BINARY_DEST}"
fi
# ── Header / footer ────────────────────────────────────────────────────────────
print_header() {
echo ""
echo "╔══════════════════════════════════════════════════╗"
echo "║ Claude Code Statusline - Installer ║"
echo "╚══════════════════════════════════════════════════╝"
echo ""
}
print_footer() {
echo ""
echo "╔══════════════════════════════════════════════════╗"
echo "║ Installation Complete! ║"
echo "╚══════════════════════════════════════════════════╝"
echo ""
echo "Installed: ${BINARY_DEST}"
echo ""
echo -e "Next step: ${CYAN}Restart Claude Code to see your new statusline${NC}"
echo ""
echo "To update, run the installation command again."
echo "To customize, edit ${TOML_FILE}"
echo ""
}
# ── Trap ───────────────────────────────────────────────────────────────────────
cleanup_on_error() {
echo ""
error "Installation failed. No changes made."
exit 1
}
# ── Dep version helper ─────────────────────────────────────────────────────────
dep_version() {
"$1" --version 2>/dev/null | head -1 | grep -oE '[0-9]+\.[0-9]+(\.[0-9]+)?' | head -1 || echo "found"
}
# ── Download with retries ──────────────────────────────────────────────────────
download_with_retries() {
local url="$1"
local dest="$2"
local attempt=1
while [[ ${attempt} -le ${MAX_RETRIES} ]]; do
if curl -fsSL --output "${dest}" "${url}" 2>/dev/null; then
return 0
fi
attempt=$((attempt + 1))
[[ ${attempt} -le ${MAX_RETRIES} ]] && sleep 1
done
return 1
}
# ── Main ───────────────────────────────────────────────────────────────────────
print_header
trap cleanup_on_error ERR INT TERM
# [1/3] Check dependencies
step 1 "Checking dependencies..."
missing_deps=()
for dep in claude curl; do
if ! command -v "${dep}" &>/dev/null; then
missing_deps+=("${dep}")
fi
done
if [[ ${#missing_deps[@]} -gt 0 ]]; then
error "Missing dependencies: ${missing_deps[*]}"
echo ""
if [[ " ${missing_deps[*]} " == *" claude "* ]]; then
echo -e "${CYAN}Claude Code CLI:${NC}"
echo " Visit https://claude.ai/code for installation instructions"
echo ""
fi
if [[ " ${missing_deps[*]} " == *" curl "* ]]; then
OS_NAME="$(uname -s)"
echo -e "${CYAN}curl:${NC}"
if [[ "${OS_NAME}" == "Darwin" ]]; then
echo " brew install curl"
elif command -v apt-get &>/dev/null; then
echo " sudo apt-get update && sudo apt-get install curl"
elif command -v dnf &>/dev/null; then
echo " sudo dnf install curl"
elif command -v yum &>/dev/null; then
echo " sudo yum install curl"
fi
echo ""
fi
echo "Installation aborted. Install dependencies and try again."
exit 1
fi
for dep in claude curl; do
success "${dep} $(dep_version "${dep}")"
done
# [2/3] Install binary
step 2 "Installing binary..."
OS="$(uname -s)"
case "${OS}" in
Darwin) ASSET="statusline-macos" ;;
Linux) ASSET="statusline-linux-x64" ;;
*)
error "Unsupported OS: only macOS and Linux are supported."
exit 1
;;
esac
if [[ -n "${VERSION_ARG}" ]]; then
TAG="${VERSION_ARG}"
else
TAG="$(curl -fsSL "${GITHUB_API}" 2>/dev/null | grep -o '"tag_name": *"[^"]*"' | grep -o '"[^"]*"$' | tr -d '"')"
if [[ -z "${TAG}" ]]; then
error "Could not determine latest release tag."
exit 1
fi
fi
info "Downloading statusline ${TAG} for ${ASSET}..."
if ! mkdir -p "${INSTALL_DIR}" 2>/dev/null; then
error "Cannot create install directory: ${INSTALL_DIR}"
exit 1
fi
DOWNLOAD_URL="${GITHUB_DL_BASE}/${TAG}/${ASSET}"
if ! download_with_retries "${DOWNLOAD_URL}" "${BINARY_DEST}"; then
error "Failed to download from ${DOWNLOAD_URL}"
info "Check your internet connection and try again"
exit 1
fi
if [[ ! -s "${BINARY_DEST}" ]]; then
error "Downloaded file is empty"
exit 1
fi
info "Verifying checksum..."
CHECKSUMS_URL="${GITHUB_DL_BASE}/${TAG}/checksums.txt"
CHECKSUMS_TMP="$(mktemp)"
if ! download_with_retries "${CHECKSUMS_URL}" "${CHECKSUMS_TMP}"; then
rm -f "${CHECKSUMS_TMP}"
error "Failed to download checksums.txt — cannot verify binary integrity"
rm -f "${BINARY_DEST}"
exit 1
fi
# Extract the expected hash for our specific asset
EXPECTED_LINE="$(grep " ${ASSET}$" "${CHECKSUMS_TMP}" || true)"
rm -f "${CHECKSUMS_TMP}"
if [[ -z "${EXPECTED_LINE}" ]]; then
error "Checksum not found for ${ASSET} in checksums.txt"
rm -f "${BINARY_DEST}"
exit 1
fi
# sha256sum on Linux, shasum on macOS
if command -v sha256sum &>/dev/null; then
ACTUAL_HASH="$(sha256sum "${BINARY_DEST}" | awk '{print $1}')"
else
ACTUAL_HASH="$(shasum -a 256 "${BINARY_DEST}" | awk '{print $1}')"
fi
EXPECTED_HASH="$(echo "${EXPECTED_LINE}" | awk '{print $1}')"
if [[ "${ACTUAL_HASH}" != "${EXPECTED_HASH}" ]]; then
error "Checksum mismatch for ${ASSET}"
error " expected: ${EXPECTED_HASH}"
error " got: ${ACTUAL_HASH}"
rm -f "${BINARY_DEST}"
exit 1
fi
success "Checksum verified"
if ! chmod +x "${BINARY_DEST}"; then
error "Failed to make binary executable"
exit 1
fi
if [[ -f "${TOML_FILE}" ]]; then
info "Config already exists, skipping: ${TOML_FILE}"
else
if ! "${BINARY_DEST}" --print-defaults > "${TOML_FILE}"; then
error "Failed to generate ${TOML_FILE}"
exit 1
fi
success "Created default config: ${TOML_FILE}"
fi
success "Binary installed to ${BINARY_DEST}"
# [3/3] Configure Claude Code
step 3 "Configuring Claude Code..."
set +e
"${BINARY_DEST}" --configure-settings "${SETTINGS_FILE}" "${COMMAND_PATH}"
CFG_EXIT=$?
set -e
if [[ ${CFG_EXIT} -ne 0 ]]; then
warn "Installation succeeded, but automatic configuration failed"
echo ""
echo "Please manually add to ~/.claude/settings.json:"
echo " {"
echo " \"statusLine\": {"
echo " \"type\": \"command\","
echo " \"command\": \"${COMMAND_PATH}\","
echo " \"padding\": 0"
echo " }"
echo " }"
echo ""
exit 2
fi
print_footer