-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
312 lines (268 loc) · 7.69 KB
/
install.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
#/bin/bash
DOTPATH=~/dotfiles
# https://qiita.com/koara-local/items/1377ddb06796ec8c628a
# https://gist.github.com/natefoo/814c5bf936922dad97ff
function os() {
distro_name="unknown"
if [ -e /etc/debian_version ] || [ -e /etc/debian_release ]; then
if [ -e /etc/lsb-release ]; then
# Ubuntu
# include Elementary OS
distro_name="ubuntu"
else
# Debian
distro_name="debian"
fi
elif [ -e /etc/redhat-release ]; then
if [ -e /etc/oracle-release ]; then
# Oracle Linux
distro_name="oracle"
elif [ -e /etc/centos-release ]; then
# CentOS
distro_name="centos"
else
# Red Hat Enterprise Linux
distro_name="redhat"
fi
elif [ -e /etc/fedora-release ]; then
# Fedra
distro_name="fedora"
elif [ -e /etc/SuSE-release ]; then
# SuSE Linux
distro_name="suse"
elif [ -e /etc/arch-release ]; then
# Arch Linux
distro_name="arch"
elif [ -e /etc/turbolinux-release ]; then
# Turbolinux
distro_name="turbol"
elif [ -e /etc/mandriva-release ]; then
# Mandriva Linux
distro_name="mandriva"
elif [ -e /etc/vine-release ]; then
# Vine Linux
distro_name="vine"
elif [ -e /etc/gentoo-release ]; then
# Gentoo Linux
distro_name="gentoo"
elif [ -e /etc/os-release ]; then
# FIXME
NAME=$(cat /etc/os-release | grep --regexp="^NAME=" | sed -e "s/\"//g" | sed -e "s/NAME=//g")
case $NAME in
"Amazon Linux")
# Amazon Linux
distro_name="amazon"
;;
"Arch Linux")
# Arch Linux
distro_name="arch"
;;
"CentOS Linux")
# CentOS
distro_name="centos"
;;
"Debian GNU/Linux")
# Debian
distro_name="debian"
;;
"Fedora")
# Fedora
distro_name="fedora"
;;
"Kali GNU/Linux")
# Kali Linux
distro_name="kali"
;;
"Mageia")
# Mageia
distro_name="mageia"
;;
"openSUSE")
# openSUSE
distro_name="opensuse"
;;
"Raspbian GNU/Linux")
# Raspberry Pi OS
distro_name="raspbian"
;;
"Scientific Linux")
# Scientific Linux
distro_name="scientific"
;;
"Slackware")
# Slackware Linux
distro_name="slackware"
;;
"SLES")
# SUSE Linux Enterprise Server
distro_name="sles"
;;
"Ubuntu")
# Ubuntu
distro_name="ubuntu"
;;
esac
fi
echo "${distro_name}"
}
# https://stackoverflow.com/questions/592620/how-to-check-if-a-program-exists-from-a-bash-script
function install_if_not_exist() {
if [ -x "$(command -v $1)" ]; then
echo "already installed ${1}"
else
echo "----- install ${1} -----"
case "$(os)" in
ubuntu | debian | raspbian)
sudo apt install -y $1
;;
redhat | centos | amazon)
sudo yum -y install $1
;;
*)
echo "detected unsupported OS."
echo "please check https://github.com/PiroHiroPiro/dotfiles_for_wsl2."
exit 1
;;
esac
fi
}
echo "##### download dotfiles #####"
install_if_not_exist curl
install_if_not_exist tar
curl -sSL "https://github.com/PiroHiroPiro/dotfiles_for_wsl2/archive/main.tar.gz" | tar -zxv
# 解凍したら,DOTPATH に置く
mv -f dotfiles_for_wsl2-main $DOTPATH
cd "${DOTPATH}"
if [ $? -ne 0 ]; then
echo "Not found: ${DOTPATH}"
exit 1
fi
echo "##### finish to download dotfiles #####"
echo "##### setup zsh #####"
install_if_not_exist zsh
if [ ! -d ~/.zplug ]; then
echo "----- install zplug -----"
install_if_not_exist git
curl -sL --proto-redir -all,https https://raw.githubusercontent.com/zplug/installer/master/installer.zsh | zsh
# Permission deniedでinstallに失敗するので、予めsudoで作成
MAKE_DIRS=(log cache repos)
for dir in ${MAKE_DIRS[@]}; do \
sudo mkdir ~/.zplug/$dir
sudo chmod -R 777 ~/.zplug/$dir; \
done
fi
if [ ! -d /mnt/d/dev ]; then
echo "----- mkdir dev folder -----"
mkdir /mnt/d/dev
fi
echo "----- link zsh setting files -----"
if [ ! -d ~/.config ]; then
mkdir ~/.config
fi
LINK_FILES=(.zshrc .zsh_aliases .config/zsh .config/spaceship-prompt)
for file in ${LINK_FILES[@]}; do \
unlink ~/$file&>/dev/null
ln -sf $DOTPATH/zsh/$file ~/$file
echo "Linked: ${file}"; \
done
echo "##### finish to setup zsh #####"
echo "##### setup tmux #####"
install_if_not_exist tmux
echo "----- link tmux setting files -----"
LINK_FILES=(.tmux.conf .config/tmux)
for file in ${LINK_FILES[@]}; do \
unlink ~/$file&>/dev/null
ln -sf $DOTPATH/tmux/$file ~/$file
echo "Linked: ${file}"; \
done
# Permission deniedでinstallに失敗するので、予めsudoで作成
sudo chmod +x $DOTPATH/tmux/.config/tmux/ip.sh
sudo chmod +x $DOTPATH/tmux/.config/tmux/load_average.sh
# https://did2memo.net/2017/05/18/tmux-attach-no-sessions-error/
export TMUX_TMPDIR=/tmp
echo "##### finish to setup tmux #####"
echo "##### setup git #####"
echo "----- link git setting files -----"
if [ ! -d ~/.config ]; then
mkdir ~/.config
fi
LINK_FILES=(.config/git)
for file in ${LINK_FILES[@]}; do \
unlink ~/$file&>/dev/null
ln -sf $(pwd)/git/$file ~/$file
echo "Linked: ${file}"; \
done
echo "##### finish to setup git #####"
echo "##### setup vim #####"
install_if_not_exist vim
echo "----- link vim setting files -----"
LINK_FILES=(dein.toml dein_lazy.toml .config/dein)
for file in ${LINK_FILES[@]}; do \
unlink ~/$file&>/dev/null
ln -sf $DOTPATH/vim/$file ~/$file
echo "Linked: ${file}"; \
done
echo "----- install dein.vim -----"
if [ -d ~/.config/dein/repos/github.com/Shougo/dein.vim/ ]; then
echo "dein.vim is already installed"
else
echo "install dein"
sh -c "$(curl -fsSL https://raw.githubusercontent.com/Shougo/dein-installer.vim/master/installer.sh)"
fi
LINK_FILES=(.vimrc)
for file in ${LINK_FILES[@]}; do \
rm -f ~/$file
ln -sf $DOTPATH/vim/$file ~/$file
echo "Linked: ${file}"; \
done
# Permission deniedでinstallに失敗するので、予めsudoで作成
MAKE_DIRS=(. .cache repos/github.com)
for dir in ${MAKE_DIRS[@]}; do \
sudo mkdir -p ~/.config/dein/$dir
sudo chmod -R 777 ~/.config/dein/$dir; \
done
echo "##### finish to setup vim #####"
cd ~
echo "##### setup linuxbrew #####"
# by https://docs.brew.sh/Homebrew-on-Linux
echo "----- install requirement packeage -----"
install_if_not_exist file
install_if_not_exist git
case "$(os)" in
ubuntu | debian | raspbian)
sudo apt-get install -y build-essential
;;
redhat | centos | amazon)
sudo yum groupinstall -y 'Development Tools'
sudo yum install -y libxcrypt-compat # needed by Fedora 30 and up
;;
*)
echo "detected unsupported OS by linuxbrew."
echo "please check https://docs.brew.sh/Homebrew-on-Linux."
;;
esac
echo "----- install linuxbrew -----"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
(echo; echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"') >> /home/hiroh/.zprofile(echo; echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"') >> /home/hiroh/.zprofile
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
test -d /home/linuxbrew/.linuxbrew && eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)
test -r ~/.zshrc && echo "eval \$($(brew --prefix)/bin/brew shellenv)" >> ~/.zshrc
echo "----- install command using linuxbrew -----"
brew install gcc
brew install eza
brew install procs
brew install fd
brew install ripgrep
brew install gh
brew install lazygit
brew install fzf
brew install jq
echo "##### finish to setup linuxbrew #####"
echo
echo "zsh:"
echo "please run the following command."
echo " chsh -s $(command -v zsh)"
echo
echo "Installed."
echo
exit 0