forked from mathiasbynens/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·314 lines (258 loc) · 7.87 KB
/
install.sh
File metadata and controls
executable file
·314 lines (258 loc) · 7.87 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
#!/bin/bash
# TODO help, opitonal force link
DOTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
exists() {
command -v $1 >/dev/null 2>&1
}
install_packages() {
echo install some basic command line utilities using apt
local packages=(
curl
git
ripgrep
rsync
tmux
tree
vifm
vim-athena
xsel
zsh
jq
dnsutils
bat
eza
duf
)
# vim-athena has +clipboard and +python3
sudo apt update
echo ${packages[*]} | xargs sudo apt install --assume-yes
}
install_dev_packages() {
echo install some packages for development using apt
local packages=(
build-essential
clang-format
clangd-9
exuberant-ctags
python3-dev
)
sudo apt update
echo ${packages[*]} | xargs sudo apt install --assume-yes
echo make clangd-9 the default clangd
sudo update-alternatives --install /usr/bin/clangd clangd /usr/bin/clangd-9 100
}
install_powerline_symbols() {
echo install powerline symbols
local FONT_DIR="~/.local/share/fonts"
local URL="https://github.com/powerline/powerline/raw/develop/font"
if [[ ! -e "${FONT_DIR}/PowerlineSymbols.otf" ]]; then
curl -fLo ${FONT_DIR}/PowerlineSymbols.otf ${URL}/PowerlineSymbols.otf --create-dirs
fc-cache -vf ${FONT_DIR}
curl -fLo ~/.config/fontconfig/conf.d/10-powerline-symbols.conf ${URL}/10-powerline-symbols.conf --create-dirs
fi
}
install_kubernetes_tools() {
if ! exists kubectl; then
echo install kubectl
local RELEASE=$(curl -L -s https://dl.k8s.io/release/stable.txt)
curl -LO "https://dl.k8s.io/release/$RELEASE/bin/linux/amd64/kubectl"
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/
else
echo kubectl found
fi
if ! exists helm; then
echo install helm
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
chmod 700 get_helm.sh
sudo ./get_helm.sh
rm ./get_helm.sh
else
echo helm found
fi
}
install_docker_in_wsl2() {
# tested with ubuntu 24.04
# System is up to date
sudo apt update && sudo apt upgrade -y
# Add Docker's official GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
# Install the docker repository
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Update package index
sudo apt update
# Install docker
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# No sudo for docker commands
sudo groupadd docker || true
sudo usermod -aG docker $USER
echo restart WSL2 to apply the changes
echo execute \"wsl --shutdown\" in cmd or pwsh
}
configure_vim() {
echo configure vim
ln -svf ${DOTDIR}/vimrc ~/.vimrc
# never overwrite existing .vimrc.local
if [ ! -f ~/.vimrc.local ]; then
cp ${DOTDIR}/vimrc.local ~/.vimrc.local
fi
echo install vim plugins
vim "+PlugInstall" "+qa"
}
configure_tmux() {
echo configure tmux
ln -svf ${DOTDIR}/tmux.conf ~/.tmux.conf
}
configure_git() {
echo configure git
ln -svf ${DOTDIR}/gitconfig.base ~/.gitconfig.base
if [ ! -e ~/.gitignore ]; then
ln -sv ${DOTDIR}/gitignore ~/.gitignore
fi
if [ ! -e ~/.git_template ]; then
ln -sv ${DOTDIR}/git_template ~/.git_template
else
echo could not create ~/.git_template/ as it already exists
fi
if [ ! -e ~/.gitmessage ]; then
echo creating empty .gitmessage file
touch ~/.gitmessage
fi
# never overwrite existing .gitconfig
if [ ! -f ~/.gitconfig ]; then
cp ${DOTDIR}/gitconfig ~/.gitconfig
echo please edit your user in ~/.gitconfig
fi
}
configure_zsh() {
echo configure zsh
echo download prompt
git clone https://github.com/sindresorhus/pure.git ~/.zsh/pure
echo download colors
curl -fLo ~/.zsh/dircolors/dircolors.ansi-dark https://raw.githubusercontent.com/seebi/dircolors-solarized/master/dircolors.ansi-dark --create-dirs
mkdir ~/.zsh/completions
mkdir ~/.zsh/cache
ln -svf ${DOTDIR}/zshrc ~/.zshrc
}
configure_vifm() {
echo configure vifm
local VIFM_CONFIG="${HOME}/.config/vifm"
mkdir -vp ${VIFM_CONFIG}/colors
ln -svf ${DOTDIR}/solarized-dark.vifm ${VIFM_CONFIG}/colors/solarized-dark.vifm
ln -svf ${DOTDIR}/vifmrc ${VIFM_CONFIG}/vifmrc
}
configure_kubernetes_tools() {
echo configure kubernetes tools
if [ -d ~/.zsh/completions ]; then
cd ~/.zsh/completions
kubectl completion zsh > _kubectl
helm completion zsh > _helm
fi
}
configure_github_cli() {
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update
sudo apt install gh
echo choose "GitHub.com", "HTTPS", "Authenticate Git with your GitHub credentials=YES" and "Login with a web browser"
gh auth login
}
help() {
echo "Install and configure the dotfiles
-h|--help show this help
--install_packages my dev packages
--powerline_symbols
--install_k8s install kubectl, helm
--install_all installs all above options
--install_docker_wsl2 installs docker in wsl2 (no docker desktop)
--configure_all configures all below options
--configure_vim
--configure_tmux
--configure_git
--configure_zsh
--configure_vifm
--configure_k8s
Without arguments, the default applies:
--install_packages
--install_k8s
--configure_all
"
}
array=()
if [[ "$#" -eq 0 ]]; then
array+=(1)
array+=(13)
array+=(6)
fi
while [[ "$#" -gt 0 ]]; do
case $1 in
-h|--help) help; exit 0;;
--install_packages) array+=(1);;
--powerline_symbols) array+=(3);;
--install_k8s) array+=(13);;
--install_all) array+=(5);;
--install_docker_wsl2) array+=(14);;
--configure_all) array+=(6);;
--configure_vim) array+=(7);;
--configure_tmux) array+=(8);;
--configure_git) array+=(9);;
--configure_zsh) array+=(10);;
--configure_vifm) array+=(11);;
--configure_k8s) array+=(12);;
*) echo "Unknown parameter passed: $1"; exit 1 ;;
esac
shift
done
for choice in "${array[@]}"; do
case "$choice" in
1)
install_packages
;;
3)
install_powerline_symbols
;;
13)
install_kubernetes_tools
;;
14)
install_docker_in_wsl2
;;
5)
install_packages
install_powerline_symbols
install_kubernetes_tools
;;
6)
configure_vim
configure_tmux
configure_git
configure_zsh
configure_vifm
configure_kubernetes_tools
;;
7)
configure_vim
;;
8)
configure_tmux
;;
9)
configure_git
;;
10)
configure_zsh
;;
11)
configure_vifm
;;
12)
configure_kubernetes_tools
;;
*)
echo invalid number $choice
;;
esac
done
unset array
unset DOTDIR
# vim:set et sw=4 ts=4 fdm=indent: