-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
428 lines (388 loc) · 12.2 KB
/
setup.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
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
#!/usr/bin/env bash
set -eu -o pipefail -o posix
#############################################
# global変数
#############################################
SETUP_PYTHON_FLAG=false
SETUP_RUST_FLAG=false
SETUP_NERDFONT_FLAG=false
OS_TYPE='Linux'
##############################################
# logging function
# Globals:
# None
# Arguments:
# None
##############################################
function log() {
local level="${1}"
shift
local color
local reset="\033[0m"
case "${level}" in
INFO)
color="\033[0;32m" # Green
;;
WARN)
color="\033[0;33m" # Yellow
;;
ERROR)
color="\033[0;31m" # Red
;;
DEBUG)
color="\033[0;36m" # Cyan
;;
*)
color="\033[0;37m" # White
;;
esac
echo -e "[${color}${level}${reset}] : [$(date '+%Y-%m-%d %H:%M:%S')] : $*"
}
##############################################
# logging function
# Globals:
# OS_TYPE
# Arguments:
# None
##############################################
function set_os_type() {
case "$(uname -s)" in
Linux*) OS_TYPE=Linux ;;
Darwin*) OS_TYPE=Mac ;;
*) OS_TYPE="UNKNOWN" ;;
esac
log INFO "Detected OS_TYPE => ${OS_TYPE}"
}
##############################################
# Install コマンド用
# Globals:
# None
# Arguments:
# None
##############################################
function install_package() {
if ! dpkg -l | grep -q "^ii $1"; then
sudo apt-get install -y "$1"
log INFO "You are enable to install $1 . ✅"
else
log INFO "You already install $1. ⭕️"
fi
}
##############################################
# helpコマンド用
# Globals:
# None
# Arguments:
# None
##############################################
function help() {
cat <<EOS >&2
usage: $0 [-p] [-r] [-n]
-h flag to show help
-p flag to setup python environment (tasks/install-python.sh)
-r flag to setup rust environment (tasks/install-rust.sh)
-n flag to install nerdfont to your environment (tasks/install-nerdfonts.sh)
EOS
exit 1
}
##############################################
# 引数の解析
# Globals:
# SETUP_PYTHON_FLAG
# SETUP_RUST_FLAG
# SETUP_NERDFONT_FLAG
#
# Arguments:
# None
#
# Referece
# 1. https://zenn.dev/kawarimidoll/articles/d546892a6d36eb
# 2. https://zenn.dev/ryo_kawamata/articles/watch-files-in-bash
# 3. https://www.man7.org/linux/man-pages/man1/getopt.1.html
##############################################
function parse_args() {
while getopts ":hprn" opt; do
case ${opt} in
p)
SETUP_PYTHON_FLAG=true
;;
r)
SETUP_RUST_FLAG=true
;;
n)
SETUP_NERDFONT_FLAG=true
;;
h)
help
;;
*)
log INFO "Invalid Option: ${OPTARG} see h option, please." 1>&2
exit 2
;;
esac
shift
done
}
function install_ripgrep() {
# -- Install `ripgrep`
# new grep alternative
# for telescope in neovim
# Reference
# [1] https://github.com/BurntSushi/ripgrep
log INFO "Install 'ripgrep' ✅"
if [[ "${OS_TYPE}" = 'Linux' ]]; then
local ripgrep_ver='14.1.0'
wget "https://github.com/BurntSushi/ripgrep/releases/download/${ripgrep_ver}/ripgrep_${ripgrep_ver}-1_amd64.deb" -P /tmp
sudo dpkg -i "/tmp/ripgrep_${ripgrep_ver}-1_amd64.deb"
sudo rm "/tmp/ripgrep_${ripgrep_ver}-1_amd64.deb"
elif [[ "${OS_TYPE}" = 'Mac' ]]; then
arch -arm64 brew install ripgrep
fi
}
function install_lsd() {
# -- Install `lsd`
# new gen ls command
# Reference
# [1] https://github.com/lsd-rs/lsd
log INFO "Install 'lsd' ✅"
if [[ "${OS_TYPE}" = 'Linux' ]]; then
local lsd_ver='1.1.2'
wget "https://github.com/lsd-rs/lsd/releases/download/v${lsd_ver}/lsd-musl_${lsd_ver}_amd64.deb" -P /tmp
sudo dpkg -i "/tmp/lsd-musl_${lsd_ver}_amd64.deb"
sudo rm "/tmp/lsd-musl_${lsd_ver}_amd64.deb"
elif [[ "${OS_TYPE}" = 'Mac' ]]; then
arch -arm64 brew install lsd
fi
}
function install_bat() {
# -- Install `bat`
# new cat alternative
# Reference
# [1] https://github.com/sharkdp/bat
log INFO "Install 'bat' ✅"
if [[ "${OS_TYPE}" = 'Linux' ]]; then
install_package bat
# /usr/bin/batcatでインストールされるので ~/.local/bin/batにリンク貼る
[ -f ~/.local/bin/bat ] && rm -f ~/.local/bin/bat
[ -f /usr/bin/batcat ] && sudo rm -f /usr/bin/bat
ln -s /usr/bin/batcat ~/.local/bin/bat
elif [[ "${OS_TYPE}" = 'Mac' ]]; then
arch -arm64 brew install bat
fi
}
function install_delta() {
# -- Install `delta`
# new diff alternative
# Reference
# [1] https://github.com/dandavison/delta
log INFO "Install 'delta' ✅"
if [[ "${OS_TYPE}" = 'Linux' ]]; then
[ -f /usr/local/bin/delta ] && sudo rm -f /usr/local/bin/delta
local delta_ver='0.16.5'
wget "https://github.com/dandavison/delta/releases/download/${delta_ver}/delta-${delta_ver}-x86_64-unknown-linux-musl.tar.gz" -P /tmp
tar xvf "/tmp/delta-${delta_ver}-x86_64-unknown-linux-musl.tar.gz" -C "${HOME}/.local/bin"
sudo ln -s "${HOME}/.local/bin/delta-${delta_ver}-x86_64-unknown-linux-musl/delta" /usr/local/bin/delta
sudo rm "/tmp/delta-${delta_ver}-x86_64-unknown-linux-musl.tar.gz"
elif [[ "${OS_TYPE}" = 'Mac' ]]; then
arch -arm64 brew install git-delta
fi
}
function install_fzf() {
log INFO "Install 'fzf' ✅"
[ -d "${HOME}/.fzf" ] && rm -rf "${HOME}/.fzf"
git clone --depth 1 https://github.com/junegunn/fzf.git "${HOME}/.fzf"
"${HOME}/.fzf/install" --all
}
function install_starship() {
log INFO "Install 'starship' ✅"
# zsh promptのカスタマイズにはstarshipを使う
# Reference
# [1] https://github.com/starship/starship
# [2] dotfiles/starship.toml
sudo curl -sS https://starship.rs/install.sh | sudo bash --posix -s -- -y
}
function install_sheldon() {
log INFO "Install 'sheldon' ✅"
# zshのpluginの管理にはshelldonを使う
if [[ "${OS_TYPE}" = 'Linux' ]]; then
[ -f "${HOME}/.local/bin/sheldon" ] && rm -f "${HOME}/.local/bin/sheldon"
curl --proto '=https' -fLsS https://rossmacarthur.github.io/install/crate.sh | bash -s -- -f --repo rossmacarthur/sheldon --to ~/.local/bin
elif [[ "${OS_TYPE}" = 'Mac' ]]; then
arch -arm64 brew install sheldon
fi
}
function install_lazygit() {
log INFO 'Install lazygit ✅'
if [[ "${OS_TYPE}" = 'Linux' ]]; then
LAZYGIT_VERSION=$(curl -s "https://api.github.com/repos/jesseduffield/lazygit/releases/latest" | grep -Po '"tag_name": "v\K[^"]*')
curl -Lo lazygit.tar.gz "https://github.com/jesseduffield/lazygit/releases/latest/download/lazygit_${LAZYGIT_VERSION}_Linux_x86_64.tar.gz"
tar xf lazygit.tar.gz lazygit
sudo install lazygit /usr/local/bin
sudo rm lazygit.tar.gz lazygit
elif [[ "${OS_TYPE}" = 'Mac' ]]; then
arch -arm64 brew install lazygit
fi
}
function install_neovim() {
log INFO 'Install neovim ✅'
if [[ "${OS_TYPE}" = 'Linux' ]]; then
wget https://github.com/neovim/neovim/releases/download/stable/nvim-linux64.tar.gz -P /tmp
tar xzvf /tmp/nvim-linux64.tar.gz -C ~/.local/bin/
sudo rm /tmp/nvim-linux64.tar.gz
[ -e /usr/local/bin/nvim ] && sudo rm /usr/local/bin/nvim
sudo ln -s ~/.local/bin/nvim-linux64/bin/nvim /usr/local/bin/nvim
elif [[ "${OS_TYPE}" = 'Mac' ]]; then
arch -arm64 brew unlink neovim
arch -arm64 brew install --HEAD neovim
fi
}
function install_nodejs() {
log INFO 'Install nodejs@22 ✅'
if [[ "${OS_TYPE}" = 'Linux' ]]; then
export NVM_DIR="${HOME}/.nvm"
[ -d "${NVM_DIR}" ] && rm -rf "${NVM_DIR}"
mkdir -p "${NVM_DIR}"
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
# source "${HOME}/.zshrc"
# nvm install 22
elif [[ "${OS_TYPE}" = 'Mac' ]]; then
if [[ -x "$(commnd -v node) " ]]; then
brew uninstall node@22
fi
brew install node@22
fi
}
function install_github_cli() {
log INFO 'Install github-cli ✅'
if [[ ${OS_TYPE} = 'Linux' ]]; then
(type -p wget >/dev/null || (sudo apt-get update && sudo apt-get install wget -y)) &&
sudo mkdir -p -m 755 /etc/apt/keyrings &&
wget -qO- https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg >/dev/null &&
sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg &&
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/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-get update &&
sudo apt-get install gh -y
elif [[ ${OS_TYPE} = 'Mac' ]]; then
arch -arm64 brew install gh
fi
}
function install_fdfind() {
log INFO 'Install fd-find ✅'
if [[ ${OS_TYPE} = 'Linux' ]]; then
sudo apt install fd-find
[ -f ~/.local/bin/fd ] && rm -f ~/.local/bin/fd
ln -s "$(which fdfind)" ~/.local/bin/fd
elif [[ ${OS_TYPE} = 'Mac' ]]; then
arch -arm64 brew install fd
fi
}
function install_yazi() {
log INFO 'Install yazi ✅'
if [[ ${OS_TYPE} = 'Linux' ]]; then
wget https://github.com/sxyazi/yazi/releases/download/v0.3.3/yazi-x86_64-unknown-linux-gnu.zip -P /tmp
unzip /tmp/yazi-x86_64-unknown-linux-gnu.zip -d "${HOME}/.local/bin"
sudo ln -s "${HOME}/.local/bin/yazi-x86_64-unknown-linux-gnu/yazi" "${HOME}/.local/bin/yazi"
rm /tmp/yazi-x86_64-unknown-linux-gnu.zip
elif [[ ${OS_TYPE} = 'Mac' ]]; then
arch -arm64 brew install --HEAD yazi
fi
}
function install_tmux() {
log INFO 'Install tmux ✅'
if [[ ${OS_TYPE} = 'Linux' ]]; then
sudo apt-get install -yq libevent-dev ncurses-dev build-essential bison pkg-config
wget https://github.com/tmux/tmux/releases/download/3.5a/tmux-3.5a.tar.gz -P /tmp
cd /tmp
tar -zxf tmux-*.tar.gz
cd tmux-*/
./configure --prefix="${HOME}/.local"
make && sudo make install
elif [[ ${OS_TYPE} = 'Mac' ]]; then
brew install tmux
fi
}
function install_tmux_plugin_manager() {
log INFO 'Install tmux plugin manager ✅'
[ -d "${HOME}/.tmux/plugins/tpm" ] && rm -rf "${HOME}/.tmux/plugins/tpm"
git clone --depth 1 https://github.com/tmux-plugins/tpm "${HOME}/.tmux/plugins/tpm"
}
function install_wezterm() {
log INFO 'Install wezterm ✅'
if [[ ${OS_TYPE} = 'Linux' ]]; then
wget https://github.com/wez/wezterm/releases/download/nightly/wezterm-nightly.Ubuntu22.04.deb -P /tmp
sudo apt install -yq /tmp/wezterm-nightly.Ubuntu22.04.deb
elif [[ ${OS_TYPE} = 'Mac' ]]; then
brew install --cask wezterm-nightly
fi
}
# ${#<配列変数>} 配列のサイズ取得
# if [[ "${#ARGS[@]}" ]]
function main() {
log INFO "################### start to setup develop environment #######################"
log INFO '###### Sync dotfiles to your environment #######'
bash tasks/link.sh
log INFO "################### start to install prerequire tools #######################"
if [ "${OS_TYPE}" = 'Linux' ]; then
install_package sudo
sudo apt-get update -yq && sudo apt-get upgrade -yq
install_package zsh
install_package gcc
install_package g++
install_package make
install_package cmake
install_package git
install_package vim
# install_package tmux
install_package bat
install_package curl
install_package wget
install_package unzip
install_package sqlite3
install_package libsqlite3-dev
install_package powerline
install_package fonts-powerline
install_package python3-venv # for ruff
# install_package python3.9-venv # for ruff
elif [[ "${OS_TYPE}" = 'Mac' ]]; then
arch -arm64 brew install \
gcc \
make \
cmake \
git \
vim \
tmux \
curl \
wget \
sqlite3
fi
# Ubuntu & Mac(M3)
mkdir -p "${HOME}/.local/bin"
install_ripgrep
install_lsd
install_fdfind
install_bat
install_delta
install_fzf
install_sheldon
install_starship
install_lazygit
install_neovim
install_github_cli
install_tmux
install_tmux_plugin_manager
install_wezterm
install_nodejs
# デフォルトのshellをzshにする
if [ "${OS_TYPE}" = 'Linux' ]; then
sudo chsh "${USER}" -s "$(which zsh)"
fi
log INFO '=================== ✅Finished setup of develop environment ================='
}
if [ "${BASH_SOURCE[0]}" == "${0}" ]; then
set_os_type
if [ "${OS_TYPE}" = 'UNKNOWN' ]; then
log ERROR "Not supported: OS_TYPE=UNKNOWN "
exit 1
fi
main
fi