-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·402 lines (386 loc) · 10.5 KB
/
run.sh
File metadata and controls
executable file
·402 lines (386 loc) · 10.5 KB
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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
#!/usr/bin/env bash
readonly _FONTS_PKGLIST="${HOME}/dev/env/devenv.archive/pkglist/arch/fonts.pkgs"
readonly _BASE_PKGLIST="${HOME}/dev/env/devenv.archive/pkglist/arch/base.pkgs"
__is_excluded() {
local _item _excluded
_item="${1}"
shift
for _excluded in "$@"; do
[[ "${_excluded}" == "${_item}" ]] && return 0
done
return 1
}
__ping() {
local _host="${1}"
if ping -c 1 -W 1 "${_host}" &>/dev/null; then
echo "reached"
else
echo "unreached"
fi
}
__activate() {
local _service="${1}"
echo
echo "[::] info: activating ${_service} ..." >&2
[[ "${_service}" == "bluetooth" ]] && sudo modprobe btusb
[[ "${_service}" == "ufw" ]] && sudo ufw enable
sudo systemctl enable --now "${_service}"
sudo systemctl start --now "${_service}"
[[ "${_service}" == "ufw" ]] && sudo ufw status verbose
echo "[::] info: activating ${_service} ... done. exit(0)." >&2
echo
}
__install() {
local _file_path _type _items
_file_path="${1}"
_type="${2}"
if [[ ! -f "${_file_path}" ]]; then
echo
echo "[!!] error: file not found: '${_file_path}'." >&2
echo "[!!] error: installing ${_type} failed. exit(1)." >&2
echo
exit 1
fi
echo
echo "[::] info: installing ${_type} ..." >&2
mapfile -t _items < <(grep -vE "^\s*#|^\s*$" "${_file_path}")
((${#_items[@]} > 0)) && yay -S --noconfirm "${_items[@]}" || {
echo "[!!] error: installing ${_type} failed. exit(1)." >&2
echo
exit 1
}
[[ "${_type}" == "fonts" ]] && sudo fc-cache -fv
echo "[::] info: installing ${_type} ... done. exit(0)." >&2
echo
}
__link() {
local _src _dst _type _confirm
_src="${1}"
_dst="${2}"
_type="${3}"
echo
echo "[::] info: linking '${_dst##*/}' config ..." >&2
if [[ -L "${_dst}" && "$(readlink "${_dst}")" == "${_src}" ]]; then
echo "[::] info: skipped linking '${_dst}' config - already linked. exit(0)." >&2
echo
return 0
fi
if [[ "${_type}" == "dir" && -d "${_dst}" ]] || [[ "${_type}" == "file" && -f "${_dst}" ]]; then
echo "[~!] warn: '${_dst}' config exists. exit(1)." >&2
_confirm=""
read -rp "[::] info: remove it ? [y/N] " _confirm
_confirm="${_confirm,,}"
if [[ -n "${_confirm}" && "${_confirm}" =~ ^[Yy]$ ]]; then
rm -rf "${_dst}"
echo "[::] info: removed '${_dst}' config. exit(0)." >&2
else
echo "[::] info: skipped linking '${_dst##*/}' config. exit(0)." >&2
echo
return 0
fi
fi
ln -s "${_src}" "${_dst}"
echo "[::] info: linking '${_dst##*/}' config ... done. exit(0)." >&2
echo
}
_check() {
echo
echo "[::] info: checking requirements ..." >&2
local _exclude_list _value
_exclude_list=()
while (($# > 0)); do
case "${1}" in
--exclude=*)
_value="${1#--exclude=}"
if [[ -n "${_value}" ]]; then
IFS=',' read -ra _exclude_list <<<"${_value}"
else
_exclude_list=()
fi
shift
;;
*)
echo "[!!] error: unknown option '${1}'. exit(1)." >&2
echo
shift
exit 1
;;
esac
done
if __is_excluded "yay" "${_exclude_list[@]}"; then
echo "[::](yay) check: excluded. exit(0)." >&2
else
if [[ -n $(command -v yay) ]]; then
echo "[>>](yay) check: passed. exit(0)." >&2
else
echo "[>>](yay) check: failed." >&2
echo "[!!] error: 'yay' is not installed. exit(1)." >&2
echo
exit 1
fi
fi
if __is_excluded "hostname" "${_exclude_list[@]}"; then
echo "[::](hostname) check: excluded. exit(0)." >&2
else
if [[ "${HOSTNAME}" == "asa" ]]; then
echo "[>>](hostname) check: passed. exit(0)." >&2
else
echo "[>>](hostname) check: failed." >&2
echo "[!!] error: hostname must be 'asa' (got: '${HOSTNAME}'). exit(1)." >&2
echo
exit 1
fi
fi
if __is_excluded "user" "${_exclude_list[@]}"; then
echo "[::](user) check: excluded. exit(0)." >&2
else
if [[ "${USER}" == "akileshas" ]]; then
echo "[>>](user) check: passed. exit(0)." >&2
else
echo "[>>](user) check: failed." >&2
echo "[!!] error: user must be 'akileshas' (got: '${USER}'). exit(1)." >&2
echo
exit 1
fi
fi
if __is_excluded "ping" "${_exclude_list[@]}"; then
echo "[::](ping) check: excluded. exit(0)." >&2
else
if [[ $(__ping "8.8.8.8") == "reached" ]]; then
echo "[>>](ping) check: passed. exit(0)." >&2
else
echo "[>>](ping) check: failed." >&2
echo "[!!] error: disconnected. exit(1)." >&2
echo
exit 1
fi
fi
echo "[::] info: checking requirements ... done. exit(0)." >&2
echo
}
_sync() {
echo
echo "[::] info: updating and synchronizing the system ..." >&2
sudo pacman -Syyu --noconfirm
yay -Syyu --noconfirm
echo "[::] info: updating and synchronizing the system ... done. exit(0)." >&2
echo
}
_init() {
sudo -v
local _check_args _skip_check _skip_sync _value
_check_args=()
_skip_check=0
_skip_sync=0
while (($# > 0)); do
case "${1}" in
--check-exclude=*)
_value="${1#--check-exclude=}"
_check_args+=("--exclude=${_value}")
shift
;;
--skip-check)
_skip_check=1
shift
;;
--skip-sync)
_skip_sync=1
shift
;;
*)
echo "[!!] error: unknown option '${1}'. exit(1)." >&2
echo
shift
exit 1
;;
esac
done
if ((${_skip_check} == 0)); then
_check "${_check_args[@]}"
else
echo
echo "[::] info: skipping check. exit(0)." >&2
((${_skip_sync} == 1)) && echo
fi
if ((${_skip_sync} == 0)); then
_sync
else
echo "[::] info: skipping system synchronization. exit(0)." >&2
echo
fi
}
_pre() {
_init --check-exclude=yay,hostname --skip-sync
echo
echo "[#!](akileshas@asa) info: preparing my system ..." >&2
echo
echo "[::] info: creating directories ..." >&2
mkdir -p ~/Desktop \
~/.rtorrent \
~/Documents \
~/Documents/Books \
~/Documents/Papers \
~/Documents/Vault \
~/Documents/Vault/Personal \
~/Documents/Vault/Work \
~/Downloads \
~/Music \
~/Music/Playlist \
~/Music/Track \
~/Pictures \
~/Pictures/Vault \
~/Pictures/Wallpaper \
~/Pictures/Screenshots \
~/Public \
~/Templates \
~/Videos \
~/Videos/OBS \
~/Videos/Man \
~/dev \
~/dev/env \
~/dev/repos \
~/dev/mirrors \
~/dev/orgs \
~/dev/orgs/deepomni \
~/dev/orgs/deepomni/repos \
~/dev/orgs/deepomni/forks \
~/dev/orgs/deepomni/mirrors \
~/dev/orgs/deepomni/tmp \
~/dev/orgs/tinygrad \
~/dev/orgs/tinygrad/repos \
~/dev/orgs/tinygrad/forks \
~/dev/orgs/tinygrad/mirrors \
~/dev/orgs/tinygrad/tmp \
~/dev/tmp
echo "[::] info: creating directories ... done. exit(0)." >&2
echo
echo "[#!](akileshas@asa) info: preparing my system ... done. exit(0). ;)" >&2
echo
}
_setup() {
local _v
_init --check-exclude=hostname
echo
echo "[#!](akileshas@asa) info: setting up my system ..." >&2
__install "${_FONTS_PKGLIST}" "fonts"
__install "${_BASE_PKGLIST}" "base packages"
# __activate "bluetooth"
# __activate "paccache.timer"
__activate "power-profiles-daemon"
__activate "ufw"
__link ~/dev/env/devenv.archive/bash/inputrc ~/.inputrc "file"
__link ~/dev/env/devenv.archive/bash/login ~/.bash_login "file"
__link ~/dev/env/devenv.archive/bash/logout ~/.bash_logout "file"
__link ~/dev/env/devenv.archive/bash/profile ~/.bash_profile "file"
__link ~/dev/env/devenv.archive/bash/rc ~/.bashrc "file"
__link ~/dev/env/devenv.archive/fuzzel ~/.config/fuzzel "dir"
for _v in 2.0 3.0 4.0; do
__link ~/dev/env/devenv.archive/gtk/gtk-${_v} ~/.config/gtk-${_v} "dir"
done
__link ~/dev/env/devenv.archive/mako ~/.config/mako "dir"
__link ~/dev/env/devenv.archive/niri ~/.config/niri "dir"
__link ~/dev/env/devenv.archive/nvim-v0.11 ~/.config/nvim-devenv-v0.11 "dir"
__link ~/dev/env/devenv.archive/rtorrent/.rtorrent.rc ~/.rtorrent.rc "file"
__link ~/dev/env/devenv.archive/starship ~/.config/starship "dir"
__link ~/dev/env/devenv.archive/tmux/.tmux.conf ~/.tmux.conf "file"
__link ~/dev/env/devenv.archive/waybar ~/.config/waybar "dir"
__link ~/dev/env/devenv.archive/wezterm ~/.config/wezterm "dir"
echo "[#!](akileshas@asa) info: setting up my system ... done. exit(0). ;)" >&2
echo
}
_install_fonts() {
_init --check-exclude=hostname
echo
echo "[#!](akileshas@asa) info: installing system fonts ..." >&2
__install "${_FONTS_PKGLIST}" "fonts"
echo "[#!](akileshas@asa) info: installing system fonts ... done. exit(0). ;)" >&2
echo
}
_usage() {
echo
echo "'akileshas@asa' system setup script" >&2
echo
echo "usage:" >&2
echo " bash ./run.sh [options]" >&2
echo " bash ./run.sh [command] [options]" >&2
echo
echo "commands:" >&2
echo " init [options] initialize system (runs checks and optionally syncs)." >&2
echo " --check-exclude=items exclude checks (comma-separated: yay,user,hostname)." >&2
echo " --skip-check skip checks step." >&2
echo " --skip-sync skip system sync step." >&2
echo " check [options] run pre-flight checks (yay, user, hostname, ping)." >&2
echo " --exclude=items exclude checks (comma-separated: yay,user,host)." >&2
echo " sync sync system time and update mirrors/packages." >&2
echo " pre pre-install setup (e.g. enabling services)." >&2
echo " setup run main setup logic (install packages, fonts, link dotfiles)." >&2
# echo " post post-setup steps (e.g. enable services, cleanup)." >&2
echo " install-fonts install system fonts." >&2
echo
echo "options:" >&2
echo " -h, --help show help message." >&2
echo
}
_main() {
case "${1}" in
--help | -h)
_usage
shift
exit 0
;;
"")
_init
exit 0
;;
esac
echo
echo "[\$_] info: building the system ..." >&2
case "${1}" in
init)
shift
_init "$@"
exit 0
;;
sync)
_sync
shift
exit 0
;;
check)
shift
_check "$@"
exit 0
;;
pre)
_pre
shift
exit 0
;;
setup)
_setup
shift
exit 0
;;
# post )
# _post
# shift
# exit 0
# ;;
install-fonts)
_install_fonts
shift
exit 0
;;
*)
echo "[!!] error: unknown option '${1}'. exit(1)." >&2
echo
shift
exit 1
;;
esac
echo "[\$_] info: building the system ... done. exit(0). [ʘ‿ʘ]" >&2
echo
}
_main "$@"
unset -f __is_excluded __ping __activate __install __link _check _sync _init _pre _setup _install_fonts _usage _main
unset _FONTS_PKGLIST _BASE_PKGLIST