-
Notifications
You must be signed in to change notification settings - Fork 3
/
install.sh
executable file
·260 lines (233 loc) · 7.15 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
#!/bin/bash
BLUE=$(tput setaf 4)
RED=$(tput setaf 1)
YELLOW=$(tput setaf 3)
GREEN=$(tput setaf 2)
STD=$(tput sgr0)
# This is a general-purpose function to ask Yes/No questions in Bash, either
# with or without a default answer. It keeps repeating the question until it
# gets a valid answer.
ask() {
# http://djm.me/ask
while true; do
if [ "${2:-}" = "Y" ]; then
prompt="Y/n"
default=Y
elif [ "${2:-}" = "N" ]; then
prompt="y/N"
default=N
else
prompt="y/n"
default=
fi
# Ask the question (not using "read -p" as it uses stderr not stdout)
echo
echo -n " $1 [$prompt] "
# Read the answer (use /dev/tty in case stdin is redirected from somewhere else)
read REPLY </dev/tty
# Default?
if [ -z "$REPLY" ]; then
REPLY=$default
fi
# Check if the reply is valid
case "$REPLY" in
Y*|y*) return 0 ;;
N*|n*) return 1 ;;
esac
done
}
# Prints out the relative path between to absolute paths. Trivial.
#
# Parameters:
# $1 = first path
# $2 = second path
#
# Output: the relative path between 1st and 2nd paths
relpath() {
local pos="${1%%/}" ref="${2%%/}" down=''
while :; do
test "$pos" = '/' && break
case "$ref" in $pos/*) break;; esac
down="../$down"
pos=${pos%/*}
done
echo "$down${ref##$pos/}"
}
install_symlink () {
if [ -z "$3" ]; then
LINK_NAME=$2
else
LINK_NAME=$3
fi
if [ ! -e $HOME/$LINK_NAME ] && [ ! -d $HOME/$LINK_NAME ]; then
cd $(dirname $HOME/$LINK_NAME)
ln -s "$(relpath "$PWD" "$1")"/$2 $(basename $3)
cd -
echo " ${GREEN}Installed symlink for $2${STD}";
else
echo " ${YELLOW}Symlink for $2 already exists${STD}";
fi
}
install_tmux () {
if [ ! -e $HOME/.tmux/plugins/tpm ]; then
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
fi
install_symlink $PWD .tmux.conf
install_symlink $PWD .tmuxline
}
is_tmux_installed () {
if [ -e $HOME/.tmux.conf ] || [ -d $HOME/.tmux.conf ]; then
echo "installed"
fi
}
install_vim () {
install_symlink $PWD .vimrc
install_symlink $PWD .vimperatorrc
install_symlink $PWD .ycm_extra_conf.py .vim/.ycm_extra_conf.py
}
is_vim_installed () {
if ( [ -e $HOME/.vimrc ] || [ -d $HOME/.vimrc ] ) &&
[ -h $HOME/.vim/.ycm_extra_conf.py ] &&
[ -h $HOME/.vimperatorrc ]; then
echo "installed"
fi
}
install_git () {
CHANGE_SETTINGS=0
if [[ -z $is_git_installed ]]; then
if ! ask "Do you like to change your git settings?" N; then
CHANGE_SETTINGS=1
fi
fi
if [[ $CHANGE_SETTINGS -eq 0 ]]; then
echo
echo " Please enter your git user name and email address!"
echo
read -p " ${BLUE}Name:${STD} " gitname
read -p " ${BLUE}Email:${STD} " gitemail
echo
sed -i "s/\(name\ =\ \).*$/\1$gitname/g" .gitconfig
sed -i "s/\(email\ =\ \).*$/\1$gitemail/g" .gitconfig
echo " Replaced git name and email in .gitconfig"
fi
install_symlink $PWD .gitconfig
}
is_git_installed () {
if [ -e $HOME/.gitconfig ] || [ -d $HOME/.gitconfig ]; then
echo "installed"
fi
}
install_gpg () {
# Disable gnome-keyring ssh-agent
if [[ $(gconftool-2 --get /apps/gnome-keyring/daemon-components/ssh) != "false" ]]; then
gconftool-2 --type bool --set /apps/gnome-keyring/daemon-components/ssh false
fi
# Disable X11 gpg-agent by removing its startup script
sudo mv /etc/X11/Xsession.d/90gpg-agent .
if ask "You already have a gpg config! Do you like to replace it?" Y; then
rm $HOME/.gnupg/gpg.conf
rm $HOME/.gnupg/gpg-agent.conf
rm $HOME/.gnupg/scdaemon.conf
fi
install_symlink $PWD gpg.conf .gnupg/gpg.conf
install_symlink $PWD gpg-agent.conf .gnupg/gpg-agent.conf
install_symlink $PWD scdaemon.conf .gnupg/scdaemon.conf
}
is_gpg_installed () {
if [ -h $HOME/.gnupg/gpg.conf ] &&
[ -h $HOME/.gnupg/gpg-agent.conf ] &&
[ -h $HOME/.gnupg/scdaemon.conf ]; then
echo "installed"
fi
}
install_bash () {
if [ -e $HOME/.bashrc ] && [ ! -h $HOME/.bashrc ]; then
if ask "You already have a .bashrc! Do you like to replace it?" Y; then
mv $HOME/.bashrc $HOME/.bashrc.bak
echo " Renamed existing .bashrc to .bashrc.bak"
install_symlink $PWD .bashrc
fi
else
install_symlink $PWD .bashrc
fi
install_symlink $PWD .bash_exports
install_symlink $PWD .liquidpromptrc
install_symlink $PWD .lesspipe.sh
install_symlink $PWD .LESS_TERMCAP
git submodule update --init --remote
install_symlink $PWD liquidprompt/liquidprompt .liquidprompt
if ask "Do you like to install source highlighting in less and grep? [requires sudo]" Y; then
if ! type "source-highlight" >/dev/null 2>&1; then
if type "apt-get" >/dev/null 2>&1; then
echo " Insert your password to install source-highlight for less:"
sudo apt-get --assume-yes install source-highlight 2>&1 >/dev/null
echo " Installed source-highlight for less"
fi
if type "pacman" >/dev/null 2>&1; then
echo " Insert your password to install source-highlight for less:"
sudo pacman -S --noconfirm source-highlight 2>&1 >/dev/null
echo " Installed source-highlight for less"
fi
fi
fi
}
is_bash_installed () {
if [ -e $HOME/.bashrc ] &&
[ -e $HOME/.liquidpromptrc ] &&
[ -e $HOME/.lesspipe.sh ] &&
[ -e $HOME/.LESS_TERMCAP ]; then
echo "installed"
fi
}
while :
do
clear
cat<<EOF
==============================================
Sappo's dotfile installer
----------------------------------------------
Please enter which dotfile to install
bashrc ${BLUE}(1)${STD} - ${GREEN}$(is_bash_installed)${STD}
gitconfig ${BLUE}(2)${STD} - ${GREEN}$(is_git_installed)${STD}
gpg ${BLUE}(3)${STD} - ${GREEN}$(is_gpg_installed)${STD}
vimrc ${BLUE}(4)${STD} - ${GREEN}$(is_vim_installed)${STD}
tmux ${BLUE}(5)${STD} - ${GREEN}$(is_tmux_installed)${STD}
${BLUE}(A)ll${STD}
${BLUE}(U)pdate${STD}
${BLUE}(Q)uit${STD}
----------------------------------------------
EOF
read -n1 -s
case "$REPLY" in
"1")
install_bash
;;
"2")
install_git
;;
"3")
install_gpg
;;
"4")
install_vim
;;
"5")
install_tmux
;;
"A")
install_bash
install_git
install_gpg
install_vim
install_tmux
;;
"U")
git submodule foreach git pull --rebase origin master
;;
"q") exit;;
"Q") exit;;
* ) echo -e " ${RED}Invalid option...${STD}";;
esac
echo
read -p " Press ${BLUE}[Enter]${STD} key to continue..." fackEnterKey
done