-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.sh
executable file
·330 lines (297 loc) · 8.29 KB
/
setup.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
#!/bin/bash
. $(dirname $0)/abstract.sh
. $(dirname $0)/functions.sh
echo -e ${INFO} " __ ___ __ __ _____ __ "${DEFAULT};
echo -e ${INFO} " / |/ /_ __ ____/ /___ / /_/ __(_) /__ _____ "${DEFAULT};
echo -e ${INFO} " / /|_/ / / / / / __ / __ \/ __/ /_/ / / _ \/ ___/ "${DEFAULT};
echo -e ${INFO} " / / / / /_/ / / /_/ / /_/ / /_/ __/ / / __(__ ) "${DEFAULT};
echo -e ${INFO} " /_/ /_/\__ / \____/\____/\__/_/ /_/_/\___/____/ "${DEFAULT};
echo -e ${INFO} " /____/ \n"${DEFAULT};
# Init variables {{{
# Current path
CUR_PATH=$(pwd)
FROM_HOME=$(echo ${PWD#$HOME})
WITH_COMPOSER=0
OVERRIDE_CONFS=0
WITH_NODE=0
WITH_SSH=0
WITH_CASKS=0
# Define the current distrib and the install command
if [[ "$(uname -s)" == "Darwin" ]]; then
OS='mac'
INSTALLCMD='brew install'
elif [[ "$(uname -s)" == "Linux" ]]; then
if [ -f /etc/debian_version ]; then
OS='debian'
INSTALLCMD='apt-get install -y'
elif [ -f /etc/redhat-release ]; then
OS='redhat'
INSTALLCMD='yum install -y'
fi
fi
# }}}
# Help {{{
display_help()
{
# echo -e $INFO
echo -e "Usage :"
echo -e " ./setup.sh <options>\n"
echo -e "Options :"
echo -e " -h, --help Display this help"
echo -e " -o, --override-confs Override configuration files if they exist"
echo -e " --with-composer Install composer and the static analysis / unit test tools"
echo -e " --with-node Install NodeJS, NPM and some NodeJS packages (grunt, bower)"
echo -e " --with-ssh Install ssh 'bins' and configuration"
echo -e " --with-casks Install homebrew casks apps (only available for Mac OSX)\n"
# echo -e $DEFAULT
exit
}
# }}}
# Check command arguments {{{
while test $# -gt 0
do
case "$1" in
-h | --help) display_help
;;
-o | --override-confs) OVERRIDE_CONFS=1
;;
--with-composer) WITH_COMPOSER=1
;;
--with-node) WITH_NODE=1
;;
--with-ssh) WITH_SSH=1
;;
--with-casks) WITH_CASKS=1
;;
esac
shift
done
# }}}
# Create a dotfiles configuration file to shared local config {{{
if [ ! -f ${HOME}/.dotfiles.conf ]; then
echo -e "\n${INFO}DOTFILES CONFIG FILE${DEFAULT}"
STEPMSG='Set dotfiles directory path'
echo -ne "${PROCESSMSG}${STEPMSG}"\\r
OUTPUT=$(echo "export DOTFILESDIR=\$HOME${FROM_HOME}" > ${HOME}/.dotfiles.conf 2>/dev/null)
if [ $? -ne 0 ]; then
echo -e "${ERRORMSG}${STEPMSG}"
echo -e ${WARN}${OUTPUT}${DEFAULT}
exit 1
fi
echo -e "${SUCCESSMSG}${STEPMSG}"
STEPMSG='Register current user login'
echo -ne "${PROCESSMSG}${STEPMSG}"\\r
USERNAME=$(whoami)
OUTPUT=$(echo "export USERLOGIN=${USERNAME}" >> ${HOME}/.dotfiles.conf 2>/dev/null)
if [ $? -ne 0 ]; then
echo -e "${ERRORMSG}${STEPMSG}"
echo -e ${WARN}${OUTPUT}${DEFAULT}
exit 1
fi
echo -e "${SUCCESSMSG}${STEPMSG}"
fi
# }}}
# Install required apps {{{
# We need Git, Zsh Tmux, ... to be installed
echo -e "\n${INFO}COMMANDS${DEFAULT}"
COMMANDS_LIST=(
"ansible"
"autojump"
"bat"
"cmake"
"diff-so-fancy"
"dnsmasq"
"dos2unix"
"fzf"
"git-extras"
"git-flow"
"git-lfs"
"git-standup"
"gnu-sed"
"gnu-tar"
# "gpg-agent"
"htop"
"mkcert"
"mycli"
"netcat"
"nvm"
"openssl"
"pgcli"
"prettyping"
"python3"
"pyenv"
"rbenv"
"rsync"
"socat"
"tmux"
"tree"
"unison"
"unzip"
"vim"
"watch"
"wget"
"zsh"
)
for i in "${COMMANDS_LIST[@]}"
do
check_command $i
done
GEMS_LIST=(
"tmuxinator"
"docker-sync"
"dotenv"
"bundler"
)
for i in "${GEMS_LIST[@]}"
do
install_gem $i
done
# }}}
# Install external libraries (like oh-my-zsh, scm_breeze, ...) {{{
echo -e "\n${INFO}EXTERNAL LIBS${DEFAULT}"
STEPMSG='Download external libraries'
echo -ne "${PROCESSMSG}${STEPMSG}"\\r
OUTPUT=$(git submodule update --init --recursive 2>&1 >/dev/null)
if [ $? -ne 0 ]; then
echo -e "${ERRORMSG}${STEPMSG}"
echo -e ${WARN}${OUTPUT}${DEFAULT}
exit 1
fi
echo -e "${SUCCESSMSG}${STEPMSG}"
# }}}
# Configure shell {{{
echo -e "\n${INFO}SHELL${DEFAULT}"
# Apply configuration for zsh
symlink_config "config/zsh" ".zshrc"
# Enable common aliases
symlink_config "config/aliases" ".aliases"
# }}}
# Apply configuration for vim {{{
echo -e "\n${INFO}VIM${DEFAULT}"
symlink_config "config/vim" ".vimrc"
if [ ! -d ~/.vim/backup ]; then
mkdir -p ~/.vim/backup
fi
if [ ! -d ~/.vim/swap ]; then
mkdir -p ~/.vim/swap
fi
if [ ! -d ~/.vim/undo ]; then
mkdir -p ~/.vim/undo
fi
if [ ! -d ~/.vim/autoload ]; then
mkdir -p ~/.vim/autoload
fi
if [ ! -d ~/.vim/plugged ]; then
mkdir -p ~/.vim/plugged
fi
# Install Vim plugin manager Plug
STEPMSG="Installing VIM plugin manager"
if [ ! -f ~/.vim/autoload/plug.vim ]; then
echo -ne "${PROCESSMSG}${STEPMSG}"\\r
OUTPUT=$(curl -fLo ~/.vim/autoload/plug.vim https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim 2>&1 >/dev/null)
if [ $? -ne 0 ]; then
echo -e "${ERRORMSG}${STEPMSG}"
echo -e ${WARN}${OUTPUT}${DEFAULT}
exit 1
fi
echo -e "${SUCCESSMSG}${STEPMSG}"
else
echo -e "${SKIPMSG}${STEPMSG}"
fi
# }}}
# Apply configuration for tmux {{{
symlink_config "config/tmux" ".tmux.conf"
echo -e "\n${INFO}TMUX${DEFAULT}"
# Install tmuxinator autocompletion script for zsh
STEPMSG="Installing tmuxinator autocompletion script for zsh"
if [ ! -f ~/.bin/tmuxinator.zsh ]; then
if [ ! -d ~/.bin ]; then
mkdir -p ~/.bin
fi
echo -ne "${PROCESSMSG}${STEPMSG}"\\r
OUTPUT=$(wget -P ~/.bin/ https://raw.githubusercontent.com/tmuxinator/tmuxinator/master/completion/tmuxinator.zsh 2>&1 >/dev/null)
if [ $? -ne 0 ]; then
echo -e "${ERRORMSG}${STEPMSG}"
echo -e ${WARN}${OUTPUT}${DEFAULT}
exit 1
fi
echo -e "${SUCCESSMSG}${STEPMSG}"
else
echo -e "${SKIPMSG}${STEPMSG}"
fi
# }}}
# Apply configuration for git {{{
echo -e "\n${INFO}GIT${DEFAULT}"
symlink_config "config/git/config" ".gitconfig"
if [ ! -d ~/.gitconfig.d ]; then
mkdir -p ~/.gitconfig.d
fi
symlink_config "config/git/ignore" ".gitconfig.d/.gitignore_global"
symlink_config "config/git/commit.template" ".gitconfig.d/.gitcommit.template"
if [ ! -f ~/.gitconfig_local ]; then
read -r -p "What is your full name ? " USERNAME
read -r -p "What is your email address? " USEREMAIL
STEPMSG="Configuring GIT user name and email"
echo -ne "${PROCESSMSG}${STEPMSG}"\\r
OUTPUT=$(cat templates/.gitconfig_local.tpl | sed -e "s|##USERNAME##|${USERNAME}|g" | sed -e "s|##USEREMAIL##|${USEREMAIL}|g" > ~/.gitconfig_local 2>/dev/null)
if [ $? -ne 0 ]; then
echo -e "${ERRORMSG}${STEPMSG}"
echo -e ${WARN}${OUTPUT}${DEFAULT}
exit 1
fi
echo -e "${SUCCESSMSG}${STEPMSG}"
fi
# }}}
# Install composer {{{
if [[ ${WITH_COMPOSER} -eq 1 ]]; then
echo -e "\n${INFO}COMPOSER${DEFAULT}"
if [ ! -f /usr/local/bin/composer ]; then
STEPMSG="Installing Composer"
echo -ne "${PROCESSMSG}${STEPMSG}"\\r
OUTPUT=$(curl -sS https://getcomposer.org/installer | php && mv composer.phar /usr/local/bin/composer 2>&1 >/dev/null)
if [ $? -ne 0 ]; then
echo -e "${ERRORMSG}${STEPMSG}"
echo -e ${WARN}${OUTPUT}${DEFAULT}
exit 1
fi
echo -e "${SUCCESSMSG}${STEPMSG}"
else
STEPMSG="Updating Composer"
echo -ne "${PROCESSMSG}${STEPMSG}"\\r
OUTPUT=$(composer self-update 2>&1 >/dev/null)
if [ $? -ne 0 ]; then
echo -e "${ERRORMSG}${STEPMSG}"
echo -e ${WARN}${OUTPUT}${DEFAULT}
exit 1
fi
echo -e "${SUCCESSMSG}${STEPMSG}"
fi
COMPOSER_PKG_LIST=(
"hirak/prestissimo"
)
for i in "${COMPOSER_PKG_LIST[@]}"
do
install_composer_pkg $i
done
fi
# }}}
# Apply configuration for ssh {{{
if [[ ${WITH_SSH} -eq 1 ]]; then
echo -e "\n${INFO}SSH${DEFAULT}"
if [ ! -d ~/.ssh ]; then
mkdir ~/.ssh
fi
symlink_config "config/ssh" ".ssh/config"
# Installing ssh config files stored on Dropbox
if [ -f ~/Dropbox/dotfiles/ssh/setup.sh ]; then
. ~/Dropbox/dotfiles/ssh/setup.sh
fi
fi
# }}}
# Custom OS setup {{{
if [ -f "$(dirname $0)/setup-${OS}.sh" ];then
. $(dirname $0)/setup-${OS}.sh
fi
# }}}
echo -e ${INFO}"\nYou are all set. You can now define zsh as your default shell using the command :\nchsh -s $(which zsh)"${DEFAULT}