forked from seagle0128/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·355 lines (303 loc) · 10 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
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
#!/bin/sh
#############################################################
# Set development environment on Linux/macOS/Cygwin quickly.
# Author: Vincent Zhang <[email protected]>
# URL: https://github.com/seagle0128/dotfiles
#############################################################
# Variables
DOTFILES=$HOME/.dotfiles
EMACSD=$HOME/.emacs.d
FZF=$HOME/.fzf
TMUX=$HOME/.tmux
ZSH=$HOME/.antigen
# Get OS name
SYSTEM=`uname -s`
# Only enable exit-on-error after the non-critical colorization stuff,
# which may fail on systems lacking tput or terminfo
# set -e
# Use colors, but only if connected to a terminal, and that terminal
# supports them.
if command -v tput >/dev/null 2>&1; then
ncolors=$(tput colors)
fi
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)"
BOLD="$(tput bold)"
NORMAL="$(tput sgr0)"
else
RED=""
GREEN=""
YELLOW=""
BLUE=""
BOLD=""
NORMAL=""
fi
# Check git
command -v git >/dev/null 2>&1 || {
echo "${RED}Error: git is not installed${NORMAL}" >&2
exit 1
}
# Check curl
command -v curl >/dev/null 2>&1 || {
echo "${RED}Error: curl is not installed${NORMAL}" >&2
exit 1
}
# Sync repository
sync_repo() {
local repo_uri="$1"
local repo_path="$2"
local repo_branch="$3"
if [ -z "$repo_branch" ]; then
repo_branch="master"
fi
if [ ! -e "$repo_path" ]; then
mkdir -p "$repo_path"
git clone --depth 1 --branch $repo_branch "https://github.com/$repo_uri.git" "$repo_path"
else
cd "$repo_path" && git pull --rebase --stat origin $repo_branch; cd - >/dev/null
fi
}
sync_brew_package() {
if ! command -v brew >/dev/null 2>&1; then
echo "${RED}Error: brew is not installed${NORMAL}" >&2
return 1
fi
if ! command -v ${1} >/dev/null 2>&1; then
brew install ${1} >/dev/null
else
brew upgrade ${1} >/dev/null
fi
}
sync_apt_package() {
if command -v apt >/dev/null 2>&1; then
APT=apt
elif command -v apt-get >/dev/null 2>&1; then
APT=apt-get
else
echo "${RED}Error: unable to find apt or apt-get${NORMAL}" >&2
return 1
fi
if [ ! -z "$APT" ]; then
sudo $APT upgrade -y ${1} >/dev/null
fi
}
sync_arch_package() {
if ! command -v pacman >/dev/null 2>&1; then
echo "${RED}Error: pacman is not installed${NORMAL}" >&2
return 1
fi
sudo pacman -S --noconfirm ${1} >/dev/null
}
# Clean all configurations
clean_dotfiles() {
confs="
.gemrc
.gitconfig
.markdownlint.json
.npmrc
.tmux.conf
.vimrc
.zshenv
.zshrc
.zshrc.local
"
for c in ${confs}; do
[ -f $HOME/${c} ] && mv $HOME/${c} $HOME/${c}.bak
done
[ -d $EMACSD ] && mv $EMACSD $EMACSD.bak
rm -rf $ZSH $TMUX $FZF $DOTFILES
rm -f $HOME/.fzf.*
rm -f $HOME/.gitignore_global $HOME/.gitconfig_global
rm -f $HOME/.tmux.conf $HOME/.tmux.local
}
YES=0
NO=1
promote_yn() {
eval ${2}=$NO
read -p "$1 [y/N]: " yn
case $yn in
[Yy]* ) eval ${2}=$YES;;
[Nn]*|'' ) eval ${2}=$NO;;
*) eval ${2}=$NO;;
esac
}
# Reset configurations
if [ -d $ZSH ] || [ -d $TMUX ] || [ -d ~$FZF ] || [ -d $EMACSD ]; then
promote_yn "Do you want to reset all configurations?" "continue"
if [ $continue -eq $YES ]; then
clean_dotfiles
fi
fi
# Brew
if [ "$SYSTEM" = "Darwin" ]; then
printf "${BLUE} ➜ Installing Homebrew...${NORMAL}\n"
if ! command -v brew >/dev/null 2>&1; then
# Install homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
# Tap cask and cask-upgrade
brew tap homebrew/cask
brew tap homebrew/cask-fonts
brew tap buo/cask-upgrade
fi
fi
# Apt-Cyg
if [ "$OSTYPE" = "cygwin" ]; then
printf "${BLUE} ➜ Installing Apt-Cyg...${NORMAL}\n"
if ! command -v apt-cyg >/dev/null 2>&1; then
APT_CYG=/usr/local/bin/apt-cyg
curl -fsSL https://raw.githubusercontent.com/transcode-open/apt-cyg/master/apt-cyg > $APT_CYG
chmod +x $APT_CYG
fi
fi
# Antigen: the plugin manager for zsh
printf "${BLUE} ➜ Installing Antigen...${NORMAL}\n"
if [ "$SYSTEM" = "Darwin" ]; then
sync_brew_package antigen
else
if command -v apt-get >/dev/null 2>&1; then
# sync_apt_package zsh-antigen
sudo mkdir -p /usr/share/zsh-antigen && sudo curl -o /usr/share/zsh-antigen/antigen.zsh -sL git.io/antigen
elif command -v yaourt >/dev/null 2>&1; then
yaourt -S --noconfirm antigen-git
else
mkdir -p $ZSH
curl -fsSL git.io/antigen > $ZSH/antigen.zsh.tmp && mv $ZSH/antigen.zsh.tmp $ZSH/antigen.zsh
fi
fi
# Dotfiles
printf "${BLUE} ➜ Installing Dotfiles...${NORMAL}\n"
sync_repo seagle0128/dotfiles $DOTFILES
chmod +x $DOTFILES/install.sh
chmod +x $DOTFILES/install_brew_cask.sh
chmod +x $DOTFILES/install_go.sh
ln -sf $DOTFILES/.zshenv $HOME/.zshenv
ln -sf $DOTFILES/.zshrc $HOME/.zshrc
ln -sf $DOTFILES/.vimrc $HOME/.vimrc
ln -sf $DOTFILES/.tmux.conf.local $HOME/.tmux.conf.local
ln -sf $DOTFILES/.markdownlint.json $HOME/.markdownlint.json
cp -n $DOTFILES/.npmrc $HOME/.npmrc
cp -n $DOTFILES/.gemrc $HOME/.gemrc
cp -n $DOTFILES/.zshrc.local $HOME/.zshrc.local
mkdir -p $HOME/.pip; cp -n $DOTFILES/.pip.conf $HOME/.pip/pip.conf
ln -sf $DOTFILES/.gitignore_global $HOME/.gitignore_global
ln -sf $DOTFILES/.gitconfig_global $HOME/.gitconfig_global
if [ "$SYSTEM" = "Darwin" ]; then
cp -n $DOTFILES/.gitconfig_macOS $HOME/.gitconfig
elif [ "$OSTYPE" = "cygwin" ]; then
cp -n $DOTFILES/.gitconfig_cygwin $HOME/.gitconfig
else
cp -n $DOTFILES/.gitconfig_linux $HOME/.gitconfig
fi
if [ "$OSTYPE" = "cygwin" ]; then
ln -sf $DOTFILES/.minttyrc $HOME/.minttyrc
fi
# Emacs Configs
printf "${BLUE} ➜ Installing Centaur Emacs...${NORMAL}\n"
sync_repo seagle0128/.emacs.d $EMACSD
# Oh My Tmux
printf "${BLUE} ➜ Installing Oh My Tmux...${NORMAL}\n"
sync_repo gpakosz/.tmux $TMUX
ln -sf $TMUX/.tmux.conf $HOME/.tmux.conf
# Ripgrep
printf "${BLUE} ➜ Installing ripgrep (rg)...${NORMAL}\n"
if [ "$SYSTEM" = "Darwin" ]; then
sync_brew_package ripgrep
elif [ "$SYSTEM" = "Linux" ] && [ "`uname -m`" = "x86_64" ] && command -v dpkg >/dev/null 2>&1; then
# sync_apt_package ripgrep
# Only support Linux x64 binary
RG_UPDATE=1
RG_RELEASE_URL="https://github.com/BurntSushi/ripgrep/releases"
RG_VERSION_PATTERN='[[:digit:]]+\.[[:digit:]]+.[[:digit:]]*'
RG_RELEASE_TAG=$(curl -fs "${RG_RELEASE_URL}/latest" | grep -oE $RG_VERSION_PATTERN)
if command -v rg >/dev/null 2>&1; then
RG_UPDATE=0
RG_VERSION=$(rg --version | grep -oE $RG_VERSION_PATTERN)
if [ "$RG_VERSION" != "$RG_RELEASE_TAG" ]; then
RG_UPDATE=1
fi
fi
if [ $RG_UPDATE -eq 1 ]; then
curl -LO ${RG_RELEASE_URL}/download/${RG_RELEASE_TAG}/ripgrep_${RG_RELEASE_TAG}_amd64.deb &&
sudo dpkg -i ripgrep_${RG_RELEASE_TAG}_amd64.deb
rm -f ripgrep_${RG_RELEASE_TAG}_amd64.deb
fi
fi
# FD
printf "${BLUE} ➜ Installing FD...${NORMAL}\n"
if [ "$SYSTEM" = "Darwin" ]; then
sync_brew_package fd
elif [ "$SYSTEM" = "Linux" ] && command -v apt-get >/dev/null 2>&1; then
# sync_apt_package fd-find
# Only support Linux x64 binary
FD_UPDATE=1
FD_RELEASE_URL="https://github.com/sharkdp/fd/releases"
FD_VERSION_PATTERN='[[:digit:]]+\.[[:digit:]]+.[[:digit:]]*'
FD_RELEASE_TAG=$(curl -fs "${FD_RELEASE_URL}/latest" | grep -oE $FD_VERSION_PATTERN)
if command -v fd >/dev/null 2>&1; then
FD_UPDATE=0
FD_VERSION=$(fd --version | grep -oE $FD_VERSION_PATTERN)
if [ "$FD_VERSION" != "$FD_RELEASE_TAG" ]; then
FD_UPDATE=1
fi
fi
if [ $FD_UPDATE -eq 1 ]; then
curl -LO ${FD_RELEASE_URL}/download/v${FD_RELEASE_TAG}/fd_${FD_RELEASE_TAG}_amd64.deb &&
sudo dpkg -i fd_${FD_RELEASE_TAG}_amd64.deb
rm -f fd_${FD_RELEASE_TAG}_amd64.deb
fi
fi
# FZF
printf "${BLUE} ➜ Installing FZF...${NORMAL}\n"
if [ "$OSTYPE" = "cygwin" ]; then
if ! command -v fzf >/dev/null 2>&1 && command -v apt-cyg >/dev/null 2>&1; then
apt-cyg install fzf fzf-zsh fzf-zsh-completion
fi
else
if [ "$SYSTEM" = "Darwin" ]; then
sync_brew_package fzf
FZF=/usr/local/opt/fzf
elif [ "$SYSTEM" = "Linux" ] && command -v apt-get >/dev/null 2>&1; then
sync_repo junegunn/fzf $FZF
fi
[ -f $FZF/install ] && $FZF/install --all --no-update-rc --no-bash --no-fish >/dev/null
fi
# Peco
if [ "$OSTYPE" != "cygwin" ]; then
printf "${BLUE} ➜ Installing Peco...${NORMAL}\n"
if [ "$SYSTEM" = "Darwin" ]; then
sync_brew_package peco
elif [ "$SYSTEM" = "Linux" ] && [ "`uname -m`" = "x86_64" ]; then
# Only support Linux x64 binary
PECO_UPDATE=1
PECO_RELEASE_URL="https://github.com/peco/peco/releases"
PECO_VERSION_PATTERN='v[[:digit:]]+\.[[:digit:]]+.[[:digit:]]*'
PECO_RELEASE_TAG=$(curl -fs "${PECO_RELEASE_URL}/latest" | grep -oE $PECO_VERSION_PATTERN)
if command -v peco >/dev/null 2>&1; then
PECO_UPDATE=0
PECO_VERSION=$(peco --version | grep -oE $PECO_VERSION_PATTERN)
if [ "$PECO_VERSION" != "$PECO_RELEASE_TAG" ]; then
PECO_UPDATE=1
fi
fi
if [ $PECO_UPDATE -eq 1 ]; then
curl -fsSL ${PECO_RELEASE_URL}/download/${PECO_RELEASE_TAG}/peco_linux_amd64.tar.gz | tar xzf - &&
chmod +x peco_linux_amd64/peco && sudo mv peco_linux_amd64/peco /usr/local/bin
rm -rf peco_linux_amd64
fi
fi
fi
# Entering zsh
printf "Done. Enjoy!\n"
if command -v zsh >/dev/null 2>&1; then
if [ "$OSTYPE" != "cygwin" ] && [ "$SHELL" != "$(which zsh)" ]; then
chsh -s $(which zsh)
printf "${BLUE} You need to logout and login to enable zsh as the default shell.${NORMAL}\n"
fi
env zsh
else
echo "${RED}Error: zsh is not installed${NORMAL}" >&2
exit 1
fi