|
1 | 1 | #!/usr/bin/env bash |
2 | | -# claude-code installer. |
| 2 | +# claude-code installer. Runs as the workspace user (see src/base/Dockerfile). |
3 | 3 | set -e |
4 | 4 |
|
5 | | -USER_NAME="${_REMOTE_USER:-${USERNAME:-root}}" |
6 | | -if [ "$USER_NAME" = "root" ]; then |
7 | | - USER_GROUP="root" |
8 | | -else |
9 | | - USER_GROUP="$(id -gn "$USER_NAME")" |
10 | | -fi |
11 | | - |
12 | | -USER_HOME="$(getent passwd "$USER_NAME" | cut -d: -f6)" |
13 | | - |
14 | | -HOME="$USER_HOME" curl -fsSL https://claude.ai/install.sh | HOME="$USER_HOME" bash |
| 5 | +curl -fsSL https://claude.ai/install.sh | bash |
15 | 6 |
|
16 | | -if [ ! -x "$USER_HOME/.local/bin/claude" ]; then |
17 | | - echo "claude-code: expected $USER_HOME/.local/bin/claude after install, but it was not found." >&2 |
| 7 | +if [ ! -x "$HOME/.local/bin/claude" ]; then |
| 8 | + echo "claude-code: expected $HOME/.local/bin/claude after install, but it was not found." >&2 |
18 | 9 | exit 1 |
19 | 10 | fi |
20 | 11 |
|
21 | | -# The upstream installer runs as root with HOME=$USER_HOME and writes into |
22 | | -# $HOME/.claude, $HOME/.local AND $HOME/.cache (its own state dir plus |
23 | | -# node-gyp from any native-module compile). Chown all three so nothing is |
24 | | -# left root-owned on the remote user's home. .cache is guarded because it |
25 | | -# may not exist on minimal installs. |
26 | | -chown -R "$USER_NAME:$USER_GROUP" "$USER_HOME/.claude" "$USER_HOME/.local" |
27 | | -if [ -d "$USER_HOME/.cache" ]; then |
28 | | - chown -R "$USER_NAME:$USER_GROUP" "$USER_HOME/.cache" |
| 12 | +# PATH hook in ~/.profile — if-check at source time only prepends |
| 13 | +# $HOME/.local/bin when it's not already in $PATH. |
| 14 | +cat >> "$HOME/.profile" <<EOF |
| 15 | +
|
| 16 | +if ! echo ":\$PATH:" | grep -q ":\$HOME/.local/bin:"; then |
| 17 | + export PATH="\$HOME/.local/bin:\$PATH" |
29 | 18 | fi |
| 19 | +EOF |
30 | 20 |
|
31 | 21 | # Declare the HOME paths Claude Code needs persisted. The home-persist |
32 | 22 | # resolver reads every /etc/home-persist.d/*.json at workspace start and |
33 | | -# symlinks these into /mnt/home-persist. |
34 | | -mkdir -p /etc/home-persist.d |
35 | | -cat > /etc/home-persist.d/claude-code.json <<'EOF' |
| 23 | +# symlinks these into /mnt/home-persist. /etc/home-persist.d is root-owned. |
| 24 | +sudo mkdir -p /etc/home-persist.d |
| 25 | +sudo tee /etc/home-persist.d/claude-code.json >/dev/null <<'EOF' |
36 | 26 | { |
37 | 27 | "source": "claude-code", |
38 | 28 | "paths": [".claude/", ".claude.json"] |
|
0 commit comments