-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
231 lines (199 loc) Β· 6.68 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
#!/usr/bin/env bash
# REMIND. bash dotfiles are not supported yet.
RED='\033[0;31m'
YELLOW='\033[0;33m'
GREEN='\033[0;32m'
NC='\033[0m'
safe_link(){
local src=$1
local dst=$2
if [[ -f $dst ]] || [[ -d $dst ]]; then
read -p "$dst already exists. Override? [y/n] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
read -p "Backup $dst to $dst.bak? [y/n] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
mv $dst $dst.bak
# echo "Backup $dst to $dst.bak"
else
rm -rf $dst
# echo "Override $dst"
fi
ln -s $src $dst
else
echo "Skip $dst"
fi
elif [[ -L $dst ]]; then # if broken symlink
read -p "$dst is broken symlink. Override? [y/n] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
rm $dst
ln -s $src $dst
else
echo "Skip $dst"
fi
else
mkdir -p $(dirname $dst)
echo "Link $src to $dst"
ln -s $src $dst
fi
}
automatic_link() {
local src=$1
local dst=$2
if [[ -f $dst ]] || [[ -d $dst ]]; then
echo "$dst already exists. Backup $dst to $dst.bak."
mv $dst $dst.bak
ln -s $src $dst
elif [[ -L $dst ]]; then # if broken symlink
echo "$dst is broken symlink. Remove $dst and reassign."
rm $dst
ln -s $src $dst
else
mkdir -p $(dirname $dst)
echo "Link $src to $dst"
ln -s $src $dst
fi
}
DOTFILES=$(dirname $(readlink -f $0))
echo "dotfile absolute path: $DOTFILES"
symlink () {
# zsh symlink
safe_link $DOTFILES/zsh/zfunc ~/.zfunc
safe_link $DOTFILES/zsh/zlogin ~/.zlogin
safe_link $DOTFILES/zsh/zlogout ~/.zlogout
safe_link $DOTFILES/zsh/zprofile ~/.zprofile
safe_link $DOTFILES/zsh/zshenv ~/.zshenv
safe_link $DOTFILES/zsh/zshrc ~/.zshrc
safe_link $DOTFILES/zsh/p10k.zsh ~/.p10k.zsh
safe_link $DOTFILES/zsh/prezto ~/.zprezto
safe_link $DOTFILES/zsh/zpreztorc ~/.zpreztorc
safe_link $DOTFILES/zsh/zplug ~/.zplug
safe_link $DOTFILES/zsh ~/.zsh
# bash symlink
safe_link $DOTFILES/bash/bashrc ~/.bashrc
# fzf symlink
safe_link $DOTFILES/zsh/fzf ~/.fzf
safe_link $DOTFILES/zsh/fzf.zsh ~/.fzf.zsh
safe_link $DOTFILES/bash/fzf.bash ~/.fzf.bash
# vim, neovim symlink
safe_link $DOTFILES/vim/vimrc ~/.vimrc
safe_link $DOTFILES/vim ~/.vim
safe_link $DOTFILES/nvim ~/.config/nvim
# nano symlink
safe_link $DOTFILES/nano ~/.nano
safe_link $DOTFILES/nano/nanorc ~/.nanorc
# tmux symlink
safe_link $DOTFILES/tmux/tmux.conf ~/.tmux.conf
safe_link $DOTFILES/tmux ~/.tmux
# git symlink
safe_link $DOTFILES/git/.gitconfig ~/.gitconfig
safe_link $DOTFILES/git/.gitignore ~/.gitignore
# bin symlink
safe_link $DOTFILES/bin ~/.bin
}
symlink_automatic () {
# zsh symlink
automatic_link $DOTFILES/zsh/zfunc ~/.zfunc
automatic_link $DOTFILES/zsh/zlogin ~/.zlogin
automatic_link $DOTFILES/zsh/zlogout ~/.zlogout
automatic_link $DOTFILES/zsh/zprofile ~/.zprofile
automatic_link $DOTFILES/zsh/zshenv ~/.zshenv
automatic_link $DOTFILES/zsh/zshrc ~/.zshrc
automatic_link $DOTFILES/zsh/p10k.zsh ~/.p10k.zsh
automatic_link $DOTFILES/zsh/prezto ~/.zprezto
automatic_link $DOTFILES/zsh/zpreztorc ~/.zpreztorc
automatic_link $DOTFILES/zsh/zplug ~/.zplug
automatic_link $DOTFILES/zsh ~/.zsh
# bash symlink
automatic_link $DOTFILES/bash/bashrc ~/.bashrc
# fzf symlink
automatic_link $DOTFILES/zsh/fzf ~/.fzf
automatic_link $DOTFILES/zsh/fzf.zsh ~/.fzf.zsh
automatic_link $DOTFILES/bash/fzf.bash ~/.fzf.bash
# vim, neovim symlink
automatic_link $DOTFILES/vim/vimrc ~/.vimrc
automatic_link $DOTFILES/vim ~/.vim
automatic_link $DOTFILES/nvim ~/.config/nvim
# nano symlink
automatic_link $DOTFILES/nano ~/.nano
automatic_link $DOTFILES/nano/nanorc ~/.nanorc
# tmux symlink
automatic_link $DOTFILES/tmux/tmux.conf ~/.tmux.conf
automatic_link $DOTFILES/tmux ~/.tmux
# git symlink
automatic_link $DOTFILES/git/.gitconfig ~/.gitconfig
automatic_link $DOTFILES/git/.gitignore ~/.gitignore
# bin symlink
automatic_link $DOTFILES/bin ~/.bin
}
set_git_secret_config () {
echo -e "${YELLOW}Set git secret config${NC}"
if [ ! -f ~/.gitconfig.secret ];
then
touch ~/.gitconfig.secret
echo -e "${YELLOW}Register git user name / email${NC}"
echo -ne "${YELLOW}Enter your name: ${NC}"
read username
echo -ne "${YELLOW}Enter your email: ${NC}"
read useremail
git config --file ~/.gitconfig.secret user.name "$username"
git config --file ~/.gitconfig.secret user.email "$useremail"
echo -e "${YELLOW}Register git credential helper ${NC}"
echo -e "${YELLOW}1. Do not register${NC}"
echo -e "${YELLOW}2. Register permanently (store)${NC}"
echo -e "${YELLOW}3. Regieter temporarily (cache)${NC}"
echo -ne "${YELLOW}Enter your choice: ${NC}"
read choice
case $choice in
1)
;;
2|s|store)
git config --file ~/.gitconfig.secret credential.helper "store"
;;
3|c|cache)
git config --file ~/.gitconfig.secret credential.helper "cache --timeout=3600"
;;
*)
echo -e "${RED}Invalid choice. ${NC}"
;;
esac
echo
# print current .gitconfig.secret config
echo -e "${GREEN}Current git secret config${NC}"
echo -ne "${GREEN}user.name: ${NC}"; git config --file ~/.gitconfig.secret user.name
echo -ne "${GREEN}user.email: ${NC}"; git config --file ~/.gitconfig.secret user.email
echo -ne "${GREEN}credential.helper: ${NC}"; git config --file ~/.gitconfig.secret credential.helper
echo
else
echo -e "${RED}~/.gitconfig.secret already exists. ${NC}"
echo
fi
}
update_submodule() {
cd $DOTFILES
git submodule update --init --recursive
}
case $1
in
i*|interact)
echo -e "${RED}| ${YELLOW}interactive installation ${RED}| ${NC}\n"
symlink
set_git_secret_config
update_submodule
;;
a*|auto)
echo -e "${RED}| ${YELLOW}automatic installation ${RED}| ${NC}\n"
symlink_automatic
update_submodule
;;
h*|help|*)
echo "Usage: bash install.sh [OPTION]"
echo "Options:"
echo ""
echo " interact Install interactively"
echo " auto Install automatically"
echo " help Print this help"
echo ""
esac