-
Notifications
You must be signed in to change notification settings - Fork 1
/
bootstrap.sh
254 lines (222 loc) · 6.52 KB
/
bootstrap.sh
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
#!/bin/bash
set -e
BASE_DIR=$(dirname "${0}")
source "${BASE_DIR}/utils.sh"
UNAME_OUTPUT="$(uname -s)"
case "${UNAME_OUTPUT}" in
Linux*) MACHINE_OS=Linux ;;
Darwin*) MACHINE_OS=MacOS ;;
*)
echo "Unknown OS: ${UNAME_OUTPUT}"
exit 1
;;
esac
BIN_DIR="${HOME}/bin"
LOCAL_DIR="${HOME}/.local"
LOCAL_BIN_DIR="${LOCAL_DIR}/bin"
if [ ${MACHINE_OS} = "MacOS" ]; then
FONTS_DIR="${HOME}/Library/Fonts"
elif [ ${MACHINE_OS} = "Linux" ]; then
FONTS_DIR="${HOME}/.local/share/fonts"
else
echo "Unknown OS: ${UNAME_OUTPUT}"
exit 1
fi
NVIM_CONFIG_DIR="${HOME}/.config/nvim"
MISE_CONFIG_DIR="${HOME}/.config/mise"
SYMLINKS=(
"${BASE_DIR}/git/gitattributes ${HOME}/.gitattributes"
"${BASE_DIR}/git/gitconfig ${HOME}/.gitconfig"
"${BASE_DIR}/git/gitignore ${HOME}/.gitignore"
"${BASE_DIR}/mise/config.toml ${HOME}/.config/mise/config.toml"
"${BASE_DIR}/python/pdbrc.py ${HOME}/.pdbrc.py"
"${BASE_DIR}/tmux/tmux.conf ${HOME}/.tmux.conf"
"${BASE_DIR}/vim ${HOME}/.config/nvim"
"${BASE_DIR}/kitty ${HOME}/.config/kitty"
"${BASE_DIR}/zsh/zshrc ${HOME}/.zshrc"
"${BASE_DIR}/zsh/zsh_plugins.txt ${HOME}/.zsh_plugins.txt"
)
[ -d "${BASE_DIR}" ] || exit 1
mkdir -p "${BIN_DIR}"
mkdir -p "${LOCAL_BIN_DIR}"
mkdir -p "${FONTS_DIR}"
mkdir -p "${MISE_CONFIG_DIR}"
function _system {
info "updating the system"
if [ ${MACHINE_OS} = "MacOS" ]; then
if ! which brew >/dev/null 2>&1; then
echo "brew not found"
exit 1
fi
BREW_PACKAGES=$(tr '\n' ' ' <"${BASE_DIR}/packages/brew-packages")
# shellcheck disable=2086
brew install ${BREW_PACKAGES}
brew update
brew upgrade
brew autoremove
brew cleanup
elif [ ${MACHINE_OS} = "Linux" ]; then
(
APT_PACKAGES=$(tr '\n' ' ' <"${BASE_DIR}/packages/apt-packages")
EXTRA_OPTS="-t unstable"
sudo apt update --list-cleanup
sudo apt dist-upgrade --purge
# shellcheck disable=2086
sudo apt dist-upgrade --purge ${EXTRA_OPTS}
# shellcheck disable=2086
sudo apt build-dep python3 ${EXTRA_OPTS}
# shellcheck disable=2086
sudo apt install --purge ${EXTRA_OPTS} ${APT_PACKAGES}
sudo flatpak update
sudo flatpak uninstall --unused
sudo apt autoremove --purge
sudo apt clean
) || true
else
echo "Unknown OS: ${UNAME_OUTPUT}"
exit 1
fi
}
function _patches {
info "patching files"
if [ ${MACHINE_OS} = "MacOS" ]; then
:
elif [ ${MACHINE_OS} = "Linux" ]; then
if ! grep "force-dark-mode" /usr/share/applications/google-chrome.desktop; then
sudo sed -i \
's;/usr/bin/google-chrome-stable;/usr/bin/google-chrome-stable --force-dark-mode;g' \
/usr/share/applications/google-chrome.desktop
fi
else
echo "Unknown OS: ${UNAME_OUTPUT}"
exit 1
fi
}
function _symlinks {
info "updating symlinks"
for FILE in "${SYMLINKS[@]}"; do
# shellcheck disable=2086
create_symlink ${FILE}
done
}
function _mise {
info "installing mise"
if [ ${MACHINE_OS} = "MacOS" ]; then
MISE_BINARY="/opt/homebrew/bin/mise"
elif [ ${MACHINE_OS} = "Linux" ]; then
MISE_BINARY="${HOME}/.local/bin/mise"
if [ ! -f "${MISE_BINARY}" ]; then
curl https://mise.run | sh
fi
else
echo "Unknown OS: ${UNAME_OUTPUT}"
exit 1
fi
eval "$("${MISE_BINARY}" activate bash)"
today=$(date +%Y-%m-%d)
marker_file="${HOME}/.cache/mise-last-cache-clear"
if [ -f "$marker_file" ]; then
last_run_date=$(cat "$marker_file")
if [ "$last_run_date" == "$today" ]; then
echo "Mise cache already cleared today. Skipping..."
else
"${MISE_BINARY}" cache clear
echo "$today" >"$marker_file"
fi
else
"${MISE_BINARY}" cache clear
echo "$today" >"$marker_file"
fi
if [ ${MACHINE_OS} = "Linux" ]; then
"${MISE_BINARY}" self-update || true
fi
"${MISE_BINARY}" plugins update -y || true
"${MISE_BINARY}" install -y || true
"${MISE_BINARY}" upgrade -y || true
"${MISE_BINARY}" prune -y
}
function _fonts {
info "installing fonts"
download_file \
"${FONTS_DIR}/codicon.ttf" \
https://github.com/microsoft/vscode-codicons/blob/main/dist/codicon.ttf?raw=true
download_file \
"${FONTS_DIR}/Hack Regular Nerd Font Complete.ttf" \
https://github.com/ryanoasis/nerd-fonts/blob/master/patched-fonts/Hack/Regular/HackNerdFont-Regular.ttf?raw=true
download_file \
"${FONTS_DIR}/Inconsolata Nerd Font Complete.otf" \
https://github.com/ryanoasis/nerd-fonts/blob/master/patched-fonts/Inconsolata/InconsolataNerdFont-Regular.ttf?raw=true
download_file \
"${FONTS_DIR}/Fira Code Regular Nerd Font Complete.ttf" \
https://github.com/ryanoasis/nerd-fonts/blob/master/patched-fonts/FiraCode/Regular/FiraCodeNerdFont-Regular.ttf?raw=true
download_file \
"${FONTS_DIR}/JetBrains Mono Nerd Font Complete.ttf" \
https://github.com/ryanoasis/nerd-fonts/blob/master/patched-fonts/JetBrainsMono/NoLigatures/Regular/JetBrainsMonoNLNerdFont-Regular.ttf?raw=true
if [ ${MACHINE_OS} = "Linux" ]; then
if [ "$(gsettings get org.gnome.desktop.interface monospace-font-name)" != "'Hack Nerd Font 11'" ]; then
gsettings set org.gnome.desktop.interface monospace-font-name 'Hack Nerd Font 11'
fi
fi
}
function _gh {
gh extension install github/gh-copilot
gh extension upgrade --all
}
function _zsh {
info "installing zsh plugins"
zsh -i -c "antidote update"
}
function _neovim {
info "installing neovim"
if [ ${MACHINE_OS} = "MacOS" ]; then
brew install --HEAD utf8proc
brew upgrade utf8proc --fetch-HEAD
brew install --HEAD neovim
brew upgrade neovim --fetch-HEAD
elif [ ${MACHINE_OS} = "Linux" ]; then
download_executable \
"${BIN_DIR}/nvim" \
https://github.com/neovim/neovim/releases/download/nightly/nvim.appimage
else
echo "Unknown OS: ${UNAME_OUTPUT}"
exit 1
fi
info "installing vim-spell"
if [ ! -f "${NVIM_CONFIG_DIR}/spell/.done" ]; then
(
cd "${NVIM_CONFIG_DIR}/spell"
wget -N -nv ftp://ftp.vim.org/pub/vim/runtime/spell/en.* --timeout=5 || exit 1
wget -N -nv ftp://ftp.vim.org/pub/vim/runtime/spell/pt.* --timeout=5 || exit 1
touch .done
)
fi
}
function _mise-reshim {
info "reshimming mise"
if [ ${MACHINE_OS} = "MacOS" ]; then
MISE_BINARY="/opt/homebrew/bin/mise"
elif [ ${MACHINE_OS} = "Linux" ]; then
MISE_BINARY="${HOME}/.local/bin/mise"
else
echo "Unknown OS: ${UNAME_OUTPUT}"
exit 1
fi
"${MISE_BINARY}" reshim
}
function _ {
(
cd "${HOME}"
_system
_patches
_neovim
_symlinks
_fonts
_zsh
_mise
_gh
_mise-reshim
)
}
echo
set -x
"_${1}" "$@"