-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprerequisites.sh
More file actions
executable file
·222 lines (202 loc) · 6.45 KB
/
prerequisites.sh
File metadata and controls
executable file
·222 lines (202 loc) · 6.45 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
#!/usr/bin/env bash
# PocketShell — Prerequisite Checker
# Checks all dependencies and installs npm packages.
set -euo pipefail
# --- Colors ---
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
BOLD='\033[1m'
NC='\033[0m' # No Color
PASS="${GREEN}PASS${NC}"
FAIL="${RED}FAIL${NC}"
WARN="${YELLOW}WARN${NC}"
passed=0
failed=0
warned=0
check_pass() {
echo -e " [${PASS}] $1"
passed=$((passed + 1))
}
check_fail() {
echo -e " [${FAIL}] $1"
failed=$((failed + 1))
}
check_warn() {
echo -e " [${WARN}] $1"
warned=$((warned + 1))
}
# --- Detect platform ---
detect_platform() {
local uname_s
uname_s="$(uname -s)"
case "$uname_s" in
Linux*)
if grep -qi microsoft /proc/version 2>/dev/null; then
echo "wsl"
else
echo "linux"
fi
;;
Darwin*)
echo "macos"
;;
MINGW*|MSYS*|CYGWIN*)
echo "windows"
;;
*)
echo "unknown"
;;
esac
}
PLATFORM="$(detect_platform)"
echo ""
echo -e "${BOLD}PocketShell — Prerequisite Check${NC}"
echo -e "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
# --- Platform ---
case "$PLATFORM" in
wsl)
check_pass "Platform: WSL (Windows Subsystem for Linux)"
;;
linux)
check_pass "Platform: Linux"
;;
macos)
check_pass "Platform: macOS"
;;
windows)
check_warn "Platform: Windows (Git Bash / MSYS)"
echo -e " ${YELLOW}Note: node-pty requires C++ build tools (windows-build-tools).${NC}"
echo -e " ${YELLOW}Consider using WSL for a smoother experience.${NC}"
;;
*)
check_warn "Platform: Unknown ($( uname -s ))"
;;
esac
# --- Node.js ---
if command -v node &>/dev/null; then
NODE_VERSION="$(node -v | sed 's/^v//')"
NODE_MAJOR="$(echo "$NODE_VERSION" | cut -d. -f1)"
if [ "$NODE_MAJOR" -ge 18 ]; then
check_pass "Node.js v${NODE_VERSION} (>= 18 required)"
else
check_fail "Node.js v${NODE_VERSION} found, but >= 18 is required"
case "$PLATFORM" in
macos)
echo -e " Install: ${CYAN}brew install node${NC} or https://nodejs.org"
;;
wsl|linux)
echo -e " Install: ${CYAN}curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - && sudo apt-get install -y nodejs${NC}"
;;
*)
echo -e " Install from: https://nodejs.org"
;;
esac
fi
else
check_fail "Node.js not found"
case "$PLATFORM" in
macos)
echo -e " Install: ${CYAN}brew install node${NC} or https://nodejs.org"
;;
wsl|linux)
echo -e " Install: ${CYAN}curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - && sudo apt-get install -y nodejs${NC}"
;;
*)
echo -e " Install from: https://nodejs.org"
;;
esac
fi
# --- npm ---
if command -v npm &>/dev/null; then
NPM_VERSION="$(npm -v)"
check_pass "npm v${NPM_VERSION}"
else
check_fail "npm not found (usually bundled with Node.js)"
fi
# --- Claude CLI ---
if command -v claude &>/dev/null; then
check_pass "Claude CLI found"
else
check_fail "Claude CLI not found"
echo -e " Install: ${CYAN}npm install -g @anthropic-ai/claude-code${NC}"
echo -e " Docs: https://docs.anthropic.com/en/docs/claude-code"
if [ "$PLATFORM" = "wsl" ]; then
echo -e " ${YELLOW}Note: Claude CLI must be installed inside WSL, not Windows.${NC}"
fi
fi
# --- Build tools (required for node-pty native module) ---
if command -v make &>/dev/null && command -v gcc &>/dev/null; then
check_pass "Build tools found (make, gcc)"
else
case "$PLATFORM" in
wsl|linux)
echo -e " [${WARN}] Build tools (make/gcc) not found — required for node-pty"
echo -e " Attempting to install build-essential (may prompt for password)..."
if sudo apt-get install -y build-essential; then
check_pass "Build tools installed (build-essential)"
else
check_fail "Could not install build tools automatically"
echo -e " Run manually: ${CYAN}sudo apt-get install -y build-essential${NC}"
fi
;;
macos)
echo -e " [${WARN}] Build tools not found — required for node-pty"
echo -e " Attempting to install Xcode Command Line Tools..."
if xcode-select --install 2>/dev/null; then
check_pass "Xcode Command Line Tools installation started"
echo -e " ${YELLOW}Note: Complete the installation dialog, then re-run setup.${NC}"
else
check_fail "Could not install Xcode Command Line Tools automatically"
echo -e " Run manually: ${CYAN}xcode-select --install${NC}"
fi
;;
*)
check_fail "Build tools (make/gcc) not found — required for node-pty"
echo -e " Install your platform's C build tools."
;;
esac
fi
# --- devtunnel (optional, needed for remote access) ---
if ! command -v devtunnel &>/dev/null; then
echo -e " [${WARN}] devtunnel CLI not found — attempting to install..."
if curl -sL https://aka.ms/DevTunnelCliInstall | bash; then
check_pass "devtunnel CLI installed"
else
check_warn "devtunnel CLI could not be installed automatically"
echo -e " Install manually: ${CYAN}curl -sL https://aka.ms/DevTunnelCliInstall | bash${NC}"
fi
fi
if command -v devtunnel &>/dev/null; then
if devtunnel user show &>/dev/null 2>&1; then
check_pass "devtunnel CLI ready (logged in)"
else
check_warn "devtunnel installed but not logged in"
echo -e " Run: ${CYAN}devtunnel user login -g -d${NC}"
echo -e " ${YELLOW}(Opens browser for GitHub/Microsoft authentication)${NC}"
fi
fi
# --- npm install ---
echo ""
echo -e "${BOLD}Installing dependencies...${NC}"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if [ "$failed" -gt 0 ]; then
echo -e " ${YELLOW}Skipping npm install — fix the failed checks above first.${NC}"
elif (cd "$SCRIPT_DIR" && npm install); then
check_pass "npm install completed"
else
check_fail "npm install failed"
fi
# --- Summary ---
echo ""
echo -e "${BOLD}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BOLD}Summary:${NC} ${GREEN}${passed} passed${NC}, ${RED}${failed} failed${NC}, ${YELLOW}${warned} warnings${NC}"
echo ""
if [ "$failed" -gt 0 ]; then
echo -e "${RED}Fix the failed checks above before running PocketShell.${NC}"
exit 1
else
echo -e "${GREEN}Ready to go!${NC} Run: ${CYAN}./pocketshell.sh start${NC}"
fi