-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
install
executable file
·486 lines (402 loc) · 12.8 KB
/
install
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
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
#!/bin/bash
# debug
# set -x
NVIM_HOME=$HOME/.nvim
OS="$(uname -s)"
IS_APT=0
IS_DNF=0
IS_PACMAN=0
IS_BREW=0
# utils {
info() {
local content="$*"
printf "[lin.nvim] - %s\n" "$content"
}
err() {
local content="$*"
info "error! $content"
}
skip_info() {
local old="$IFS"
IFS='/'
local target="'$*'"
info "$target already exist, skip..."
IFS=$old
}
backup() {
local src=$1
if [[ -f "$src" || -d "$src" ]]; then
local target=$src.$(date +"%Y-%m-%d.%H-%M-%S")
info "backup '$src' to '$target'"
mv $src $target
fi
}
install() {
local command="$1"
local target="$2"
if ! type "$target" >/dev/null 2>&1; then
info "install '$target' with command: '$command'"
eval "$command"
else
skip_info $target
fi
}
install_func() {
local func="$1"
local target="$2"
if ! type "$target" >/dev/null 2>&1; then
info "install '$target' with function: '$func'"
eval "$func"
else
skip_info $target
fi
}
latest_github_release_tag() {
local org="$1"
local repo="$2"
local uri="https://github.com/$org/$repo/releases/latest"
curl -s -f -L $uri | grep "href=\"/$org/$repo/releases/tag" | grep -Eo 'href="/[a-zA-Z0-9#~.*,/!?=+&_%:-]*"' | head -n 1 | cut -d '"' -f2 | cut -d "/" -f6
}
install_linux_ctags() {
local CTAGS_HOME=$NVIM_HOME/universal-ctags
local org="universal-ctags"
local repo="ctags"
local CTAGS_VERSION=$(latest_github_release_tag $org $repo)
info "install universal-ctags($CTAGS_VERSION) from source"
cd $NVIM_HOME
if [ ! -d $CTAGS_HOME ]; then
git clone https://github.com/universal-ctags/ctags.git $CTAGS_HOME
fi
cd $CTAGS_HOME
git checkout $CTAGS_VERSION
./autogen.sh
./configure
make
sudo make install
}
# }
# apt: ubuntu/debian {
install_apt_nvim() {
info "install 'nvim'(appimage) from github.com"
sudo apt-get -qq -y install fuse
wget https://github.com/neovim/neovim/releases/download/stable/nvim.appimage
sudo mkdir -p /usr/local/bin
chmod u+x nvim.appimage
sudo mv nvim.appimage /usr/local/bin/nvim
}
install_apt_node() {
# see: https://github.com/nodesource/distributions
info "install nodejs-lts from NodeSource"
sudo apt-get install -y curl
curl -fsSL https://deb.nodesource.com/setup_lts.x -o nodesource_setup.sh
sudo -E bash nodesource_setup.sh
sudo apt-get -qq update
sudo apt-get -qq -y install nodejs
}
install_apt_ctags() {
sudo apt-get -qq -y install libseccomp-dev
sudo apt-get -qq -y install libjansson-dev
sudo apt-get -qq -y install libyaml-dev
sudo apt-get -qq -y install libxml2-dev
install_linux_ctags
}
install_apt_git() {
sudo apt-add-repository ppa:git-core/ppa
sudo apt-get -qq update
sudo apt-get -qq -y install git
}
install_apt() {
info "install dependencies with apt"
sudo locale-gen en_US
sudo locale-gen en_US.UTF-8
sudo update-locale
# neovim
install_func "install_apt_nvim" "nvim"
# c++ toolchain
install "sudo apt-get -qq -y install build-essential" "gcc"
install "sudo apt-get -qq -y install build-essential" "make"
install "sudo apt-get -qq -y install autoconf" "autoconf"
install "sudo apt-get -qq -y install automake" "automake"
install "sudo apt-get -qq -y install pkg-config" "pkg-config"
install "sudo apt-get -qq -y install cmake" "cmake"
# download tools
install_func "install_apt_git" "git"
install "sudo apt-get -qq -y install curl" "curl"
install "sudo apt-get -qq -y install wget" "wget"
# compress tools
install "sudo apt-get -qq -y install p7zip" "7z"
install "sudo apt-get -qq -y install gzip" "gzip"
install "sudo apt-get -qq -y install unzip" "unzip"
# # luarocks
# install "sudo apt-get -qq -y install luajit" "luajit"
# install "sudo apt-get -qq -y install luarocks" "luarocks"
# copy/paste tools
install "sudo apt-get -qq -y install xsel" "xsel"
install "sudo apt-get -qq -y install xclip" "xclip"
# # python3
install "sudo apt-get -qq -y install python3 python3-dev python3-venv python3-pip python3-docutils" "python3"
install "sudo apt-get -qq -y install python3 python3-dev python3-venv python3-pip python3-docutils" "pip3"
# # nodejs
install_func "install_apt_node" "node"
# # ctags
# install_func "install_apt_ctags" "ctags"
}
# }
# homebrew {
install_brew() {
info "install dependencies with brew"
if ! type clang >/dev/null 2>&1; then
xcode-select --install
fi
if ! type brew >/dev/null 2>&1; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
fi
brew update
# neovim
install "brew install neovim" "nvim"
# c++ toolchain
install "brew install cmake" "cmake"
install "brew install pkg-config" "pkg-config"
# download tools
install "brew install git" "git"
install "brew install curl" "curl"
install "brew install wget" "wget"
# compress tools
install "brew install gzip" "gzip"
install "brew install p7zip" "7z"
install "brew install unzip" "unzip"
# # luarocks
# install "brew install luarocks" "luarocks"
# # python3
install "brew install python3" "python3"
# # nodejs
install "brew install node" "node"
# # ctags
# install "brew install universal-ctags" "ctags"
}
# }
# dnf: fedora/centos {
install_dnf_ctags() {
sudo dnf install -y libseccomp-devel
sudo dnf install -y jansson-devel
sudo dnf install -y libyaml-devel
sudo dnf install -y libxml2-devel
install_linux_ctags
}
install_dnf() {
info "install dependencies with dnf"
sudo dnf check-update
# neovim
install "sudo dnf install -y neovim" "nvim"
# c++ toolchain
install "sudo dnf group install -y \"Development Tools\"" "gcc"
install "sudo dnf group install -y \"Development Tools\"" "make"
install "sudo dnf install -y autoconf" "autoconf"
install "sudo dnf install -y automake" "automake"
install "sudo dnf install -y pkg-config" "pkg-config"
install "sudo dnf install -y cmake" "cmake"
# download tools
install "sudo dnf install -y git" "git"
install "sudo dnf install -y curl" "curl"
install "sudo dnf install -y wget" "wget"
# compress tools
install "sudo dnf install -y gzip" "gzip"
install "sudo dnf install -y p7zip" "7z"
install "sudo dnf install -y unzip" "unzip"
# # luarocks
# install "sudo dnf install -y luarocks" "luarocks"
# copy/paste tools
install "sudo dnf install -y xsel" "xsel"
install "sudo dnf install -y xclip" "xclip"
# # python3
install "sudo dnf install -y python3 python3-devel python3-pip python3-docutils" "python3"
install "sudo dnf install -y python3 python3-devel python3-pip python3-docutils" "pip3"
# # nodejs
install "sudo dnf install -y nodejs npm" "node"
# # ctags
# install_func "install_dnf_ctags" "ctags"
}
# }
# packman: manjaro/archlinux {
install_pacman() {
info "install dependencies with pacman"
sudo pacman -Syy
# neovim
install "yes | sudo pacman -S neovim" "nvim"
# c++ toolchain
install "yes | sudo pacman -S base-devel" "gcc"
install "yes | sudo pacman -S base-devel" "make"
install "yes | sudo pacman -S autoconf" "autoconf"
install "yes | sudo pacman -S automake" "automake"
install "yes | sudo pacman -S pkg-config" "pkg-config"
install "yes | sudo pacman -S cmake" "cmake"
# download tools
install "yes | sudo pacman -S git" "git"
install "yes | sudo pacman -S curl" "curl"
install "yes | sudo pacman -S wget" "wget"
# compress tools
install "yes | sudo pacman -S gzip" "gzip"
install "yes | sudo pacman -S p7zip" "7z"
install "yes | sudo pacman -S unzip" "unzip"
# # luarocks
# install "yes | sudo pacman -S luarocks" "luarocks"
# copy/paste tools
install "yes | sudo pacman -S xsel" "xsel"
install "yes | sudo pacman -S xclip" "xclip"
# # python3
install "yes | sudo pacman -S python python-pip" "python3"
install "yes | sudo pacman -S python python-pip" "pip3"
# # node
install "yes | sudo pacman -S nodejs npm" "node"
# # ctags
# install "yes | sudo pacman -S ctags" "ctags"
}
# }
# dependency
rust_dependency() {
info "install rust and modern commands"
install "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y" "cargo"
install "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y" "rustc"
if [ -f $HOME/.cargo/env ]; then
. "$HOME/.cargo/env"
fi
install "cargo install fd-find" "fd"
install "cargo install ripgrep" "rg"
install "cargo install --locked bat" "bat"
install "cargo install eza" "eza"
}
# pip_dependency() {
# info "install python packages with pip3"
# local python_has_pep668=$(python3 -c 'import sys; major=sys.version_info.major; minor=sys.version_info.minor; micro=sys.version_info.micro; r1=major >= 3 and minor > 11; r2=major >= 3 and minor == 11 and micro >= 1; print(1 if r1 or r2 else 0)')
#
# python3 --version
# if [ $python_has_pep668 -eq 1 ]; then
# python3 -m pip install pynvim --user --upgrade --break-system-packages
# else
# python3 -m pip install pynvim --user --upgrade
# fi
# }
# npm_dependency() {
# info "install node packages with npm"
# sudo npm install --silent -g neovim
# install "sudo npm install --silent -g trash-cli" "trash"
# }
install_nerdfont() {
if [ "$OS" = "Darwin" ]; then
local font_name=$2
info "install $font_name nerd fonts with brew"
brew install $font_name
else
mkdir -p ~/.local/share/fonts && cd ~/.local/share/fonts
local org="ryanoasis"
local repo="nerd-fonts"
local font_file=$1
local font_version=$(latest_github_release_tag $org $repo)
local font_url="https://github.com/$org/$repo/releases/download/$font_version/$font_file"
info "install $font_file($font_version) nerd fonts from github"
if [ -f $font_file ]; then
rm -rf $font_file
fi
curl -s -L $font_url -o $font_file
if [ $? -ne 0 ]; then
info "failed to download $font_file, skip..."
else
unzip -q -o $font_file
info "install $font_file($font_version) nerd font from github - done"
fi
sudo fc-cache -f
fi
}
nerdfont_dependency() {
install_nerdfont "Hack.zip" "font-hack-nerd-font"
# install_nerdfont "FiraCode.zip" "font-fira-code-nerd-font"
info "please set 'Hack NFM' (or 'Hack Nerd Font Mono') as your terminal font"
}
nvim_config() {
info "install ~/.config/nvim/init.lua for neovim"
mkdir -p $HOME/.config
backup $HOME/.config/nvim
ln -s $NVIM_HOME $HOME/.config/nvim
# # nvim-treesitter
# local nvim_treesitter_home="$NVIM_HOME/lua/configs/nvim-treesitter/nvim-treesitter"
# local nvim_treesitter_ensure_installed="$nvim_treesitter_home/ensure_installed.lua"
# if [ ! -f $nvim_treesitter_ensure_installed ]; then
# cp $nvim_treesitter_home/ensure_installed_sample.lua $nvim_treesitter_ensure_installed
# fi
# nvim-lspconfig
local nvim_lspconfig_home="$NVIM_HOME/lua/configs/neovim/nvim-lspconfig"
local nvim_lspconfig_setup_handlers="$nvim_lspconfig_home/setup_handlers.lua"
if [ ! -f $nvim_lspconfig_setup_handlers ]; then
cp $nvim_lspconfig_home/setup_handlers_sample.lua $nvim_lspconfig_setup_handlers
fi
# mason-lspconfig.nvim
local mason_lspconfig_home="$NVIM_HOME/lua/configs/williamboman/mason-lspconfig-nvim"
local mason_lspconfig_ensure_installed="$mason_lspconfig_home/ensure_installed.lua"
if [ ! -f $mason_lspconfig_ensure_installed ]; then
cp $mason_lspconfig_home/ensure_installed_sample.lua $mason_lspconfig_ensure_installed
fi
local mason_lspconfig_setup_handlers="$mason_lspconfig_home/setup_handlers.lua"
if [ ! -f $mason_lspconfig_setup_handlers ]; then
cp $mason_lspconfig_home/setup_handlers_sample.lua $mason_lspconfig_setup_handlers
fi
# mason-null-ls.nvim
local mason_null_ls_home="$NVIM_HOME/lua/configs/jay-babu/mason-null-ls-nvim"
local mason_null_ls_ensure_installed="$mason_null_ls_home/ensure_installed.lua"
if [ ! -f $mason_null_ls_ensure_installed ]; then
cp $mason_null_ls_home/ensure_installed_sample.lua $mason_null_ls_ensure_installed
fi
local mason_null_ls_setup_handlers="$mason_null_ls_home/setup_handlers.lua"
if [ ! -f $mason_null_ls_setup_handlers ]; then
cp $mason_null_ls_home/setup_handlers_sample.lua $mason_null_ls_setup_handlers
fi
# conform.nvim
local conform_home="$NVIM_HOME/lua/configs/stevearc/conform-nvim"
local conform_formatters_by_ft="$conform_home/formatters_by_ft.lua"
if [ ! -f $conform_formatters_by_ft ]; then
cp $conform_home/formatters_by_ft_sample.lua $conform_formatters_by_ft
fi
# # nvim-lint
# local nvim_lint_home="$NVIM_HOME/lua/configs/mfussenegger/nvim-lint"
# local nvim_lint_linters_by_ft="$nvim_lint_home/linters_by_ft.lua"
# if [ ! -f $nvim_lint_linters_by_ft ]; then
# cp $nvim_lint_home/linters_by_ft_sample.lua $nvim_lint_linters_by_ft
# fi
}
info "install for $OS"
# dependency
case "$OS" in
Linux)
if [ -f "/etc/arch-release" ] || [ -f "/etc/artix-release" ]; then
install_pacman
IS_PACMAN=1
elif [ -f "/etc/fedora-release" ] || [ -f "/etc/redhat-release" ]; then
install_dnf
IS_DNF=1
elif [ -f "/etc/gentoo-release" ]; then
info "gentoo ($OS) is not supported, exit..."
exit 1
else
# assume apt
install_apt
IS_APT=1
fi
;;
Darwin)
install_brew
IS_BREW=1
;;
FreeBSD | NetBSD | OpenBSD)
info "$OS is not supported, exit..."
exit 1
;;
*)
info "$OS is not supported, exit..."
exit 1
;;
esac
rust_dependency
# pip_dependency
# npm_dependency
nerdfont_dependency
nvim_config
info "install for $OS - done"