|
1 | 1 | #!/bin/sh |
2 | | -# Capsem developer bootstrap -- checks tools, installs deps, runs doctor. |
3 | | -# Only prerequisite: sh. Works on macOS and Linux (apt/dnf). |
| 2 | +# Capsem developer bootstrap -- installs deps, runs doctor with auto-fix. |
| 3 | +# Only prerequisite: sh, git, curl. |
4 | 4 | # Usage: sh scripts/bootstrap.sh |
5 | 5 | set -eu |
6 | 6 |
|
7 | | -# --- OS detection --- |
8 | | -OS="$(uname -s)" |
9 | | -PKG="unknown" |
10 | | -if [ "$OS" = "Linux" ]; then |
11 | | - if command -v apt-get >/dev/null 2>&1; then PKG="apt" |
12 | | - elif command -v dnf >/dev/null 2>&1; then PKG="dnf" |
13 | | - fi |
14 | | -fi |
15 | | - |
16 | | -PASS=0 |
17 | | -FAIL=0 |
18 | | - |
19 | | -pass() { printf " [ok] %s\n" "$1"; PASS=$((PASS + 1)); } |
| 7 | +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" |
20 | 8 |
|
21 | | -miss() { |
22 | | - printf " [MISS] %s\n" "$1" |
23 | | - printf " install: %s\n" "$2" |
24 | | - FAIL=$((FAIL + 1)) |
25 | | -} |
26 | | - |
27 | | -# --- Platform-aware install hint --- |
28 | | -hint_for() { |
29 | | - tool="$1" |
30 | | - case "$tool" in |
31 | | - rustup) |
32 | | - echo "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh" ;; |
33 | | - cargo) |
34 | | - echo "installed with rustup (see above)" ;; |
35 | | - just) |
36 | | - echo "cargo install just" ;; |
37 | | - node) |
38 | | - case "$OS" in |
39 | | - Darwin) echo "brew install node (24+ required)" ;; |
40 | | - Linux) |
41 | | - case "$PKG" in |
42 | | - apt) echo "sudo apt install nodejs npm (24+ required, or use https://nodejs.org)" ;; |
43 | | - dnf) echo "sudo dnf install nodejs npm (24+ required, or use https://nodejs.org)" ;; |
44 | | - *) echo "install Node.js 24+ from https://nodejs.org" ;; |
45 | | - esac ;; |
46 | | - *) echo "install Node.js 24+ from https://nodejs.org" ;; |
47 | | - esac ;; |
48 | | - pnpm) |
49 | | - echo "npm i -g pnpm" ;; |
50 | | - python3) |
51 | | - case "$OS" in |
52 | | - Darwin) echo "brew install python" ;; |
53 | | - Linux) |
54 | | - case "$PKG" in |
55 | | - apt) echo "sudo apt install python3 python3-venv" ;; |
56 | | - dnf) echo "sudo dnf install python3" ;; |
57 | | - *) echo "install Python 3.11+ from https://python.org" ;; |
58 | | - esac ;; |
59 | | - *) echo "install Python 3.11+ from https://python.org" ;; |
60 | | - esac ;; |
61 | | - uv) |
62 | | - echo "curl -LsSf https://astral.sh/uv/install.sh | sh" ;; |
63 | | - git) |
64 | | - case "$OS" in |
65 | | - Darwin) echo "brew install git" ;; |
66 | | - Linux) |
67 | | - case "$PKG" in |
68 | | - apt) echo "sudo apt install git" ;; |
69 | | - dnf) echo "sudo dnf install git" ;; |
70 | | - *) echo "install git from https://git-scm.com" ;; |
71 | | - esac ;; |
72 | | - *) echo "install git from https://git-scm.com" ;; |
73 | | - esac ;; |
74 | | - docker) |
75 | | - case "$OS" in |
76 | | - Darwin) echo "brew install colima docker && colima start --vm-type vz --vz-rosetta --memory 8 --cpu 8" ;; |
77 | | - Linux) |
78 | | - case "$PKG" in |
79 | | - apt) echo "sudo apt install docker.io" ;; |
80 | | - dnf) echo "sudo dnf install docker" ;; |
81 | | - *) echo "install docker for your distribution" ;; |
82 | | - esac ;; |
83 | | - *) echo "install docker" ;; |
84 | | - esac ;; |
85 | | - esac |
86 | | -} |
87 | | - |
88 | | -printf "Capsem Bootstrap (%s)\n" "$OS" |
| 9 | +printf "Capsem Bootstrap (%s)\n" "$(uname -s)" |
89 | 10 | echo "========================" |
90 | 11 | echo "" |
91 | 12 |
|
92 | | -# --- Phase 1: Core tools --- |
93 | | -echo "== Checking tools ==" |
94 | | - |
95 | | -for tool in rustup cargo just node pnpm python3 uv git; do |
| 13 | +# --- Phase 1: Bare minimum tools --- |
| 14 | +MISSING=0 |
| 15 | +for tool in bash git curl; do |
96 | 16 | if command -v "$tool" >/dev/null 2>&1; then |
97 | | - if [ "$tool" = "node" ]; then |
98 | | - pass "node ($(node --version))" |
99 | | - else |
100 | | - pass "$tool" |
101 | | - fi |
| 17 | + printf " [ok] %s\n" "$tool" |
102 | 18 | else |
103 | | - miss "$tool" "$(hint_for "$tool")" |
| 19 | + printf " [MISS] %s\n" "$tool" |
| 20 | + MISSING=$((MISSING + 1)) |
104 | 21 | fi |
105 | 22 | done |
106 | 23 |
|
107 | | -# Container runtime |
108 | | -if command -v docker >/dev/null 2>&1; then |
109 | | - pass "docker" |
110 | | -else |
111 | | - miss "docker" "$(hint_for "docker")" |
112 | | -fi |
113 | | -# Docker BuildKit (buildx) -- required for cross-arch container builds |
114 | | -if docker buildx version >/dev/null 2>&1; then |
115 | | - pass "docker buildx" |
116 | | -else |
117 | | - if [ "$OS" = "Darwin" ]; then |
118 | | - miss "docker buildx" "brew install docker-buildx && ln -sf \$(brew --prefix docker-buildx)/bin/docker-buildx ~/.docker/cli-plugins/docker-buildx" |
119 | | - else |
120 | | - miss "docker buildx" "sudo apt install docker-buildx-plugin" |
121 | | - fi |
122 | | -fi |
123 | | -# Colima (macOS only -- manages the container VM) |
124 | | -if [ "$OS" = "Darwin" ]; then |
125 | | - if command -v colima >/dev/null 2>&1; then |
126 | | - pass "colima" |
127 | | - else |
128 | | - miss "colima" "brew install colima && colima start --vm-type vz --vz-rosetta --memory 8 --cpu 8" |
129 | | - fi |
130 | | -fi |
131 | | - |
132 | | -# --- macOS: Xcode Command Line Tools + codesigning --- |
133 | | -if [ "$OS" = "Darwin" ]; then |
134 | | - if xcode-select -p >/dev/null 2>&1; then |
135 | | - pass "Xcode Command Line Tools ($(xcode-select -p))" |
136 | | - else |
137 | | - miss "Xcode Command Line Tools" "xcode-select --install" |
138 | | - fi |
139 | | - |
140 | | - # Cargo runner config (signs binaries with Virtualization entitlements) |
141 | | - if [ -f ".cargo/config.toml" ] && grep -q 'runner.*run_signed' .cargo/config.toml; then |
142 | | - pass ".cargo/config.toml (cargo runner)" |
143 | | - else |
144 | | - miss ".cargo/config.toml" "git checkout .cargo/config.toml" |
145 | | - fi |
| 24 | +# Check for rustup/cargo (needed for cargo tools) |
| 25 | +if ! command -v rustup >/dev/null 2>&1; then |
| 26 | + printf " [MISS] rustup -- install: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh\n" |
| 27 | + MISSING=$((MISSING + 1)) |
146 | 28 | fi |
147 | 29 |
|
148 | | -# --- Linux: VM feature notice --- |
149 | | -if [ "$OS" = "Linux" ]; then |
150 | | - printf "\n" |
151 | | - printf " [INFO] Linux uses KVM for VM features. Ensure /dev/kvm is accessible.\n" |
152 | | - printf " macOS uses Apple Virtualization.framework (codesigning required).\n" |
| 30 | +# Check for just (needed for everything else) |
| 31 | +if ! command -v just >/dev/null 2>&1; then |
| 32 | + printf " [MISS] just -- install: cargo install just\n" |
| 33 | + MISSING=$((MISSING + 1)) |
153 | 34 | fi |
154 | 35 |
|
155 | | -echo "" |
156 | | -printf "== Results: %d found, %d missing ==\n" "$PASS" "$FAIL" |
157 | | - |
158 | | -if [ "$FAIL" -gt 0 ]; then |
| 36 | +if [ "$MISSING" -gt 0 ]; then |
159 | 37 | echo "" |
160 | 38 | echo "Install the missing tools above, then re-run: sh scripts/bootstrap.sh" |
161 | 39 | exit 1 |
|
165 | 43 | echo "" |
166 | 44 | echo "== Installing dependencies ==" |
167 | 45 |
|
168 | | -printf " Python deps (uv sync)...\n" |
169 | | -uv sync --quiet |
| 46 | +if command -v uv >/dev/null 2>&1; then |
| 47 | + printf " Python deps (uv sync)...\n" |
| 48 | + uv sync --quiet |
| 49 | +else |
| 50 | + printf " [SKIP] Python deps (uv not installed yet -- doctor will catch this)\n" |
| 51 | +fi |
170 | 52 |
|
171 | | -printf " Frontend deps (pnpm install)...\n" |
172 | | -(cd frontend && pnpm install --frozen-lockfile --silent) |
| 53 | +if command -v pnpm >/dev/null 2>&1; then |
| 54 | + printf " Frontend deps (pnpm install)...\n" |
| 55 | + (cd frontend && pnpm install --frozen-lockfile --silent) |
| 56 | +else |
| 57 | + printf " [SKIP] Frontend deps (pnpm not installed yet -- doctor will catch this)\n" |
| 58 | +fi |
173 | 59 |
|
174 | | -# --- Phase 3: Run doctor --- |
| 60 | +# --- Phase 3: Run doctor with auto-fix --- |
175 | 61 | echo "" |
176 | | -echo "== Running just doctor ==" |
| 62 | +echo "== Running doctor (with auto-fix) ==" |
177 | 63 | echo "" |
178 | | -just doctor |
| 64 | +"$SCRIPT_DIR/doctor-common.sh" --fix |
179 | 65 |
|
180 | 66 | echo "" |
181 | 67 | echo "========================" |
182 | 68 | echo "Bootstrap complete. Next steps:" |
183 | 69 | echo "" |
184 | | -echo " just build-assets # Build VM kernel + rootfs (~10 min, needs Docker via Colima on macOS)" |
| 70 | +echo " just build-assets # Build VM kernel + rootfs (~10 min, needs Docker)" |
185 | 71 | echo " just run \"echo hi\" # Verify VM boots" |
186 | 72 | echo "" |
0 commit comments