-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinstall.bash
More file actions
executable file
·411 lines (375 loc) · 11 KB
/
install.bash
File metadata and controls
executable file
·411 lines (375 loc) · 11 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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
#!/usr/bin/env bash
DOTFILES_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
main() {
set -eu
install_basics
install_homebrew
install_homebrew_packages
trust_github
setup_bashrc
setup_gitconfig
setup_tmux
unminimize_ubuntu
mise_install
stow_dotfiles
install_neovim_plugins
install_go_packages
install_npm_packages
install_pi_packages
setup_mcporter
symlink_go
exec bash
}
install_basics() {
local commands=(curl git make ping clang)
if is_macos; then
for command in "${commands[@]}"; do
if ! command_exists "$command"; then
echo "command $command not found, please install it manually"
return 1
fi
done
elif ! command_exists "${commands[@]}"; then
echo "-> install basics"
sudo apt-get -y update
sudo apt-get -y install \
build-essential \
clang\
curl \
file \
git \
iproute2 \
iputils-ping \
man-db
fi
}
install_homebrew() {
if is_macos; then
export HOMEBREW_PREFIX="/opt/homebrew"
else
export HOMEBREW_PREFIX="/home/linuxbrew/.linuxbrew"
fi
if [ ! -x "$HOMEBREW_PREFIX/bin/brew" ]; then
echo "-> install homebrew"
NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
eval "$($HOMEBREW_PREFIX/bin/brew shellenv)"
}
install_homebrew_packages() {
echo "-> install homebrew packages"
local brew_packages=(
protobuf
atlassian-labs/acli/acli
bash-completion@2
bat
black
btop
claude-code
cloc
codex
curl
direnv
fd
fzf
gawk
gdb
gh
git
git-delta
glow
golangci-lint
grpcurl
htop
hyperfine
imagemagick
isort
jj
jjui
jq
kubectx
less
llm
magic-wormhole
mise
neovim
nono
pyright
ripgrep
rsync
socat
stow
tmux
trafilatura
tree
tree-sitter-cli
unzip
uv
vhs
watchman
yq
zoxide
)
brew install -q "${brew_packages[@]}"
if is_macos; then
brew install -q pngpaste
brew install -q --cask keycastr snowflake-snowsql
else
brew install -q bubblewrap
fi
if is_datadog; then
brew install -q datadog/tap/dd-auth datadog/tap/ddoc
if is_macos; then
brew install -q --cask datadog/tap/datadog-workspaces
fi
fi
}
trust_github() {
echo "-> trust github"
mkdir -pm700 ~/.ssh
ssh-keyscan -t rsa,ecdsa,ed25519 github.com >> ~/.ssh/known_hosts
}
is_macos() {
if [[ "$OSTYPE" =~ ^darwin ]]; then
return 0
else
return 1
fi
}
is_datadog() {
[ -e "$HOME/dd" ]
}
quiet_run() {
local output
if ! output=$("$@" 2>&1); then
echo "$output"
return 1
fi
}
command_exists() {
local commands=("$@")
local missing=0
for command in "${commands[@]}"; do
if ! command -v "$command" > /dev/null 2>&1; then
missing=1
break
fi
done
return $missing
}
setup_bashrc() {
if ! grep "$DOTFILES_DIR" "$HOME/.bashrc" > /dev/null; then
echo "-> setup bashrc"
echo "export DOTFILES_DIR=\"$DOTFILES_DIR\"" >> "$HOME/.bashrc"
echo ". $DOTFILES_DIR/bash/.bashrc" >> "$HOME/.bashrc"
fi
}
setup_gitconfig() {
# Ensure .gitconfig exists to avoid grep warnings
touch "$HOME/.gitconfig"
if ! grep "$DOTFILES_DIR" "$HOME/.gitconfig" > /dev/null; then
echo "-> add .gitconfig include to $HOME/.gitconfig"
echo "[include]" >> "$HOME/.gitconfig"
echo " path = \"$DOTFILES_DIR/git/.gitconfig\"" >> "$HOME/.gitconfig"
fi
if ! grep -E 'includeIf.+DataDog' "$HOME/.gitconfig" > /dev/null; then
echo "-> add .gitconfig.datadog include to $HOME/.gitconfig for DataDog"
echo "[includeIf \"gitdir:~/go/src/github.com/DataDog/**\"]" >> "$HOME/.gitconfig"
echo " path = \"$DOTFILES_DIR/git/.gitconfig.datadog\"" >> "$HOME/.gitconfig"
fi
if ! grep -E 'includeIf.+open-telemetry' "$HOME/.gitconfig" > /dev/null; then
echo "-> add .gitconfig.open-telemetry include to $HOME/.gitconfig for OpenTelemetry"
echo "[includeIf \"gitdir:~/go/src/github.com/open-telemetry/**\"]" >> "$HOME/.gitconfig"
echo " path = \"$DOTFILES_DIR/git/.gitconfig.datadog\"" >> "$HOME/.gitconfig"
fi
if [[ "${USER:-}" == "bits" ]] && ! grep '# workspace config' "$HOME/.gitconfig" > /dev/null; then
echo "-> add workspace config to $HOME/.gitconfig"
echo "# workspace config" >> "$HOME/.gitconfig"
echo "[delta]" >> "$HOME/.gitconfig"
echo " hyperlinks-file-link-format = "cursor://vscode-remote/ssh-remote+workspace-${HOSTNAME}/{path}:{line}"
" >> "$HOME/.gitconfig"
fi
}
setup_tmux() {
# Ensure .tmux.conf exists to avoid grep warnings
touch "$HOME/.tmux.conf"
if ! grep "$DOTFILES_DIR" "$HOME/.tmux.conf" > /dev/null; then
echo "-> setup tmux config"
echo "source-file \"$DOTFILES_DIR/tmux/.tmux.conf\"" >> "$HOME/.tmux.conf"
fi
}
unminimize_ubuntu() {
if grep "minimized" "$(which man)" > /dev/null; then
echo "-> unminimizing ubuntu install"
yes | DEBIAN_FRONTEND=noninteractive unminimize
fi
}
stow_dotfiles() {
echo "-> stow dotfiles"
mkdir -p "$HOME/.claude" "$HOME/.pi/agent" "$HOME/.mcporter/daemon"
stow_file_adopt git/.gitignore
stow --adopt -t "$HOME" jj jjui neovim mise claude codex idea kitty pi
}
stow_file_adopt() {
local rel_path="$1"
local src="$DOTFILES_DIR/$rel_path"
local dst="$HOME/${rel_path#*/}"
if [ -L "$dst" ]; then
return
fi
mkdir -p "$(dirname "$dst")"
if [ -e "$dst" ]; then
cp "$dst" "$src"
fi
ln -sf "$src" "$dst"
}
install_neovim_plugins() {
echo "-> install neovim plugins"
quiet_run nvim --headless "+Lazy! restore" "+Lazy! clean" "+Lazy! install" +qa
quiet_run nvim --headless "+MasonToolsUpdateSync" +qa
}
mise_install() {
echo "-> install mise tools"
# Avoid GitHub API rate limits for mise's aqua backend
if [ -z "${GITHUB_TOKEN:-}" ] && command -v gh &>/dev/null; then
export GITHUB_TOKEN=$(gh auth token 2>/dev/null)
fi
mise trust -q
mise install -q
mise upgrade -q
eval "$(mise activate bash)"
}
install_go_packages() {
echo "-> install go packages"
export GOPROXY="https://proxy.golang.org,direct"
local go_packages=(
github.com/bokwoon95/wgo@latest
github.com/go-delve/delve/cmd/dlv@latest
github.com/maruel/panicparse/v2/cmd/pp@latest
golang.org/x/perf/cmd/benchstat@latest
golang.org/x/pkgsite/cmd/pkgsite@latest
golang.org/x/tools/cmd/stress@latest
honnef.co/go/tools/cmd/staticcheck@latest
)
for package in "${go_packages[@]}"; do
go install "$package" &
done
wait
}
install_npm_packages() {
echo "-> install npm packages"
quiet_run npm install -g markserv @mariozechner/pi-coding-agent mcporter @mermaid-js/mermaid-cli
}
install_pi_packages() {
echo "-> install pi packages"
pi update
}
setup_mcporter() {
echo "-> setup mcporter config"
mkdir -p "$HOME/.mcporter"
# Remove legacy claude mcp servers (migrated to mcporter)
for name in datadog datadog-staging chrome-devtools snowflake; do
claude mcp remove "$name" &>/dev/null || true
done
local snowflake_block=""
if [ -n "${SNOWFLAKE_ACCOUNT:-}" ] && [ -f "$HOME/.config/mcp/snowflake-config.yaml" ]; then
local user_email
user_email="$(whoami)@datadoghq.com"
snowflake_block=$(cat <<SNOWFLAKE
,
"snowflake": {
"command": "uvx",
"args": [
"--python", "3.12",
"--python-preference=managed",
"--from", "git+https://github.com/Snowflake-Labs/mcp",
"mcp-server-snowflake",
"--service-config-file", "~/.config/mcp/snowflake-config.yaml",
"--authenticator", "externalbrowser",
"--transport", "stdio",
"--user", "${user_email}"
],
"env": {
"SNOWFLAKE_ACCOUNT": "${SNOWFLAKE_ACCOUNT}",
"SNOWFLAKE_USER": "${user_email}",
"SNOWFLAKE_DATABASE": "REPORTING"
}
}
SNOWFLAKE
)
else
echo " skipping snowflake mcp (see Confluence: 'Snowflake for MCP')"
fi
cat > "$HOME/.mcporter/mcporter.json" <<EOF
{
"mcpServers": {
"atlassian": {
"baseUrl": "https://mcp.atlassian.com/v1/mcp",
"auth": "oauth"
},
"datadog": {
"baseUrl": "https://mcp.datadoghq.com/api/unstable/mcp-server/mcp?toolsets=core,profiling",
"auth": "oauth"
},
"datadog-staging": {
"baseUrl": "https://mcp.datad0g.com/api/unstable/mcp-server/mcp?toolsets=core,profiling",
"auth": "oauth"
},
"chrome-devtools": {
"command": "npx",
"args": ["-y", "chrome-devtools-mcp@latest"]
},
"google-workspace": {
"command": "npx",
"args": ["-y", "mcp-remote", "https://google-workspace-mcp-server-834963730936.us-central1.run.app/mcp"]
}${snowflake_block}
},
"imports": []
}
EOF
}
fetch_repositories() {
echo "-> fetch jj repositories in ~/go/src"
local repos=()
while IFS= read -r repo; do
repos+=("$repo")
done < <(find "$HOME/go/src" -mindepth 4 -maxdepth 4 -type d -name .jj 2>/dev/null | sed 's|/\.jj$||')
if [ ${#repos[@]} -eq 0 ]; then
return
fi
# Parallel but bounded. GIT_SSH_COMMAND disables SSH ControlMaster to avoid
# `mux_client_request_session: Session open refused by peer` races when many
# fetches hit github.com at once; scoped to xargs, so no restore needed.
printf '%s\n' "${repos[@]}" \
| GIT_SSH_COMMAND='ssh -o ControlMaster=no -o ControlPath=none' \
xargs -n1 -P 16 -I {} bash -c '
repo="$1"
cd "$repo" || exit 0
# Skip repos with no git remotes.
if [ -z "$(jj git remote list 2>/dev/null)" ]; then
exit 0
fi
# --ignore-working-copy bypasses the snapshot, so large files in
# the working copy do not abort the fetch.
if output=$(jj --ignore-working-copy git fetch 2>&1); then
:
else
echo " failed: $repo"
echo "$output" | sed "s/^/ /"
fi
' _ {}
}
symlink_go() {
# Hack: Make sure the VS Code Go extension can always find the go binary
echo "-> symlink go to /usr/local/bin"
local target="/usr/local/bin/go"
local go_bin
go_bin="$(mise which go)"
if [ "$(readlink "$target" 2>/dev/null)" = "$go_bin" ]; then
return
fi
sudo ln -sf "$go_bin" "$target"
}
# Only run main when executed directly, not when sourced.
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
main "$@"
fi