-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·236 lines (208 loc) · 5.28 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
#!/bin/bash
DOTFILES=$HOME/.dotfiles
ZINIT_PATH=$HOME/.zinit
VIM_PATH=$HOME/.vim
PROXY_PORT=7890
CONFIG=$HOME/.config
ALACRITTY_PATH=$CONFIG/alacritty
KITTY_PATH=$CONFIG/kitty
WEZTERM_PATH=$CONFIG/wezterm
HELIX_PATH=$CONFIG/helix
OS=$(uname -s)
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
is_mac()
{
[ "$OS" = "Darwin" ]
}
is_linux()
{
[ "$OS" = "Linux" ]
}
is_debian() {
command -v apt-get > /dev/null 2>&1
}
is_arch() {
command -v yay > /dev/null 2>&1 || command -v pacman > /dev/null 2>&1
}
is_fedora() {
command -v dnf > /dev/null 2>&1
}
install_package() {
if ! command -v ${1} > /dev/null 2>&1; then
if is_mac; then
brew install ${1}
elif is_debian; then
sudo apt install -y ${1}
elif is_arch; then
sudo pacman -S --noconfirm ${1}
elif is_fedora; then
sudo dnf install -y ${1}
fi
else
if is_mac; then
brew upgrade ${1}
elif is_debian; then
sudo apt upgrade -y ${1}
elif is_arch; then
sudo pacman -S --noconfirm ${1}
elif is_fedora; then
sudo dnf install -y ${1}
fi
fi
}
clean_dotfiles() {
echo "- Clean files"
files="
.zinit
.zshenv
.zshrc
.zshrc.local
.gitconfig
.vim
.vimrc
.gvimrc
.ideavimrc
.tmux
.tmux.conf
.tmux.conf.local
.condarc
.irbrc
.bashrc
"
backup_path="bak-$(date +%s)"
mkdir -p $DOTFILES/$backup_path
for f in $files; do
if [ -f $HOME/$f ] || [ -d $HOME/$f ] || [ -h $HOME/$f ]; then
mv $HOME/$f $DOTFILES/$backup_path/$f
fi
done
}
YES=1
NO=0
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
}
set_proxy() {
https_proxy=http://127.0.0.1:$PROXY_PORT
http_proxy=http://127.0.0.1:$PROXY_PORT
all_proxy=socks5://127.0.0.1:$PROXY_PORT
}
install_requirements() {
if is_mac && ! command -v brew > /dev/null 2>&1; then
echo "- Install Homebrew"
/bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/Homebrew/install@HEAD/install.sh)"
fi
reqs="
git
curl
wget
zsh
unzip
tmux
"
for r in $reqs; do
if ! command -v $r > /dev/null 2>&1; then
echo "- Install $r"
install_package $r
fi
done
}
install_dotfiles() {
echo "- Clone dotfiles repo"
rm -rf $DOTFILES
git clone --recursive https://github.com/Yestercafe/dotfiles.git $DOTFILES
}
install_zinit() {
echo "- Install zinit"
if ! command -v zinit > /dev/null 2>&1; then
sh -c "$(curl -fsSL https://git.io/zinit-install)"
fi
}
iterm_support() {
echo "- Install iTerm2 tools"
UTILITIES=(imgcat imgls it2api it2attention it2check it2copy it2dl it2getvar it2git it2setcolor it2setkeylabel it2tip it2ul it2universion it2profile)
for U in "${UTILITIES[@]}"
do
echo "Downloading $U..."
curl -SsL "https://iterm2.com/utilities/$U" > "$DOTDIR/.iterm2/$U" && chmod +x "$DOTDIR/.iterm2/$U"
done
}
done_dotfiles() {
echo "- Link files"
ln -sf $DOTFILES/.zshenv $HOME/.zshenv
ln -sf $DOTFILES/.zshrc $HOME/.zshrc
ln -sf $DOTFILES/.bashrc $HOME/.bashrc
if is_mac; then
ln -sf $DOTFILES/.zshrc.macos.local $HOME/.zshrc.local
fi
PATH=$DOTFILES/cms-git-tools:$PATH
cp $DOTFILES/.gitconfig_macos $HOME/.gitconfig
git clone --recursive https://github.com/Yestercafe/vim.git $HOME/.vim
ln -sf $DOTFILES/.gvimrc $HOME/.gvimrc
cp $DOTFILES/.ideavimrc $HOME/.ideavimrc
# install TPM
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
ln -sf $DOTFILES/.tmux.conf $HOME/.tmux.conf
ln -sf $DOTFILES/.condarc $HOME/.condarc
ln -sf $DOTFILES/.irbrc $HOME/.irbrc
mkdir -p $ALACRITTY_PATH
ln -sf $DOTFILES/alacritty.yml $ALACRITTY_PATH/alacritty.yml
mkdir -p $WEZTERM_PATH
ln -sf $DOTFILES/wezterm.lua $WEZTERM_PATH/wezterm.lua
mkdir -p $KITTY_PATH
ln -sf $DOTFILES/kitty.conf $KITTY_PATH/kitty.conf
mkdir -p $HELIX_PATH
ln -sf $DOTFILES/helix.toml $HELIX_PATH/config.toml
ln -sf $DOTFILES/starship.toml $CONFIG/
echo "- Done!"
}
main() {
sudo -v
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
set_proxy
if [ -d $ZINIT_PATH ] || [ -d $TMUX_PATH ] || [ -d $VIM_PATH ]; then
promote_yn "Do you want to reset all configurations and continue?" "choice"
if [ $choice -eq $YES ]; then
install_requirements
install_dotfiles
clean_dotfiles
install_zinit
done_dotfiles
else
exit
fi
else
install_requirements
install_dotfiles
clean_dotfiles
install_zinit
if is_mac; then
iterm_support
fi
done_dotfiles
fi
}
main