forked from kyau/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dotme
executable file
·385 lines (378 loc) · 11.7 KB
/
dotme
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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
#!/usr/bin/env bash
# $KYAULabs: dotme,v 2.1.2 2021/07/10 11:14:39 kyau Exp $
# Configuration {{{
# location of dotfiles repository
#[email protected]:kyau/dotfiles.git
repo=https://github.com/kyau/dotfiles.git
# folder the repo will be stored in (~/$repofolder)
repo_folder="dot"
# package installer
pkgman="pikaur"
# configs in the root directory
root_files=( "bash_profile" "bashrc" "gitconfig" "ssh/config" "ssh/authorized_keys" "tmux.conf" "vimrc" )
# xorg configs in the root directory
root_files_xorg=( "Xmodmap" "Xresources" "xbindkeysrc" "xinitrc" )
# directories in the root directory
root_dir=( "bash.d" "irssi" "tmux" "vim" )
# xorg directories in the root directory
root_dir_xorg=( "ncmpcpp" )
# configs inside ~/.config/
config_files=( "starship.toml" )
# xorg configs inside ~/.config/
config_files_xorg=( "compton.conf" )
# directories inside ~/.config/
config_dir=( "fish" "htop" "ranger" )
# xorg directories inside ~/.config/
config_dir_xorg=( "ckb-next" "i3" "mpd" "mpv" "polybar" "vis" )
# }}}
# CONFIG DONE ~ DO NOT EDIT BELOW THIS LINE!
# here_be_dragons() {{{
function here_be_dragons() {
if [ -z "$1" ]; then return 0; fi
if [ -z "$2" ]; then local s=; else local s=$2; fi
if [ -z "$3" ]; then local dot=; else local dot=$3; fi
if [ -e "${destination}${s}/${dot}${1}" ]; then
if [ "${destination}${s}/${dot}${1}" == "${HOME}/.ssh" ]; then
printf "symlink: ignore: %s%s/%s%s\\n" "${destination}" "${s}" "${dot}" "${1}" >> "${destination}/${log}"
else
if [ -h "${destination}${s}/${dot}${1}" ]; then
if [ "$debug" == "1" ]; then
printf "\\n \\x1b[31m \\uf057 \\x1b[0m ~%s/%s%s \\x1b[1;30m(current sym-link will be deleted)\\x1b[0m" "${s}" "${dot}" "${1}"
else
printf "symlink: delete: %s%s/%s%s\\n" "${destination}" "${s}" "${dot}" "${1}" >> "${destination}/${log}"
/bin/rm "${destination}${s}/${dot}${1}"
fi
else
if [ "$debug" == "1" ]; then
printf "\\n \\x1b[1;34m \\ue706 \\x1b[0m ~%s/%s%s \\x1b[1;30m(backup: ~%s/%s.ibk)\\x1b[0m" "${s}" "${dot}" "${1}" "${s}" "${1}"
else
printf "symlink: backup: %s%s/%s%s.ibk\\n" "${destination}" "${s}" "${dot}" "${1}" >> "${destination}/${log}"
/bin/mv "${destination}${s}/${dot}${1}" "${destination}${s}/${1//\//_}.ibk"
fi
fi
fi
fi
if [ "$s" == "/.config" ]; then
local t=/config
else
local t=$s
fi
if [ -e "${HOME}/${repo_folder}${t}/${1}" ]; then
if [ "$debug" == "1" ]; then
printf "\\n \\x1b[1;36m \\uf064 \\x1b[0m %s%s/%s \\x1b[1;37m \\uf061 \\x1b[0m ~%s/%s%s" "${repo_folder}" "${t}" "${1}" "${s}" "${dot}" "${1}"
else
/bin/ln -s "${HOME}/${repo_folder}${t}/${1}" "${destination}${s}/${dot}${1}"
printf "symlink: create: %s%s/%s -> %s/%s%s\\n" "${repo_folder}" "${t}" "${1}" "${s}" "${dot}" "${1}" >> "${destination}/${log}"
fi
else
printf "\\n \\x1b[31mERROR: \\x1b[1;37m~/%s%s/%s \\x1b[0mnot found\\x1b[0m" "${repo_folder}" "${t}" "${1}"
printf "! symlink: ERROR: ~/%s%s/%s not found\\n" "${repo_folder}" "${t}" "${1}" >> "${destination}/${log}"
testpass=0
fi
}
# }}}
# symlink_master() {{{
function symlink_master() {
local tmparr=()
dest=
local directory=0
local dot=
case "$1" in
root_files)
tmparr=("${root_files[@]}")
dot=.
;;
root_files_xorg)
tmparr=("${root_files_xorg[@]}")
dot=.
;;
root_dir)
tmparr=("${root_dir[@]}")
dot=.
directory=1
;;
root_dir_xorg)
tmparr=("${root_dir_xorg[@]}")
dot=.
directory=1
;;
config_files)
tmparr=("${config_files[@]}")
dest=/.config
;;
config_files_xorg)
tmparr=("${config_files_xorg[@]}")
dest=/.config
;;
config_dir)
tmparr=("${config_dir[@]}")
dest=/.config
directory=1
;;
config_dir_xorg)
tmparr=("${config_dir_xorg[@]}")
dest=/.config
directory=1
;;
*)
return 0
;;
esac
if [ "$directory" == "0" ]; then
for file in "${tmparr[@]}"; do
here_be_dragons "$file" "$dest" "$dot"
done
elif [ "$directory" == "1" ]; then
for dir in "${tmparr[@]}"; do
here_be_dragons "$dir" "$dest" "$dot"
done
fi
}
# }}}
# gitclone() {{{
function gitclone() {
printf "\\x1b[1;30m \\uf141 \\x1b[0m \\x1b[37m%sCloning repository\\x1b[0m " "${testing}"
if [ -d "${HOME}/${repo_folder}" ]; then
if [ "$debug" == "1" ]; then printf "\\n "; fi
printf "\\x1b[1;33m \\uf12a \\x1b[0m "
if [ "$debug" == "1" ]; then
printf "%s/%s \\x1b[1;30m(directory exists)\\x1b[0m\\n" "${HOME}" "${repo_folder}"
else
printf "\\n"
fi
printf "! download: WARNING: %s already exists\\n" "${repo_folder}" >> "${destination}/${log}"
testpass=0
else
if git clone --quiet ${repo} "${HOME}/${repo_folder}" | sed 's/^/\t/' >> "${destination}/${log}"; then
#if [ $? -eq 0 ]; then
printf "\\x1b[1;32m \\uf00c \\x1b[0m\\n"
else
printf "\\x1b[31m \\uf00d \\x1b[0m\\n"
fi
fi
if [ "$debug" == "1" ]; then
printf " \\x1b[0;37m Test "
if [ "$testpass" == "1" ]; then
printf "\\x1b[1;32mPass \\uf00c \\x1b[0m\\n"
else
printf "Fail \\x1b[31m \\uf00d \\x1b[0m\\n"
fi
fi
cd "${HOME}/${repo_folder}" || exit 1
testpass=1
}
# }}}
# symlink() {{{
function symlink() {
printf "\\x1b[1;30m \\uf141 \\x1b[0m \\x1b[37m%sLink configs\\x1b[0m " "${testing}"
printf "symlink: creating symbolic links...\\n" >> "${destination}/${log}"
if [ ! -d "${destination}/.config/" ]; then
if [ "$debug" == "1" ]; then
printf "\\n \\x1b[1;36m \\uf067 \\x1b[0m ~/.config \\x1b[1;30m(mkdir)\\x1b[0m"
else
/bin/mkdir "${destination}/.config"
fi
fi
symlink_master root_files
symlink_master root_dir
symlink_master config_files
symlink_master config_dir
if [ "$1" == "1" ]; then
symlink_master root_files_xorg
symlink_master root_dir_xorg
symlink_master config_files_xorg
symlink_master config_dir_xorg
fi
if [ "$debug" == "1" ]; then printf "\\n \\x1b[0;37m Test "; fi
if [ "$testpass" == "1" ]; then printf "Pass \\x1b[1;32m \\uf00c \\x1b[0m\\n"; else printf "Fail \\x1b[31m \\uf00d \\x1b[0m\\n"; fi
testpass=1
}
# }}}
# bindir() {{{
function bindir() {
printf "\\x1b[1;30m \\uf141 \\x1b[0m \\x1b[37m%sLink bin\\x1b[0m " "${testing}"
if [ -e "${destination}/bin" ]; then
if [ -h "${destination}/bin" ]; then
if [ "$debug" == "1" ]; then
printf "\\n \\x1b[31m \\uf057 \\x1b[0m ~/bin \\x1b[1;30m(current sym-link will be deleted)\\x1b[0m"
else
printf "bin: delete: %s/bin\\n" "${destination}" >> "${destination}/${log}"
/bin/rm "${destination}/bin"
fi
else
if [ "$debug" == "1" ]; then
printf "\\n \\x1b[1;34m \\ue706 \\x1b[0m ~/bin \\x1b[1;30m(backup: ~/bin.ibk)\\x1b[0m"
else
printf "bin: backup: %s/bin\\n" "${destination}" >> "${destination}/${log}"
/bin/mv "${destination}/bin" "${destination}/bin.ibk"
fi
fi
fi
if [ -d "${HOME}/$repo_folder/bin" ]; then
if [ "$debug" == "1" ]; then
printf "\\n \\x1b[0;37m Test "
printf "Pass \\x1b[1;32m \\uf00c \\x1b[0m\\n"
else
/bin/ln -s "${HOME}/${repo_folder}/bin" "$destination/bin"
printf "\\x1b[1;32m \\uf00c \\x1b[0m\\n"
fi
else
printf "\\n \\x1b[31mERROR: \\x1b[1;37m~/%s/bin\\x1b[0m not found" "${repo_folder}"
printf "! symlink: ERROR: ~/%s/bin not found\\n" "${repo_folder}" >> "${destination}/${log}"
if [ "$debug" == "1" ]; then
printf "\\n \\x1b[0;37m Test "
printf "Fail \\x1b[31m \\uf00d \\x1b[0m\\n"
fi
fi
}
# }}}
# install() {{{
function install() {
testpass=1
if [ -z "$1" ]; then return 0; fi
printf "\\x1b[1;30m \\uf141 \\x1b[0m \\x1b[37m%sInstalling packages\\x1b[0m " "${testing}"
if [ -f "${HOME}/${repo_folder}/.pkg-${1}" ]; then
IFS=$'\n' read -d '' -r -a pkglist < "$HOME/$repo_folder/.pkg-$1"
if [ ${#pkglist[@]} -eq 0 ]; then
printf " \\x1b[1;33m \\uf12a \\x1b[0m No packages detected\\n"
else
if [ "$debug" == "1" ]; then
printf "\\n \\x1b[0m Verifying packages:\\x1b[0m "
else
printf "\\n \\x1b[0m Installing packages:\\x1b[0m "
fi
local first=1
for pkg in "${pkglist[@]}"; do
pkgc=
if [ "${pkg:0:1}" == "#" ]; then continue; fi
#if [ "$first" == "1" ]; then
# printf "\x1b[1;30m%s\x1b[0m" "${pkg}"
#else
# printf ", \x1b[1;30m%s\x1b[0m" "${pkg}"
#fi
if [ "$debug" == "1" ]; then
local pacman=0
local aur=0
if pacman -Ssq "$pkg" | grep "^$pkg$" > /dev/null; then
#if [ $? -eq 0 ]; then
pacman=1
else
pacman=0
fi
if [ "$pacman" == "0" ]; then
if git ls-remote -q --exit-code "https://aur.archlinux.org/$pkg.git" > /dev/null; then
#if [ $? -eq 0 ]; then
aur=1
else
aur=0
fi
fi
if [ "$pacman" == "1" ] || [ "$aur" == "1" ]; then
pkgc="\\x1b[0;36m"
else
pkgc="\\x1b[0;31m"
testpass=0
fi
else
#if yes 2>/dev/null | $pkgman -Sq "$pkg" --noconfirm > /dev/null; then
if $pkgman -S "$pkg" --noedit --nodiff --noconfirm > /dev/null 2>&1; then
#if [ $? -eq 0 ]; then
pkgc="\\x1b[0;36m"
printf "pkg: install: %s installed\\n" "${pkg}" >> "${destination}/${log}"
else
pkgc="\\x1b[0;31m"
testpass=0
printf "pkg: ERROR: %s failed install\\n" "${pkg}" >> "${destination}/${log}"
fi
fi
if [ "$first" == "1" ]; then
first=0
else
printf "\\x1b[0m, "
if [ "$debug" == "1" ] && [ "$aur" == "1" ]; then printf "%saur:" "${pkgc}"; fi
fi
#printf "%s%s\\x1b[0m" "${pkgc}" "${pkg}"
printf "${pkgc}%s\\x1b[0m" "${pkg}"
done
fi
else
printf "\\n \\x1b[31mERROR: \\x1b[1;37m~/%s/.pkg-%s\\x1b[0m not found" "${repo_folder}" "${1}"
printf "pkg: ERROR: ~/%s/.pkg-%s not found\\n" "${repo_folder}" "${1}" >> "${destination}/${log}"
fi
if [ "$debug" == "1" ]; then
printf "\\n \\x1b[0;37m Test "
if [ "$testpass" == "1" ]; then
printf "Pass \\x1b[1;32m \\uf00c \\x1b[0m\\n"
else
printf "Fail \\x1b[31m \\uf00d \\x1b[0m\\n"
fi
fi
}
# }}}
# fish() {{{
function fish() {
printf " Finish installing \\x1b[0;36mfish\\x1b[0m:\\n"
printf " * chsh -s /usr/bin/fish\\n"
printf " * fish\\n"
printf " * curl -sL https://git.io/fisher | source && fisher install jorgebucaran/fisher\\n"
printf " * fisher\\n"
printf " * git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm\\n"
printf " * git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim\\n\\n"
printf " * sh -c \"\$(curl -fsSL https://starship.rs/install.sh)\"\\n\\n"
}
# }}}
# show_help() {{{
# display usage if no arguments
function show_help() {
printf "Usage: %s [OPTION]...\\n" "${0}"
printf "Initiate the user environment. Does nothing with no OPTION.\\n"
printf " -i\\t\\tinstall user packages (.pkg-<profile>)\\n"
printf " -p <profile>\\tuser environment profile\\n"
printf " -t\\t\\tdebug mode: runs tests, informational only does not do anything\\n"
printf " -x\\t\\tinclude Xorg apps/configs (applies to -i and -s)\\n"
printf " -h\\t\\tdisplay this help and exit\\n\\n"
}
# }}}
# main() {{{
debug=0
log=install.log
destination=${HOME}
doinstall=0
testing=
testpass=1
xorg=0
if ! git --version >/dev/null 2>&1; then
#if [ ! $? -eq 0 ]; then
printf "\\x1b[1;33m \\uf12a \\x1b[1;37m dotme\\x1b[0m requires \\x1b[1;36mgit\\x1b[0m.\\n"
exit 1
fi
# check for arguments
if [ $# -eq 0 ] ; then
show_help
exit 1
fi
# parse arguments
while getopts hip:tx opt; do
case "$opt" in
t) debug=1;;
i) doinstall=1;;
p) profile=$OPTARG;;
x) xorg=1;;
h|\?|:|*) show_help; exit 1;;
esac
done
shift $((OPTIND - 1))
if [ -z "$profile" ]; then echo "You must specify a profile."; exit 1; fi
if [ ! -f "${destination}/${log}" ]; then
touch "${destination}/${log}"
fi
if [ "$debug" == "1" ]; then
testing=$(printf "\\x1b[1;35mRunning Test:\\x1b[0m ")
printf "\\x1b[1;35m \\ue00a Test Mode!\\x1b[0m\\n"
fi
printf "\\x1b[1;36m \\uf011 \\x1b[0m \\x1b[37mEnvironment:\\x1b[1;33m %s\\x1b[0m\\n" "${profile}"
gitclone; bindir
symlink "${xorg}"
if [ "$doinstall" == "1" ]; then install "${profile}"; fish; fi
# }}}
# vim: ft=bash sts=4 sw=4 ts=4 noet: