-
Notifications
You must be signed in to change notification settings - Fork 2
/
bootstrap
executable file
·290 lines (246 loc) · 8.8 KB
/
bootstrap
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
#!/bin/zsh
if [ "$#" -ne 1 ] && [ ! -f "$HOME/.auth" ]; then
echo "Usage: ./bootstrap <DOTFILES_GITHUB_PERSONAL_ACCESS_TOKEN>"
exit 1
fi
DOTFILES_GITHUB_PERSONAL_ACCESS_TOKEN=$1
SETUP_HOMEBREW=false
detect_platform() {
UNAME=$(uname -a)
case "${UNAME}" in
*microsoft*) PLATFORM=wsl;;
*Darwin*) PLATFORM=macos;;
*Linux*) PLATFORM=linux;;
*) PLATFORM=unknown;;
esac
}
configure_shell_options() {
if [ -n "$ZSH_VERSION" ]; then
setopt extended_glob
elif [ -n "$BASH_VERSION" ];
then shopt -s extglob
fi
}
create_auth_dotfile() {
if [ ! -f "$HOME/.auth" ]; then
SETUP_HOMEBREW=true
cat > "$HOME/.auth" <<- OUT
export HOMEBREW_GITHUB_API_TOKEN=$DOTFILES_GITHUB_PERSONAL_ACCESS_TOKEN
OUT
fi
}
install_xcode_cli() {
if [ $PLATFORM = 'macos' ]; then
xcode-select -p 1>/dev/null
if [[ $? != 0 ]]; then
xcode-select --install
fi
fi
}
pip_install() {
pip install -r $HOME/.dotfiles/requirements.txt
}
winget_install() {
winget.exe install $(<$HOME/.dotfiles/wingetpkgs) --disable-interactivity --accept-package-agreements --accept-source-agreements
}
aptitude_install() {
sudo add-apt-repository ppa:wslutilities/wslu
curl -s https://ngrok-agent.s3.amazonaws.com/ngrok.asc | sudo tee /etc/apt/trusted.gpg.d/ngrok.asc >/dev/null && echo "deb https://ngrok-agent.s3.amazonaws.com buster main" | sudo tee /etc/apt/sources.list.d/ngrok.list
sudo add-apt-repository ppa:neovim-ppa/unstable -y
source /etc/os-release
wget -O $HOME/tmp/packages-microsoft-prod.deb https://packages.microsoft.com/config/ubuntu/$VERSION_ID/packages-microsoft-prod.deb
sudo dpkg -i $HOME/tmp/packages-microsoft-prod.deb
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
echo 'deb http://download.opensuse.org/repositories/shells:/zsh-users:/zsh-completions/xUbuntu_22.04/ /' | sudo tee /etc/apt/sources.list.d/shells:zsh-users:zsh-completions.list
curl -fsSL https://download.opensuse.org/repositories/shells:zsh-users:zsh-completions/xUbuntu_22.04/Release.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/shells_zsh-users_zsh-completions.gpg > /dev/null
sudo apt-get update
xargs sudo apt-get -y install < $HOME/.dotfiles/aptpkglist
}
manual_install() {
powershell.exe -C "Add-AppxPackage -Path $(wslpath -w $HOME/.dotfiles/msix)/affinity-photo-2.3.1.msix"
powershell.exe -C "Add-AppxPackage -Path $(wslpath -w $HOME/.dotfiles/msix)/affinity-designer-2.3.1.msix"
powershell.exe -C "Add-AppxPackage -Path $(wslpath -w $HOME/.dotfiles/msix)/affinity-publisher-2.3.1.msix"
wget https://dl.todesktop.com/210203cqcj00tw1/windows/nsis/x64 -O $HOME/.tmp/morgen.exe && chmod +x $HOME/tmp/morgen.exe && $HOME/tmp/morgen.exe
if [ ! -f /usr/local/bin/fx ]; then
curl https://fx.wtf/install.sh | sudo sh
fi
if [ ! -f $HOME/bin/unused ]; then
wget -O $HOME/tmp/unused.tar.gz https://github.com/unused-code/unused/releases/download/0.4.0/unused-0.4.0-x86_64-unknown-linux-musl.tar.gz
tar -xf $HOME/tmp/unused.tar.gz --strip-components=1 -C $HOME/bin
fi
if [ ! -d $HOME/.pure ]; then
git clone https://github.com/sindresorhus/pure.git "$HOME/.pure"
fi
chmod +x $HOME/bin/*
}
configure_gpg() {
echo "----------"
echo "INSTRUCTIONS:"
echo "1. Select pinentry-tty from the prompt"
echo "2. Complete the rest of the prompts"
echo "3. Run 'gpg --list-secret-keys --keyid-format LONG'"
echo "4. From the output line 'sec XXXXX/<LONG_KEY> XXXX-XX-XX [expires: XXXX-XX-XX]' copy <LINK_KEY>"
echo "5. Run 'gpg --armor --export <LONG_KEY> > gpg-key.txt'"
echo "6. Run 'git config --global user.signingkey <LONG_KEY>'"
echo "7. Add the contents of the file to GitHub"
echo "----------"
sudo update-alternatives --config pinentry
export GPG_TTY=$(tty)
gpg --gen-key
gpg-agent --daemon
}
configure_wsl_windows_crossover_paths() {
WINDOWS_PROFILE_PATH=$(wslpath "$(wslvar USERPROFILE)")
WINDOWS_USER_BIN_PATH="$(wslpath "$(wslvar USERPROFILE)")/bin"
WINDOWS_POWERSHELL_BIN_PATH="$(wslpath "$(wslvar WINDIR)")/System32/WindowsPowerShell/v1.0"
WINDOWS_APPS_PATH="$(wslpath "$(wslvar USERPROFILE)")/AppData/Local/Microsoft/WindowsApps"
WINDOWS_CROSSOVER_PATHS="$WINDOWS_USER_BIN_PATH:$WINDOWS_APPS_PATH:$WINDOWS_POWERSHELL_BIN_PATH"
sudo grep -qF "$WINDOWS_CROSSOVER_PATHS" /etc/zsh/zshenv || echo "export
PATH=\"$WINDOWS_CROSSOVER_PATHS:\$PATH\"" | sudo tee -a /etc/zsh/zshenv
}
install_homebrew() {
if [ $PLATFORM = 'macos' ]; then
which -s brew
if [[ $? != 0 ]]; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
fi
fi
}
install_homebrew_bundle() {
if [ $PLATFORM = 'macos' ]; then
if [[ $SETUP_HOMEBREW == true ]]; then
/opt/homebrew/bin/brew tap homebrew/bundle
/opt/homebrew/bin/brew bundle
fi
fi
}
copy_userprofile_files() {
WINDOWS_PROFILE_PATH=$(wslpath "$(wslvar USERPROFILE)")
cp $HOME/.dotfiles/userprofile/* "$WINDOWS_PROFILE_PATH"
}
symlink_dotfiles() {
ln -sfn $HOME/.dotfiles/.^(gitignore|git) $HOME/
mkdir -p $HOME/.config && ln -sfn $HOME/.dotfiles/_config/* $HOME/.config
}
configure_paths() {
if [ $PLATFORM = "macos" ]; then
sudo cp $HOME/.dotfiles/_etc_paths/* /etc/paths.d
elif [ $PLATFORM = "wsl" ]; then
PATH_AMENDMENT="$HOME/bin:$HOME/.asdf/bin"
sudo grep -qF "$PATH_AMENDMENT" /etc/zsh/zshenv || echo "export PATH=\"$PATH_AMENDMENT:\$PATH\"" | sudo tee -a /etc/zsh/zshenv
fi
}
configure_ssh() {
mkdir -p $HOME/.ssh && rsync -u $HOME/.dotfiles/_ssh/* $HOME/.ssh
}
make_workspace() {
mkdir -p $HOME/workspace/utils
}
make_user_bin() {
mkdir -p $HOME/bin
rsync -u $HOME/.dotfiles/bin/* $HOME/bin
}
restore_user_defaults() {
$HOME/.dotfiles/dx --restore-all
}
setup_vim() {
vim -c 'PlugUpdate' -c 'CocUpdate' -c 'q!' -c 'q!'
}
set_default_shell() {
if [ $PLATFORM = "macos" ]; then
sudo dscl . -create /Users/$USER UserShell /opt/homebrew/bin/zsh
elif [ $PLATFORM = "wsl" ]; then
chsh -s /usr/bin/zsh
fi
}
install_fonts() {
if [ $PLATFORM = "macos" ]; then
find . -name "*.[ot]tf" -type f -exec cp {} "$HOME/Library/Fonts" \;
elif [ $PLATFORM = "wsl" ]; then
echo "Installing fonts via Ubuntu & Powershell"
find . -name "*.[ot]tf" -type f -exec sudo cp {} "/usr/local/share/fonts" \;
sudo fc-cache -fv
powershell.exe -Command "Get-ChildItem -Path $(wslpath -w $HOME/.dotfiles/fonts)* -Recurse -include *.ttf,*.otf | % { (New-Object -ComObject Shell.Application).Namespace(0x14).CopyHere(\"$_.fullname\") }"
fi
}
configure_sublime_merge() {
if [ ! -L "/usr/local/bin/smerge" ]; then
sudo ln -s "/Applications/Sublime Merge.app/Contents/SharedSupport/bin/smerge" /usr/local/bin/smerge
fi
}
install_rosetta() {
sudo softwareupdate --install-rosetta
}
configure_asdf() {
if [ $PLATFORM = "wsl" ]; then
if [ ! -d "$HOME/.tmux/plugins/tpm" ]; then
# Not available via aptitude
git clone https://github.com/asdf-vm/asdf.git $HOME/.asdf --branch v0.13.1
fi
fi
asdf plugin-add yarn
asdf plugin-add python
asdf plugin add nodejs
asdf plugin add ruby
asdf plugin add rust
asdf plugin-add golang
asdf plugin-add pnpm
if [ $PLATFORM = 'macos' ]; then
export PATH=/opt/homebrew/bin:$PATH
export PATH="/opt/homebrew/sbin:$PATH"
export PATH="/opt/homebrew/opt/[email protected]/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/[email protected]/lib"
export CPPFLAGS="-I/opt/homebrew/opt/[email protected]/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/[email protected]/lib/pkgconfig"
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=/opt/homebrew/opt/[email protected]"
export RUBY_CFLAGS="-w"
fi
asdf install
}
install_tpm() {
if [ ! -d "$HOME/.tmux/plugins/tpm" ]; then
git clone https://github.com/tmux-plugins/tpm "$HOME/.tmux/plugins/tpm"
fi
}
bootstrap() {
mkdir -p $HOME/tmp
detect_platform
configure_shell_options
make_workspace
configure_paths
configure_ssh
install_fonts
create_auth_dotfile
symlink_dotfiles
make_user_bin
if [ $PLATFORM = "wsl" ]; then
copy_userprofile_files
winget_install
aptitude_install
manual_install
# configure_gpg
configure_wsl_windows_crossover_paths
elif [ $PLATFORM = "macos" ]; then
install_xcode_cli
install_rosetta
install_homebrew
install_homebrew_bundle
fi
pip_install
set_default_shell
if [ $PLATFORM = "macos" ]; then
restore_user_defaults
fi
setup_vim
configure_sublime_merge
configure_asdf
install_tpm
}
bootstrap