-
Notifications
You must be signed in to change notification settings - Fork 2
/
init
executable file
·396 lines (336 loc) · 9.74 KB
/
init
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
#!/bin/bash
set -euo pipefail
#
# bootstrap init script
#
# Usage:
# * For a brand new machine, clone the bootstrap repo and launch this script
# * Any time the clone is updated, re-run this script
#
# If you'd like to symlink the dot files to a location other than $HOME,
# export the variable BOOTSTRAP_TARGET_DIR before calling this script.
#
# If you'd like to use a shell other than the /usr/local/bin/mksh,
# export the variable DESIRED_SHELL before calling this script.
#
bootstrap_dir=$(dirname "${BASH_SOURCE}")
cd $bootstrap_dir
bootstrap_dir=$(pwd)
target_dir=${BOOTSTRAP_TARGET_DIR:-$HOME}
DESIRED_SHELL=${DESIRED_SHELL:-}
# --- --- --- --- --- --- ---
# helper functions
# --- --- --- --- --- --- ---
function running_mac_os() {
[[ "$OSTYPE" == "darwin"* ]] && return
false
}
function running_debian() {
(command -v apt-get >/dev/null) && return
false
}
# --- --- --- --- --- --- ---
# create dot file symlinks
# --- --- --- --- --- --- ---
echo "Symlinking dot files..."
function process_dot_dir() {
dir=$1
shopt -s dotglob
for f in "$dir"/*; do
# for dirs beneath ~/.config, symlink the entire dir
if [[ -d "$f" ]] && [[ $dir != */.config ]]; then
process_dot_dir "$f"
continue
fi
target="$target_dir/${f//$bootstrap_dir\/dots\//}"
if [[ -e "$target" ]]; then
echo "$target already exists - skipping"
continue
else
if [[ "${target%/*}" != "$target_dir" ]]; then
cmd="mkdir -p ${target%/*}"
echo "$cmd"
eval "$cmd"
fi
cmd="ln -s \"$f\" \"$target\""
echo "$cmd"
eval "$cmd"
fi
done
shopt -u dotglob
}
process_dot_dir "$bootstrap_dir/dots"
# --- --- --- --- --- --- ---
# fonts
# --- --- --- --- --- --- ---
if running_mac_os; then
echo "Installing fonts..."
for f in "$bootstrap_dir/fonts"/*; do
target="$target_dir/Library/Fonts/${f//$bootstrap_dir\/fonts\//}"
if [[ -e "$target" ]]; then
echo "$target already exists - skipping"
continue
else
echo "Installing font $f..."
cmd="cp \"$f\" \"$target\""
echo "$cmd"
eval "$cmd"
fi
done
elif running_debian; then
fonts_link="$target_dir/.fonts"
if [[ -e "$fonts_link" ]]; then
echo "Fonts already linked to at $fonts_link - skipping"
else
ln -s "$bootstrap_dir/fonts" "$fonts_link"
echo "Fonts linked to at $fonts_link"
fc-cache
echo "Font cache cleared"
fi
fi
# --- --- --- --- --- --- ---
# set desired os x behavior
# --- --- --- --- --- --- ---
if running_mac_os; then
echo "Setting up macOS behavior preferences..."
$target_dir/bin/macos_settings
fi
# --- --- --- --- --- --- ---
# install and run Homebrew
# --- --- --- --- --- --- ---
if running_mac_os; then
echo "Installing and running Homebrew..."
$target_dir/bin/brewupdate
fi
# --- --- --- --- --- --- --- ---
# install desired Linux packages
# --- --- --- --- --- --- --- ---
if running_debian; then
sudo apt-get install ninja-build gettext libtool libtool-bin autoconf automake cmake g++ pkg-config unzip xclip mksh rclone kitty cros-guest-tools x11-apps libglfw3 libglfw3-dev alacritty
fi
# --- --- --- --- --- --- ---
# set the desired shell
# --- --- --- --- --- --- ---
function existing_shell() {
if running_mac_os; then
finger $USER|grep -o 'Shell: .*'|cut -c 8-
elif running_debian; then
cat /etc/passwd|grep "^$USER:"|sed 's/^.*:\(.*\)/\1/'
fi
}
if [[ ! -z "$DESIRED_SHELL" ]]; then
if [[ ! -f "$DESIRED_SHELL" ]]; then
echo "Error: desired shell $DESIRED_SHELL does not exist!"
exit -1
fi
if $(grep -q $DESIRED_SHELL /etc/shells); then
echo "Desired shell $DESIRED_SHELL already exists in /etc/shells"
else
echo "Appending $DESIRED_SHELL to /etc/shells..."
echo $DESIRED_SHELL|sudo tee -a /etc/shells>/dev/null;
fi
if [[ "$(existing_shell)" == "$DESIRED_SHELL" ]]; then
echo "User $USER is already set to use desired shell $DESIRED_SHELL"
else
echo "Changing shell for user $USER to $DESIRED_SHELL..."
if running_debian; then
sudo chsh -s $DESIRED_SHELL $USER
else
chsh -s $DESIRED_SHELL
fi
fi
fi
# --- --- --- --- --- --- ---
# python enhancements
# --- --- --- --- --- --- ---
# install pip3
if (command -v pip3 >/dev/null); then
echo "Python pip3 already exists"
else
echo "installing Python pip..."
if running_debian; then
sudo apt-get install python3-pip
else
echo "Error: don't know how to install pip3 on this OS!"
exit -1
fi
fi
# TODO: python3 only solution?
# install PIL via Pillow - needed for Ranger image previews
# python -c "import PIL" 2>/dev/null
# if [[ $? -ne 0 ]]; then
# echo "Install Python module PIL (via pillow)..."
# sudo /usr/local/bin/pip install pillow
# else
# echo "Python module pillow already exists"
# fi
# install neovim-remote
if (command -v nvr >/dev/null); then
echo "neovim-remote already installed"
else
echo "Installing neovim-remote..."
if running_mac_os; then
# pip3 install --user --upgrade neovim-remote
echo "Skipping neovim-remote installation on macos, use 'brew install neovim-remote' instead"
else
sudo pip3 install --upgrade --break-system-packages neovim-remote
fi
fi
# broken. should be vim-vint?
# if (command -v vint >/dev/null); then
# echo "vint already installed"
# else
# echo "Installing vint..."
# /usr/local/bin/pip3 install --user --upgrade vint
# fi
# --- --- --- --- --- --- ---
# Neovim
# --- --- --- --- --- --- ---
if running_debian; then
if (command -v nvim >/dev/null); then
echo "Neovim is already installed"
else
echo 'Building and installing Neovim...'
rm -rf neovim
git clone https://github.com/neovim/neovim
cd neovim
make CMAKE_BUILD_TYPE=Release
sudo make install
cd "$bootstrap_dir"
fi
fi
# Packer content commented out in favor of lazy.nvim...
# install or update Neovim plugins
# echo "Installing / updating Neovim plugins..."
# \nvim --headless -c 'autocmd User PackerComplete quitall' -c 'PackerSync'
# --- --- --- --- --- --- ---
# Rust
# --- --- --- --- --- --- ---
if (command -v cargo >/dev/null); then
echo "rust is already installed - running rustup"
rustup update stable
else
echo "Installing rust..."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs |sh
wget https://sh.rustup.rs -O rustup-init.sh
sh rustup-init.sh --no-modify-path -y
fi
[[ -e "$HOME/.cargo/env" ]] && source "$HOME/.cargo/env"
rustfmt --version 2>/dev/null
if [[ $? -ne 0 ]]; then
rustup component add rustfmt
else
echo 'rustfmt is already installed'
fi
cargo clippy --version 2>/dev/null
if [[ $? -ne 0 ]]; then
rustup component add clippy
else
echo 'clippy is already installed'
fi
# racer
# rustup install nightly
# git clone https://github.com/racer-rust/racer.git
# cd racer
# cargo +nightly build --release
# cp target/release/racer ~/bin/
# rustup component add rust-src
# --- --- --- --- --- --- ---
# Kitty
# --- --- --- --- --- --- ---
if [[ ! -e "${target_dir}/.config/kitty/kitty.conf" ]]; then
if running_debian; then
ln -s "${target_dir}/.config/kitty/kitty_debian.conf" "${target_dir}/.config/kitty/kitty.conf"
elif running_mac_os; then
ln -s "${target_dir}/.config/kitty/kitty_macos.conf" "${target_dir}/.config/kitty/kitty.conf"
else
echo "Error: unable to prep Kitty for this operating system!"
exit -1
fi
fi
# --- --- --- --- --- --- ---
# C++ Matrix
# --- --- --- --- --- --- ---
cxxmatrix_location="${target_dir}/bin/cxxmatrix"
if [[ -e "$cxxmatrix_location" ]]; then
echo "C++ Matrix already installed"
else
git clone https://github.com/akinomyoga/cxxmatrix.git
cd cxxmatrix
make
mv cxxmatrix "$cxxmatrix_location"
fi
# --- --- --- --- --- --- ---
# Postgres.app
# --- --- --- --- --- --- ---
# commented out - use the Homebrew formula instead
# if [[ -e "/Applications/Postgres.app" ]]; then
# echo "Postgres.app already installed"
# else
# rm -f Postgres.dmg
# wget --no-check-certificate https://github.com/PostgresApp/PostgresApp/releases/download/v2.4.2/Postgres-2.4.2-13.dmg -O Postgres.dmg
# open Postgres.dmg
# echo 'Hit a key after install Postgres.app to /Applications'
# read -n 1 any_key
# echo -e "export PATH=/Applications/Postgres.app/Contents/Versions/latest/bin:\$PATH\n" >> ~/.mkshrc_private
# fi
# --- --- --- --- --- --- ---
# Debian only from here on out
# --- --- --- --- --- --- ---
! running_debian && exit
# --- --- --- --- --- --- ---
# FZF
# --- --- --- --- --- --- ---
if (command -v fzf >/dev/null); then
echo "fzf is already installed"
else
echo 'Installing fzf...'
rm -rf fzf
git clone --depth 1 https://github.com/junegunn/fzf.git
cd fzf
./install --bin
sudo cp bin/fzf /usr/local/bin/fzf
cd "$bootstrap_dir"
fi
# --- --- --- --- --- --- ---
# Ripgrep
# --- --- --- --- --- --- ---
if (command -v rg >/dev/null); then
echo "Ripgrep is already installed"
else
echo 'Installing ripgrep...'
rm -rf ripgrep
git clone https://github.com/BurntSushi/ripgrep
cd ripgrep
cargo build --release
sudo cp target/release/rg /usr/local/bin/rg
cd "$bootstrap_dir"
fi
# --- --- --- --- --- --- ---
# fd
# --- --- --- --- --- --- ---
if (command -v fd >/dev/null); then
echo "fd is already installed"
else
echo 'Installing fd...'
rm -rf fd
git clone https://github.com/sharkdp/fd
cd fd
cargo build --release
sudo cp target/release/fd /usr/local/bin/fd
cd "$bootstrap_dir"
fi
# --- --- --- --- --- --- ---
# Google Drive
# --- --- --- --- --- --- ---
gdrive='/mnt/chromeos/GoogleDrive/MyDrive/private'
gdrive_link="$target_dir/.gdrive"
if [[ -e "$gdrive_link" ]]; then
echo "$gdrive_link already exists - skipping"
elif [[ -e "$gdrive" ]]; then
ln -s "$gdrive" "$gdrive_link"
ln -s "${gdrive_link}/.netrc" ~/.netrc
ln -s "${gdrive_link}/.mkshrc_private" ~/.mkshrc_private
else
echo "WARNING: Google Drive private share not found at ${gdrive}!"
fi