-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.sh
487 lines (384 loc) · 11.1 KB
/
main.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
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
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
#!/bin/bash
pwd=$(
cd "$(dirname "$0")" || exit
pwd
)
sdir="${pwd}/software"
xhome="$HOME"
xconf="${xhome}/.config"
source "${pwd}/scripts/colorecho.sh"
source "${pwd}/scripts/try.sh"
#============================================#
# Terminal #
#============================================#
function do_terminal_fish() {
print_sub_title "fish"
try_link_dir "${sdir}/fish" "${xconf}/fish"
}
function do_terminal_zsh() {
print_sub_title "zsh"
# check zsh is default
local cmd="$SHELL"
if [[ $cmd == *"zsh" ]]; then
print_ok "defaulted zsh"
else
print_warn "zsh is not default shell"
chsh -s "$(which zsh)"
print_info "you should reboot system and go on..."
exit 0
fi
# zinit install
try_link_file "${sdir}/zsh/.zshenv" "${xhome}/.zshenv"
try_link_file "${sdir}/zsh/.zshrc" "${xhome}/.zshrc"
if [ ! -f "${xconf}/zsh/zinit/zinit.git/zinit.zsh" ]; then
exec zsh
else
print_ok "installed zinit"
fi
package_link "zsh/nobodygx" "${sdir}/zsh/nobodygx" "${xconf}/zsh/nobodygx"
# zinit finish
}
function do_terminal_foot() {
print_sub_title "foot"
package_link "foot"
}
function do_terminal_alacritty() {
print_sub_title "alacritty"
package_link "alacritty"
}
function do_terminal_wezterm() {
print_sub_title "wezterm"
package_install "wezterm"
package_install "fish"
local dst="${xconf}/wezterm"
if [ ! -d "$dst" ]; then
package_install "nerd-fonts-sarasa-term"
try_link_dir "${sdir}/wezterm" "${xconf}/wezterm"
fi
}
function do_terminal_vim() {
print_sub_title "vim"
package_install "vim"
try_mkdir "${xconf}/vim"
package_link "vim/color" "${sdir}/vim/colors" "${xconf}/vim/colors"
try_link_file "${sdir}/vim/vimrc" "${xconf}/vim/vimrc"
}
function do_terminal() {
print_title "terminal" 5
do_terminal_fish
do_terminal_zsh
do_terminal_foot
do_terminal_alacritty
do_terminal_wezterm
do_terminal_vim
}
#============================================#
# Input Method #
#============================================#
function do_input_method_fcitx() {
print_sub_title "fcitx5"
package_install "fcitx5"
package_install "fcitx5-chinese-addons"
package_install "fcitx5-im" "fcitx5-qt"
package_install "fcitx5-configtool"
}
function do_input_method_env() {
print_sub_title "write input env"
try_add_text_sudo "GTK_IM_MODULE=fcitx5" "/etc/environment"
try_add_text_sudo "QT_IM_MODULE=fcitx5" "/etc/environment"
try_add_text_sudo "XMODIFIERS=@im=fcitx5" "/etc/environment"
try_add_text_sudo "INPUT_METHOD=fcitx5" "/etc/environment"
try_add_text_sudo "SDL_IM_MODULE=fcitx5" "/etc/environment"
print_ok "defined input env"
}
function do_input_method() {
print_title "input_method" 2
do_input_method_fcitx
do_input_method_env
}
#============================================#
# User Files #
#============================================#
function do_user_files() {
print_sub_title "config user-dirs"
local src="$pwd/system/user-dirs.dirs"
local dst=${xconf}/user-dirs.dirs
if ! grep -q "downloads" "$dst"; then
try_mv "Documents" "documents"
try_mv "Downloads" "downloads"
try_mv "Pictures" "pictures"
try_mv "Public" "public"
try_mv "Music" "music"
try_mv "Videos" "videos"
try_copy_file "$src" "$dst"
fi
print_ok "defined user-dirs"
return 0
}
function do_user_filemanager() {
print_sub_title "install_fm"
package_install "yazi"
package_install "superfile"
}
function do_files() {
print_title "file manager" 2
do_user_filemanager
do_user_files
}
#============================================#
# Develop Tools #
#============================================#
function do_dev_conda() {
print_sub_title "conda"
package_install "miniconda3"
local src="${sdir}/conda/.condarc"
local dst="${xhome}/.condarc"
if [ ! -f "$dst" ]; then
try_copy_file "$sdir" "$dst"
fi
src="${sdir}/conda/pip.conf"
dst="${xconf}/pip/pip.conf"
if [ ! -f "$dst" ]; then
try_copy_file "$sdir" "$dst"
fi
}
function do_dev_ollama() {
print_sub_title "ollama"
# can use ollama[cuda], but gpu is weak
package_install "ollama"
local src="${sdir}/ollama/ollama.service"
local dst="/etc/systemd/system/ollama.service"
# add user
if ! id -u "ollama" >/dev/null 2>&1; then
sudo_run "useradd -r -s /bin/false -m -d /usr/share/ollama ollama"
fi
if id -u "ollama" >/dev/null 2>&1; then
print_ok "installed user(ollama)"
else
print_err "add user(ollama)"
fi
# add ollama.service
if [ ! -f "$dst" ]; then
sudo_run "cp $src $dst"
fi
if [ -f "$dst" ]; then
print_ok "installed ollama.service"
fi
sudo_run "systemctl start ollama"
}
function do_dev_gitea() {
print_sub_title "gitea"
package_install "gitea"
local src="${sdir}/gitea/gitea.service"
local dst="/usr/lib/systemd/system/gitea.service"
if ! check_by_grep_cat_sudo "$dst" "XGit"; then
sudo_run "cp -f $src $dst"
fi
if check_by_grep_cat_sudo "$dst" "XGit"; then
print_ok "installed gitea.service"
else
print_err "install gitea.service"
fi
src="${sdir}/gitea/app.ini"
dst="/code/code_repos/gitea_env/gitea_home/app.ini"
if ! check_by_grep_cat "$dst" "xgit"; then
cp -f "$src" "$dst"
fi
if check_by_grep_cat "$dst" "xgit"; then
print_ok "installed gitea.ini"
else
print_err "install gitea.ini"
fi
}
function do_dev() {
print_title "dev" 5
do_dev_conda
do_dev_ollama
do_dev_gitea
}
#============================================#
# Text #
#============================================#
function do_text_vscode() {
print_sub_title "vscode"
package_install "vscodium-bin"
package_install "vscodium-bin-features"
# package_install "vscodium-bin-marketplace"
try_copy_file "${sdir}/vscode/User/settings.json" "${xconf}/VSCodium/User/settings.json"
}
function do_text_pulsar() {
print_sub_title "pulsar"
package_install "pulsar-bin"
cd "${xhome}/.pulsar/packages"
eval "$(tombl -e PKGS=packages ${sdir}/pulsar/packages.toml)"
for apkg in ${PKGS[@]}
do
local pname=$(echo $apkg | awk -F '/' '{print $5}')
if [[ "$pname" ]];then
fi
# git clone --depth=1 "$apkg"
echo $pname
done
cd -
try_copy_file "${sdir}/pulsar/config.cson" "${xhome}/.pulsar/config.cson"
}
function do_text_helix() {
print_sub_title "pulsar"
package_install "helix"
local src="${sdir}/helix/config.toml"
local dst="${xconf}/helix/config.toml"
try_link_file "$src" "$dst"
# src="${sdir}/helix/languages.toml"
# dst="${xconf}/helix/languages.toml"
# try_link_file "$src" "$dst"
src="/usr/bin/helix"
dst="/usr/bin/vi"
if [ ! -h "$dst" ]; then
print_info "start link $src ==> $dst"
sudo_run "ln -s $src $dst"
fi
if [ -h $dst ]; then
print_ok "link vi"
else
print_err "link vi err, try manul"
fi
}
function do_text() {
print_title "text" 4
do_text_vscode
do_text_pulsar
do_text_helix
}
#============================================#
# Browser #
#============================================#
function write_firefox_css() {
local tdir="$1"
local src="$sdir/firefox/userChrome.css"
local dst="$tdir/chrome/userChrome.css"
local dstdir
dstdir=$(dirname "$dst")
try_mkdir "$dstdir"
if [ ! -f "$dst" ]; then
try_copy_file "$src" "$dst"
fi
if [ -f "$dst" ]; then
print_ok "Checked firefox userCss"
fi
}
function do_browser_firefox() {
print_sub_title "firefox"
package_install "firefox"
local src="${xhome}/.mozilla/firefox"
find "$src" -mindepth 1 -maxdepth 1 -type d | while read -r mdir; do
if [[ $mdir == *"default" || $mdir == *"default-release" ]]; then
write_firefox_css "$mdir"
fi
done
}
#============================================#
# Disk #
#============================================#
function write_fstab() {
local diskname="$1"
local mpoint="$2"
local cmd="" dtype="" duuid="" content=""
if [ ! -d "$mpoint" ]; then
print_info "try create $mpoint"
sudo_run "mkdir -p $mpoint"
fi
cmd=$(sudo_run "lsblk -f")
dtype=$(echo "$cmd" | grep "$diskname" | awk '{print $2}')
duuid=$(echo "$cmd" | grep "$diskname" | awk '{print $4}')
content="UUID=$duuid $mpoint $dtype defaults,noatime,nodiratime 0 0"
local dst="/etc/fstab"
sudo_run "echo '' >> $dst"
sudo_run "echo \# /dev/$diskname >> $dst"
sudo_run "echo $content >> $dst"
sudo_run "echo '' >> $dst"
}
function check_todo_disk() {
local cmd=""
cmd=$(sudo_run "lsblk -f")
if ! echo "$cmd" | grep -q "sda1"; then
return 1
fi
if ! echo "$cmd" | grep -q "sdb1"; then
return 2
fi
local dst="/etc/fstab"
if check_by_grep_cat_sudo "$dst" "/dev/sda1"; then
return 3
fi
if check_by_grep_cat_sudo "$dst" "/dev/sdb1"; then
return 4
fi
return 0
}
function do_disk_mount() {
print_sub_title "mount disk"
if ! check_todo_disk; then
print_ok 'checked mount'
return 0
fi
local dst="/etc/fstab"
if ! check_by_grep_cat_sudo "$dst" "/data"; then
write_fstab "sda1" "/data"
else
print_ok 'mounted /data'
fi
if ! check_by_grep_cat_sudo "$dst" "/code"; then
write_fstab "sdb1" "/code"
else
print_ok 'mounted /code'
fi
}
function do_disk() {
print_title "didk" 1
do_disk_mount
}
function do_network_networkmanager() {
print_sub_title "networkmanager"
package_install "dhcpcd"
local src="${pwd}/system/networkmanager/NetworkManager.conf"
local dst="/etc/NetworkManager/NetworkManager.conf"
if ! check_by_grep_cat_sudo "$dst" "wifi.backend=iwd"; then
print_info "cp $src ==> $dst"
sudo_run "cp -f $src $dst"
else
print_ok "installed NetworkManager.conf"
return 0
fi
if ! check_by_grep_cat_sudo "$dst" "wifi.backend=iwd"; then
print_err "install NetworkManager.conf wrong"
else
print_ok "installed NetworkManager.conf"
fi
# src="${pwd}/system/networkmanager/conf.d/dhcp-client.conf"
# dst="/etc/NetworkManager/conf.d/dhcp-client.conf"
# if [ -f $dst ];then
# print_info "cp $src ==> $dst"
# sudo_run "cp -f $src $dst"
# fi
}
function do_network() {
print_title "network" 1
do_network_networkmanager
}
function main() {
do_terminal
do_input_method
do_files
do_browser
do_text
do_dev
do_software
do_disk
do_network
echo_rainbow "#========== END ==========#"
}
function custom_main() {
do_text_pulsar
}
#main "$@"
custom_main