-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·288 lines (257 loc) · 6.23 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
#!/bin/bash
#vim:et:sw=2
REQUIRED_COMMANDS=(realpath curl git)
function check_executable {
local COMMAND=$1
which "$COMMAND" &> /dev/null
if [[ $? == 0 ]]; then
return 0
else
echo "Executable required is not installed: $COMMAND."
return 1
fi
}
result=0
message=""
for CMD in ${REQUIRED_COMMANDS[@]}; do
message="$( check_executable ${CMD} )\n"
let "result += $?"
done
if [[ "${result}" -ne '0' ]]; then
printf "$message"
exit 1
fi
BASE=$(realpath $(dirname $0))
source ${BASE}/setup.cfg
HELP="Commands\n"
function append_help {
COMMAND="$1"
MESSAGE="$2"
HELP+=$(printf '%-20s %s' "$COMMAND" "$MESSAGE")
HELP+="\n"
}
append_help "usage" "Prints this text."
function show_help {
echo -ne "$HELP"
}
function backup_file {
local DST=$1
local BAK="$BACKUP/$FILENAME"
echo "Backing up $DST to $BAK"
mv "$DST" "$BAK"
}
function link_to_config {
local FILENAME=$1
local SRC="$DOT_FILES/$FILENAME"
local DST="$HOME/.config/$FILENAME"
if [[ ! -e $(dirname $DST) ]]; then
echo "Creating '.config' directory"
mkdir -p $(dirname $DST)
fi
if [[ -L "$DST" ]] && [[ "$(readlink "$DST")" == "$SRC" ]]; then
echo "Link to $DST already made"
return
fi
if [[ -e "$DST" ]] && [[ ! -L "$DST" ]]; then
backup_file "$DST"
fi
echo "Linking $SRC to $DST"
ln "$LN_OPTS" "$SRC" "$DST"
}
function link_to_home {
local FILENAME=$1
local SRC="$DOT_FILES/$FILENAME"
local DST="$HOME/.$FILENAME"
if [[ -L $DST ]] && [[ "$(readlink "$DST")" == "$SRC" ]]; then
echo "Link to $DST already made"
return
fi
if [[ -e $DST ]] && [[ ! -L $DST ]]; then
backup_file "$DST"
fi
echo "Linking $SRC to $DST"
ln "$LN_OPTS" "$SRC" "$DST"
}
append_help "zsh" "Installs antigen and link my custom folder."
function install_zsh {
if check_executable 'zsh'; then
if [[ ! -d "$ANTIGEN_HOME" ]]; then
git clone "$ANTIGEN_URL" "$ANTIGEN_HOME"
else
echo "antigen already installed."
fi
link_to_home 'antigenrc'
link_to_home 'zshrc'
link_to_home 'zsh'
fi
}
append_help "nvim" "Checks for nvim installation, link the config folders and install nvim-plugged"
function install_nvim {
if check_executable 'nvim'; then
link_to_config 'nvim'
if [[ ! -f "$VIM_PLUG_FILE" ]]; then
curl -fLo "$VIM_PLUG_FILE" --create-dirs "$VIM_PLUG_URL"
echo "vim-plug installed."
else
echo "vim-plug already installed."
fi
nvim +PlugInstall +qa
fi
}
append_help "fonts" "Copy 'Source Code Pro For Powerline' to $FONT_DST, and runs fcache"
function install_fonts {
if [[ ${OS_NAME} -eq "osx" ]]; then
install_fonts_osx
else
install_fonts_linux
fi
}
function install_fonts_osx {
IFS=$(printf '\t\n\r')
for FONT in $FONT_SRC/*; do
FONT=$(basename $FONT)
cp "$FONT_SRC/$FONT" "$FONT_DST/$FONT"
done
}
function install_fonts_linux {
if check_executable 'fc-cache'; then
IFS=$(printf '\t\n\r')
if [[ ! -d "${FONT_DST}" ]]; then
echo "Create ${FONT_DST} directory"
mkdir -p "${FONT_DST}"
fi
for FONT in ${FONT_SRC}/*; do
FONT=$(basename ${FONT})
cp "${FONT_SRC}/${FONT}" "${FONT_DST}/${FONT}"
done
fc-cache "${FONT_DST}"
fi
}
append_help "git" "Links my gitconfig."
function install_git {
if check_executable 'git' ; then
link_to_home 'gitconfig'
link_to_home 'gitignore'
link_to_home 'git-commit-template.txt'
fi
}
append_help "tmux" "Links tmux.conf"
function install_tmux {
if check_executable 'tmux' ; then
link_to_config 'tmux.conf'
fi
install_tpm
if [[ ${OS_NAME} == 'linux' ]]; then
echo "Installing tmux systemd service"
if [[ ! -d "${SYSTEMD_USER_HOME}" ]]; then
mkdir -p ${SYSTEMD_USER_HOME}
fi
cp ${SYSTEMD_UNIT_SRC}/tmux.service ${SYSTEMD_USER_HOME}/tmux.service
systemctl daemon-reload
systemctl --user enable tmux.service
systemctl --user start tmux.service
fi
}
function install_tpm {
if [[ ! -d "$TPM_HOME" ]]; then
echo 'Installing tpm'
git clone https://github.com/tmux-plugins/tpm "$TPM_HOME"
fi
tmux run-shell "$TPM_HOME/bindings/install_plugins"
}
append_help "terminal" "Links and configure the systems terminal configuration"
function install_terminal {
if [[ "${DEFAULT_TERMINAL}" == 'iterm' ]]; then
echo "Using .iterm folder as iterm configuration"
link_to_home "iterm"
defaults write com.googlecode.iterm2.plist PrefsCustomFolder -string "~/.iterm"
defaults write com.googlecode.iterm2.plist LoadPrefsCustomFolder -bool true
elif [[ "${DEFAULT_TERMINAL}" == 'gnome-terminal' ]]; then
${HELPERS}/gnome-terminal.sh
else
echo "No terminal configured"
fi
}
append_help "keyboard" "Configures the keyboard"
function install_keyboard {
if ! which localectl 2>&1 > /dev/null; then
echo "Could not find localectl in the system"
return 1
fi
localectl --no-convert set-x11-keymap us,us pc105 intlm 'lv3:ralt_switch,caps:escape,terminate:ctrl_alt_bksp'
localectl --no-convert set-keymap us-acentos
if [[ ${DESKTOP_SESSION} == 'gnome' ]]; then
gsettings set 'org.gnome.desktop.input-sources' xkb-options '["lv3:ralt_switch", "caps:escape", "terminate:ctrl_alt_bksp"]'
fi
}
append_help "i3" "Links and configure i3vm"
function install_i3 {
echo "Using .i3 folder as iterm configuration"
if ! check_executable 'i3' ; then
return 1
fi
link_to_home 'config/i3'
}
append_help "all" "Runs all the above."
function install_all {
echo "Installing all."
install_zsh
install_nvim
install_fonts
install_tmux
install_git
install_i3
install_terminal
install_keyboard
}
function os_opts {
case "$(uname)" in
'Linux')
LN_OPTS='-sfi'
FONT_DST="$HOME/.fonts"
OS_NAME='linux'
DEFAULT_TERMINAL='gnome-terminal'
;;
'Darwin')
LN_OPTS='-shi'
FONT_DST="$HOME/Library/Fonts"
OS_NAME='osx'
DEFAULT_TERMINAL='iterm'
;;
esac
}
os_opts
mkdir "$BACKUP" 2>/dev/null
case "$1" in
'zsh')
install_zsh
;;
'nvim')
install_nvim
;;
'fonts')
install_fonts
;;
'git')
install_git
;;
'tmux')
install_tmux
;;
'terminal')
install_terminal
;;
'keyboard')
install_keyboard
;;
'i3')
install_i3
;;
'all')
install_all
;;
*)
show_help
;;
esac
exit 0