-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.zsh
executable file
·365 lines (318 loc) · 12.8 KB
/
bootstrap.zsh
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
#!/bin/zsh
# enable what you want to install here
CRYPTO=1
FORMALMETHODS=1
GENERICTOOLS=1
GENERICCASKTOOLS=1
DEVOPSTOOLS=1
MOBILETOOLS=1
UNITYTOOLS=1
CPPTOOLS=1
TEXLIGHT=0
TEXFULL=0
source .zshfunctions
set_error_handler
git submodule init
git submodule update
if [[ $OSTYPE == 'darwin'* ]]; then
# sanity checks
assure_userlevel_zsh
check_not_rosetta
fi
if [[ $OSTYPE == 'darwin'* ]] && isadmin; then
# clean up brew
brew autoremove
brew cleanup
if [ $GENERICTOOLS = 1 ]; then
brew install bat fzf git gs jq npm nvim oath-toolkit tldr tmux trash tree yq yt-dlp watch zsh-completions
# apple development, switch between xcode versions.
brew install robotsandpencils/made/xcodes
# xcode cleaner app
brew install --cask devcleaner
# zsh-completions setup script
if type brew &>/dev/null; then
rm -f ~/.zcompdump
FPATH=$(brew --prefix)/share/zsh-completions:$FPATH
autoload -Uz compinit compaudit
compaudit | xargs chmod g-w
# rm -f ~/.zcompdump # may be necessary
compinit
fi
# iterm2 shell integration
curl -L https://iterm2.com/shell_integration/zsh -o ~/.iterm2_shell_integration.zsh
fi
if [ $MOBILETOOLS = 1 ]; then
# Android
brew install android-platform-tools
brew install --cask android-file-transfer
# flutter-stylizer
brew install go
export GOPATH=${HOME}/go
mkdir -p $GOPATH
export PATH=${PATH}:${HOME}/go/bin
go install github.com/gmlewis/go-flutter-stylizer/cmd/flutter-stylizer@latest
mkdir -p ~/Developer # create the ~/Developer folder if it doesn't exist yet.
country=$(curl -s ipinfo.io/country --connect-timeout 5)
if [[ "$country" == "CN" ]]; then
# if in china:
export PUB_HOSTED_URL=https://mirror.sjtu.edu.cn
export FLUTTER_STORAGE_BASE_URL=https://mirror.sjtu.edu.cn/dart-pub
if [ ! -d ~/Developer/flutter ]; then
git clone -b main https://git.sjtu.edu.cn/sjtug/flutter-sdk.git ~/Developer/flutter
fi
else
if [ ! -d ~/Developer/flutter ]; then
git clone -b main https://github.com/flutter/flutter.git ~/Developer/flutter
fi
fi
# maestro for testing
[ ! -d ~/.maestro/bin ] && curl -Ls "https://get.maestro.mobile.dev" | bash
fi
if [ $CPPTOOLS = 1 ]; then
brew install gmp mpfr ncurses
# Boehm-Demers-Weiser garbage collector
brew install bdw-gc
fi
if [ $UNITYTOOLS = 1 ]; then
# for some reason, brew install dotnet doesn't provide the right arm binaries....
if [[ ! -d "$HOME/.dotnet" ]]; then
mkdir -p "$HOME/.dotnet"
ARCH=$(uname -m)
if [[ "$ARCH" == "arm64" ]]; then
curl "https://download.visualstudio.microsoft.com/download/pr/d81d84cf-4bb8-4371-a4d2-88699a38a83b/9bddfe1952bedc37e4130ff12abc698d/dotnet-sdk-8.0.303-osx-arm64.tar.gz" > "$HOME/dotnet.tar.gz"
else
curl "https://download.visualstudio.microsoft.com/download/pr/295f5e51-4d26-4706-90c1-25b745cd2abf/ef976bfc166782e519036ee7670eac36/dotnet-sdk-8.0.303-osx-x64.tar.gz" > "$HOME/dotnet.tar.gz"
fi
tar -xzvf "$HOME/dotnet.tar.gz" -C "$HOME/.dotnet"
rm "$HOME/dotnet.tar.gz"
fi
fi
if [ $DEVOPSTOOLS = 1 ]; then
brew install kubectl fluxcd/tap/flux kubetail
brew tap johanhaleby/kubetail && brew install kubetail
brewprefixlocation=$(brew --prefix)
echo "$(brew --prefix)/share/zsh"
(
set -x; cd "$(mktemp -d)" &&
OS="$(uname | tr '[:upper:]' '[:lower:]')" &&
ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/\(arm\)\(64\)\?.*/\1\2/' -e 's/aarch64$/arm64/')" &&
KREW="krew-${OS}_${ARCH}" &&
curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/${KREW}.tar.gz" &&
tar zxvf "${KREW}.tar.gz" &&
./"${KREW}" install krew
)
# For MQTT connections.
brew install mqttx --cask
fi
### Formal methods
if [ $FORMALMETHODS = 1 ]; then
brew install eprover
brew install spin
brew install --cask tla-plus-toolbox
# PsiSolver
brew tap bvoq/bvoq
brew install psisolver
# Kframework
#brew tap kframework/k
#brew install kframework
## Agda
# brew install stack
# stack install Agda # installs GHC automatically
# # install emacs from mituharu: https://github.com/railwaycat/homebrew-emacsmacport
# brew tap railwaycat/emacsmacport
# brew install --cask emacs-mac
# agda-mode setup
fi
#if [ $SECURITYTOOLS = 1 ]; then
# # https://github.com/joxeankoret/diaphora
# # frida
#fi
if [ $GENERICCASKTOOLS = 1 ]; then
brew install appcleaner baidunetdisk caffeine dash docker keka tor-browser --cask
# also install regex for safari: https://apps.apple.com/ch/app/regex-for-safari/id1597580456?l=en-GB
brew install visual-studio-code --cask # or use visual-studio-code@insiders instead
# reminder to self: you own a license to use this:
#brew install daisydisk --cask
fi
if [ $TEXLIGHT = 1 ]; then
# reminder to self: you own a license to use this:
# comes with its own latex.
brew install texifier --cask
## tex light version CLI
# brew install --cask basictex
# brew install --cask tex-live-utility
fi
if [ $TEXFULL = 1 ]; then
# reminder to self: you own a license to use this:
# comes with its own latex.
brew install texifier --cask
brew install mactex --cask
fi
fi
# Copy dotfiles after installation, because some install script like to add stuff to .zshrc (evil right?!?)
# create a backup, better safe than sorry.
[ -f ~/.emacs ] && mv ~/.emacs ~/.emacs.old
[ -f ~/.inputrc ] && mv ~/.inputrc ~/.inputrc.old
[ -f ~/.gitconfig ] && mv ~/.gitconfig ~/.gitconfig.old
[ -f ~/.tmux.conf ] && mv ~/.tmux.conf ~/.tmux.conf.old
[ -d ~/.tmux.old ] && rm -r ~/.tmux.old
[ -d ~/.tmux ] && mv ~/.tmux ~/.tmux.old
[ -f ~/.vimrc ] && mv ~/.vimrc ~/.vimrc.old
[ -f ~/.config ] && mv ~/.config/nvim/init.vim ~/.config/nvim/init.vim.old
[ -f ~/.zshrc ] && mv ~/.zshrc ~/.zshrc.old
[ -f ~/.zshfunctions ] && mv ~/.zshfunctions ~/.zshfunctions.old
[ -f ~/.zshenv ] && mv ~/.zshenv ~/.zshenv.old
cp .emacs ~/.emacs
cp .inputrc ~/.inputrc
cp .gitconfig ~/.gitconfig
cp .tmux.conf ~/.tmux.conf
cp -a .tmux ~/.tmux
cp .zshrc ~/.zshrc
cp .zshenv ~/.zshenv
cp .zshfunctions ~/.zshfunctions
if [[ $OSTYPE == 'darwin'* ]]; then
[ -f ~/Library/Application\ Support/Code/User/settings.json ] && mv ~/Library/Application\ Support/Code/User/settings.json ~/Library/Application\ Support/Code/User/settings.json.old
mkdir -p ~/Library/Application\ Support/Code/User
mkdir -p ~/Library/Application\ Support/Code\ -\ Insiders/User
cp vscode/.vscode-settings.json ~/Library/Application\ Support/Code/User/settings.json # VSCode
cp vscode/.vscode-settings.json ~/Library/Application\ Support/Code\ -\ Insiders/User/settings.json # VSCode Insiders
#cp vscode/keybindings.json ~/Library/Application\ Support/Code/User/keybindings # VSCode
#cp vscode/keybindings.json ~/Library/Application\ Support/Code\ -\ Insiders/User/keybindings.json # VSCode Insiders
defaults write com.microsoft.VSCode ApplePressAndHoldEnabled -bool false # VSCode
defaults write com.microsoft.VSCodeInsiders ApplePressAndHoldEnabled -bool false # VSCode Insiders
fi
echo "Installing Vim and Neovim configurations and plugins"
# Install vim and neovim
# install vundle for vim
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
# install vundle for nvim
sh -c 'curl -fLo "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
# copy the vim config files
mkdir -p ~/.config/nvim && cp .config/nvim/init.vim ~/.config/nvim/init.vim
cp .vimrc ~/.vimrc
if command -v nvim > /dev/null; then
nvim +'PlugInstall --sync' +qa
nvim +'PlugClean --sync' +qa
fi
\vim +'PlugInstall --sync' +qa
\vim +'PlugClean --sync' +qa
echo "To enable trace, run: 'csrutil enable --without dtrace --without debug' in reboot mode."
echo "Installing VSCode extensions"
waitconfirm
# general
code --install-extension aaron-bond.better-comments
code --install-extension deerawan.vscode-dash
code --install-extension johnpapa.vscode-peacock
code --install-extension usernamehw.errorlens
code --install-extension eamodio.gitlens
code --install-extension PKief.material-icon-theme
code --install-extension Ho-Wan.setting-toggle
code --install-extension ctf0.close-tabs-to-the-left
code --install-extension ms-vsliveshare.vsliveshare
# theme
code --install-extension ifahrentholz.one-quiet-dark-pro
# generic linters
code --install-extension redhat.vscode-yaml
code --install-extension DavidAnson.vscode-markdownlint
# Supermaven
code --install-extension Supermaven.supermaven
# ChatGPT
curl "https://persistent.oaistatic.com/pair-with-ai/openai-chatgpt-latest.vsix" > openai-chatgpt-latest.vsix
code --install-extension openai-chatgpt-latest.vsix
rm openai-chatgpt-latest.vsix
if [ $UNITYTOOLS = 1 ]; then
# Note this also installs its own dotnet runtime, but not dotnet sdk!
code --install-extension visualstudiotoolsforunity.vstuc
fi
if [ $FORMALMETHODS = 1 ]; then
code --install-extension banacorn.agda-mode
code --install-extension gpoore.codebraid-preview
fi
if [ $MOBILETOOLS = 1 ]; then
# General:
code --install-extension mariomatheu.syntax-project-pbxproj
# Dart/Flutter related:
code --install-extension Dart-Code.dart-code
code --install-extension Dart-Code.flutter
code --install-extension gmlewis-vscode.flutter-stylizer # nice button at bottom
code --install-extension qlevar.pub-manager
# Flutter test coverage:
code --install-extension ryanluker.vscode-coverage-gutters
code --install-extension flutterando.flutter-coverage
fi
if [ $CRYPTO = 1 ]; then
echo "Next: Installing monero."
waitconfirm
if [ ! -d ~/monero ]; then
git clone --recursive https://github.com/monero-project/monero ~/monero
fi
{
cd ~/monero
chmod -R u+rw ~/monero
git fetch --all
BRANCH=$(git ls-remote --heads origin | grep 'release-' | awk -F'/' '{print $3}' | sort -V | tail -n 1)
echo "Using monero branch: ${BRANCH}"
git checkout --recurse-submodules ${BRANCH}
git submodule init
git submodule update
brew update
brew bundle --file=contrib/brew/Brewfile || true # this command can fail due to empty brew taps.
chmod -R u+rw ~/monero
make USE_SINGLE_BUILDDIR=0 # makes sure that only a single build dir is used.
# a few notes
# ledger is stored in $HOME/.bitmonero. Copy for faster sync.
# keys are stored next to monero-wallet-cli.
# to recover use: monero-wallet-cli --restore-deterministic-wallet
}
fi
if [ $MOBILETOOLS = 1 ] && isadmin; then
echo "Next: Installing firebase, requires root permission."
waitconfirm
curl -sL https://firebase.tools | bash
dart pub global activate flutterfire_cli 0.3.0-dev.16 --overwrite
fi
# Language servers for vim and vscode (also edit in init.vim)
echo "Next: Installing language servers."
waitconfirm
if ! isadmin; then
# store npm packages on the user-level not admin level.
# http://michaelb.org/archive/article/30.html
npm config set prefix ~/.local
fi
npm install -g pyright
npm install -g bash-language-server
if [[ $OSTYPE == 'darwin'* ]] && isadmin; then
echo "Next: Installing chatgpt cli"
curl -sS https://raw.githubusercontent.com/0xacx/chatGPT-shell-cli/main/install.sh | sudo -E zsh
fi
if [[ $OSTYPE == 'darwin'* ]] && isadmin; then
#echo "Next: Installing rclone and others that need root permission"
#waitconfirm
#sudo -v ; curl https://rclone.org/install.sh | sudo bash
# brew install macfuse --cask # reinstall after changing security properties
fi
#later setup wasabi-kdkdk:
#using: https://wasabi-support.zendesk.com/hc/en-us/articles/115001600252-How-do-I-use-Rclone-with-Wasabi-
#s3.ap-northeast-1.wasabisys.com with PW in pass
# restart and make sure macfuse works, then:
#rclone mount wasabi-kdkdk:kdkdk/ wasabi-kdkdk/ &
# rclone copy source:path destination:path
# System changes for macOS
if [[ $OSTYPE == 'darwin'* ]] && isadmin; then
echo "Next: Installing system changes for macOS."
waitconfirm
bash .macos
echo "Almost done. Next we will install some Terminal and Xcode themes. You can also install them manually alternatively."
waitconfirm
mkdir -p ~/Library/Developer/Xcode/UserData/FontAndColorThemes/ && cp xcode/Zenburn.xccolortheme ~/Library/Developer/Xcode/UserData/FontAndColorThemes/Zenburn.xccolortheme
echo "Done. It will need to be manually selected under Xcode > Preferences > Themes > Zenburn"
echo "Also, in the new Xcode you may need to set Xcode > Preferences > General > Appearance > Dark"
echo "Afer this Terminal.app will be killed. Note that in order to apply all settings a full restart is required."
waitconfirm
cp terminal/com.apple.Terminal.plist ~/Library/Preferences/com.apple.Terminal.plist
defaults read com.apple.Terminal
echo "Done. Goodbye."
killall "Terminal"
fi