-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathupdate.sh
More file actions
executable file
·427 lines (389 loc) · 11.9 KB
/
Copy pathupdate.sh
File metadata and controls
executable file
·427 lines (389 loc) · 11.9 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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
#!/usr/bin/env bash
#
# Corey Goldberg (https://github.com/cgoldberg)
#
# update.sh - install or update local configs and scripts from github
#
# install dependencies for full functionality:
#
# - all platforms:
# - bat (cargo install bat, scoop install bat)
# - delta (cargo install git-delta, scoop install delta)
# - deno (curl -fsSL https://deno.land/install.sh | sh, scoop install deno)
# - exiftool (sudo apt install exiftool, scoop install exiftool)
# - eza (cargo install eza, scoop install eza)
# - fd (cargo install fd-find, scoop install fd)
# - ffmpeg (sudo apt install ffmpeg, scoop install ffmpeg)
# - gdu (https://github.com/dundee/gdu, scoop install gdu)
# - gh (https://github.com/cli/cli, scoop install gh)
# - git-who (https://github.com/sinclairtarget/git-who)
# - java (sudo apt install default-jdk, scoop install openjdk)
# - jq (sudo apt install jq, scoop install jq)
# - magick (sudo apt install imagemagick, scoop install imagemagick)
# - pandoc (https://github.com/jgm/pandoc, scoop install pandoc)
# - perl (sudo apt install perl, scoop install perl)
# - pipx (pip install --user pipx)
# - pre-commit (pipx-install pre-commit)
# - python3 (sudo apt install python3, scoop install python)
# - pyupgrade (pipx-install pyupgrade)
# - refurb (pipx-install refurb)
# - rg (cargo install ripgrep --features pcre2, scoop install ripgrep)
# - ruby (sudo apt install ruby, scoop install ruby)
# - shellcheck (sudo apt install shellcheck, scoop install shellcheck)
# - subl (https://sublimetext.com/docs/linux_repositories.html)
# - tickrs (cargo install tickrs, scoop install tickrs)
# - yt-dlp (pipx-install yt-dlp[default,curl-cffi,deno,secretstorage])
#
# - linux only:
# - bandwhich (cargo install bandwhich, then `sudo setcap cap_sys_ptrace,cap_dac_read_search,cap_net_raw,cap_net_admin+ep ~/.cargo/bin/bandwhich`)
# - bmon (sudo apt install bmon)
# - btop (https://github.com/aristocratos/btop - download/unarchive, then: `sudo make install && sudo make setcap`)
# - cargo (https://rustup.rs)
# - cargo-cache (cargo install cargo-cache)
# - cargo-install-update (cargo install cargo-update)
# - flatpak (sudo apt install flatpak)
# - gcc (sudo apt install build-essential)
# - githubtakeout (pipx-install githubtakeout)
# - gnome-terminal (sudo apt install gnome-terminal)
# - go (https://go.dev/doc/install)
# - google_drive_export (pipx install google-drive-export)
# - mpv (sudo apt install mpv)
# - notify-send (sudo apt install libnotify-bin)
# - iostat (sudo apt install sysstat)
# - ncal (sudo apt install ncal)
# - pyenv (https://github.com/pyenv/pyenv)
# - rsync (sudo apt install rsync)
# - rustup (https://rustup.rs)
# - toilet (sudo apt install toilet)
#
# - windows only:
# - alacritty (scoop install alacritty)
BOLD="\e[1m"
GREEN="\e[32m"
RED="\e[31m"
RESET="\e[0m"
DOTFILES_HOME="${HOME}/code/dotfiles"
BIN_DIR="${HOME}/bin"
REQUIREMENTS=(
"git"
"curl"
)
DEPENDENCIES=(
"bat"
"delta"
"exiftool"
"deno"
"eza"
"fd"
"ffmpeg"
"gdu"
"gh"
"git-who"
"java"
"jq"
"magick"
"pandoc"
"perl"
"pipx"
"pre-commit"
"python3"
"pyupgrade"
"refurb"
"rg"
"ruby"
"shellcheck"
"subl"
"tickrs"
"yt-dlp"
)
DEPENDENCIES_LINUX=(
"bandwhich"
"bmon"
"btop"
"cargo"
"cargo-cache"
"cargo-install-update"
"flatpak"
"githubtakeout"
"gnome-terminal"
"gcc"
"go"
"google_drive_export"
"iostat"
"mpv"
"ncal"
"notify-send"
"pyenv"
"rsync"
"rustup"
"toilet"
)
DEPENDENCIES_WINDOWS=(
"alacritty"
)
CONFIGS=(
".bashrc"
".bashrc_squeezebox"
".bash_logout"
".profile"
".gitconfig"
)
LINUX_CONFIGS=(
".bashrc_linux"
".bashrc_linux_selenium"
)
WIN_CONFIGS=(
".bashrc_windows"
".gitconfig_win"
".minttyrc"
)
SCRIPTS=(
"./bin/colors"
"./bin/git-pc"
"./bin/prettyping"
)
LINUX_SCRIPTS=(
"./bin/backup-gdrive"
"./bin/backup-github"
"./bin/backup-nas-to-external"
"./bin/backup-nas-to-nas"
"./bin/mount-bitz"
"./bin/mount-bytez"
"./bin/now"
"./bin/random-wallpaper"
"./bin/squeezebox-function"
"./bin/sync-nas"
"./bin/sysinfo"
"./bin/test-data-xfer-nas-to-nas"
"./bin/test-data-xfer-local-to-nas"
"./bin/toggle-audio-sink"
"./bin/verify-backup-nas"
)
GIT_SCRIPTS=(
"git-branches"
"git-clean-untracked"
"git-contribs"
"git-info"
"git-obliterate-repo"
"git-prs"
"git-score"
"git-stat"
"git-sync"
"git-syncrepo"
"git-track-branches"
"git-whack-branches"
)
err() {
printf '%b%b✗%b %b%s%b\n' \
"${BOLD}" "${RED}" "${RESET}" "${BOLD}" "$*" "${RESET}" >&2
}
ok() {
printf '%b%b✓%b %b%s%b\n' \
"${BOLD}" "${GREEN}" "${RESET}" "${BOLD}" "$*" "${RESET}" >&2
}
die() {
err "$*"
exit 1
}
is_windows() {
if [[ "${OSTYPE}" != "msys" && "${OSTYPE}" != "cygwin" ]]; then
return 1
fi
}
is_linux() {
if [[ "${OSTYPE}" != "linux"* ]]; then
return 1
fi
}
check-programs() {
local programs=("$@")
unset check_failed
for prog in "${programs[@]}"; do
if ! type "${prog}" >/dev/null 2>&1; then
err "${prog} is not installed"
check_failed="true"
else
ok "${prog} is installed"
fi
done
}
check-requirements() {
if ! is_windows && ! is_linux; then
die "fatal: unknown operating system"
fi
check-programs "${REQUIREMENTS[@]}"
if [ -n "${check_failed}" ]; then
echo
die "fatal: missing requirement"
fi
}
check-dependencies() {
check-programs "${DEPENDENCIES[@]}"
if [ -n "${check_failed}" ]; then
check_deps_failed="true"
fi
if is_linux; then
check-programs "${DEPENDENCIES_LINUX[@]}"
if [ -n "${check_failed}" ]; then
check_linux_deps_failed="true"
fi
fi
if is_windows; then
check-programs "${DEPENDENCIES_WINDOWS[@]}"
if [ -n "${check_failed}" ]; then
check_win_deps_failed="true"
fi
fi
}
# -----------------------------------------------------------------------------
if [ ! -d "${DOTFILES_HOME}" ]; then
die "fatal: can't find local dotfiles repo"
fi
check-requirements
check-dependencies
echo
mkdir --parents "${BIN_DIR}"
cd "${DOTFILES_HOME}"
current_branch=$(git branch --show-current)
default_branch=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's/.*\///')
git checkout "${default_branch}" >/dev/null 2>&1
echo "syncing local branches in ${DOTFILES_HOME} from github..."
git sync
echo
# --------------------------------- CONFIGS -----------------------------------
if is_windows; then
echo "copying windows configs from dotfiles repo to ${HOME}..."
for config in "${WIN_CONFIGS[@]}"; do
echo -e " copying: ${config}"
cp "${config}" "${HOME}"
done
echo
alacritty_dir="${APPDATA//\\//}/alacritty"
alacritty_config="./alacritty/alacritty.toml"
echo "copying alacritty config from dotfiles repo to ${alacritty_dir}..."
mkdir --parents "${alacritty_dir}"
echo -e " copying: ${alacritty_config}"
cp "${alacritty_config}" "${alacritty_dir}"
echo
fi
if is_linux; then
echo "copying linux configs from dotfiles repo to ${HOME}..."
for config in "${LINUX_CONFIGS[@]}"; do
echo -e " copying: ${config}"
cp "${config}" "${HOME}"
done
echo
cargo_dir="${HOME}/.cargo"
cargo_config="./cargo/config.toml"
echo "copying cargo config from dotfiles repo to ${cargo_dir}..."
mkdir --parents "${cargo_dir}"
echo -e " copying: ${cargo_config}"
cp "${cargo_config}" "${cargo_dir}"
echo
btop_dir="${HOME}/.config/btop"
btop_config="./btop/btop.conf"
echo "copying btop config from dotfiles repo to ${btop_dir}..."
mkdir --parents "${btop_dir}"
echo -e " copying: ${btop_config}"
cp "${btop_config}" "${btop_dir}"
echo
sublime_dir="${HOME}/.config/sublime-text/Packages/User"
sublime_config="./sublime/Preferences.sublime-settings"
echo "copying sublime config from dotfiles repo to ${sublime_dir}..."
mkdir --parents "${sublime_dir}"
echo -e " copying: ${sublime_config}"
cp "${sublime_config}" "${sublime_dir}"
echo
gnome_terminal_config="gnome-terminal.properties"
echo "setting gnome-terminal dconf config from dotfiles repo..."
echo -e " loading: ${gnome_terminal_config}"
dconf load /org/gnome/terminal/ < "./debian/dconf/${gnome_terminal_config}"
echo
gnome_media_keybindings_config="gnome-media-keybindings.properties"
echo "setting media keybindings dconf config from dotfiles repo..."
echo -e " loading: ${gnome_media_keybindings_config}"
dconf load /org/gnome/settings-daemon/plugins/media-keys/ < "./debian/dconf/${gnome_media_keybindings_config}"
echo
gnome_wm_keybindings_config="gnome-wm-keybindings.properties"
echo "setting window manager keybindings dconf config from dotfiles repo..."
echo -e " loading: ${gnome_wm_keybindings_config}"
dconf load /org/gnome/desktop/wm/keybindings/ < "./debian/dconf/${gnome_wm_keybindings_config}"
echo
fonts_dir="${HOME}/.local/share/fonts"
echo "copying fonts from dotfiles repo to ${fonts_dir}..."
mkdir --parents "${fonts_dir}"
for ttf in ./debian/fonts/*.ttf; do
echo -e " copying: ${ttf}"
cp "${ttf}" "${fonts_dir}"
done
echo "rebuilding font cache..."
fc-cache -f "${fonts_dir}"
echo
fi
echo "copying configs from dotfiles repo to ${HOME}..."
for config in "${CONFIGS[@]}"; do
echo -e " copying: ${config}"
cp "${config}" "${HOME}"
done
echo
git_hooks_dir="${HOME}/.git-hooks"
pre_commit_git_hook="./pre-commit/pre-commit"
echo "copying global pre-commit hook from dotfiles repo to ${git_hooks_dir}..."
mkdir --parents "${git_hooks_dir}"
echo -e " copying: ${pre_commit_git_hook}"
cp "${pre_commit_git_hook}" "${git_hooks_dir}"
echo
pre_commit_config_dir="${HOME}/.config/pre-commit"
pre_commit_config="./pre-commit/global-pre-commit-config.yaml"
echo "copying pre-commit config from dotfiles repo to ${pre_commit_config_dir}..."
mkdir --parents "${pre_commit_config_dir}"
echo -e " copying: ${pre_commit_config}"
cp "${pre_commit_config}" "${pre_commit_config_dir}"
echo
pandoc_template_dir="${HOME}/.pandoc"
pandoc_templates=("./pandoc/template.html" "./pandoc/template.css")
echo "copying pandoc templates from dotfiles repo to ${pandoc_template_dir}..."
mkdir --parents "${pandoc_template_dir}"
for template in "${pandoc_templates[@]}"; do
echo -e " copying: ${template}"
cp "${template}" "${pandoc_template_dir}"
done
echo
# --------------------------------- SCRIPTS -----------------------------------
echo "copying scripts from dotfiles repo to ${BIN_DIR}..."
for script in "${SCRIPTS[@]}"; do
echo -e " copying: ${script}"
cp "${script}" "${BIN_DIR}"
done
echo
if is_linux; then
echo "copying linux scripts from dotfiles repo to ${BIN_DIR}..."
for script in "${LINUX_SCRIPTS[@]}"; do
echo -e " copying: ${script}"
cp "${script}" "${BIN_DIR}"
done
echo
fi
echo "downloading git scripts from github to ${BIN_DIR}..."
for script in "${GIT_SCRIPTS[@]}"; do
url="https://raw.githubusercontent.com/cgoldberg/git-scripts/refs/heads/main/${script}"
echo -e " downloading: ./${BIN_DIR##*/}/${script}"
curl -fsS --output "${BIN_DIR}/${script}" "${url}"
chmod +x "${BIN_DIR}/${script}"
if is_windows; then
unix2dos "${BIN_DIR}/${script}" >/dev/null 2>&1
fi
done
echo
# -----------------------------------------------------------------------------
git checkout "${current_branch}" >/dev/null 2>&1
if \
[ -n "${check_deps_failed}" ] || \
[ -n "${check_linux_deps_failed}" ] || \
[ -n "${check_win_deps_failed}" ]; then
err "missing dependency"
else
ok "all dependencies installed"
fi
echo
ok "done updating configs and scripts"