-
Notifications
You must be signed in to change notification settings - Fork 0
/
arch-os
executable file
·1322 lines (1131 loc) · 58.4 KB
/
arch-os
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
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# shellcheck disable=SC1090
set -Eeo pipefail
# ///////////////////////////////////////////////////////////////////
# ARCH OS MANAGER
# - Arch Linux Helper Script TUI -
# ///////////////////////////////////////////////////////////////////
# SOURCE: https://github.com/murkl/arch-os-manager
# AUTOR: murkl
# ORIGIN: Germany
# LICENCE: GPL 2.0
# SCRIPT VERSION
VERSION="1.6.6"
# HOME
ARCH_OS_HOME="${HOME}/.arch-os"
# CONFIG
ARCH_OS_CONF="${ARCH_OS_HOME}/config/settings.conf"
ARCH_OS_BLACKLIST="${ARCH_OS_HOME}/config/blacklist.conf"
ARCH_OS_KITTY_CONF="${ARCH_OS_HOME}/config/kitty.conf"
# DATABASE
PACKAGES_DB="${ARCH_OS_HOME}/database/packages.db"
NEWS_DB="${ARCH_OS_HOME}/database/news.db"
UPDATES_DB="${ARCH_OS_HOME}/database/updates.db"
STATE_DB="${ARCH_OS_HOME}/database/state.db"
# TEMP
ARCH_OS_TMP="$(mktemp -d "/tmp/arch-os.XXXXXXX")"
MIRRORLIST_TMP="${ARCH_OS_TMP}/mirrorlist"
# STATE
HEADER_PRINTED="false"
# COLORS
# Color chart: https://github.com/muesli/termenv?tab=readme-ov-file#color-chart
COLOR_PURPLE=212
COLOR_WHITE=7
COLOR_GREEN=2
COLOR_YELLOW=3
COLOR_RED=1
# ///////////////////////////////////////////////////////////////////
# MAIN FUNCTION
# ///////////////////////////////////////////////////////////////////
main() {
# Init properties
init_properties
# Install
[ "$1" = '--install' ] && {
install_script_dependencies && exit 0
exit 1
}
# Check dependencies
if ! command -v /usr/bin/gum &>/dev/null; then echo "ERROR: gum not found. Install with: sudo pacman -S gum" >&2 && exit 1; fi
if ! command -v /usr/bin/kitty &>/dev/null; then echo "ERROR: kitty not found. Install with: sudo pacman -S kitty" >&2 && exit 1; fi
if ! command -v /usr/bin/checkupdates &>/dev/null; then echo "ERROR: checkupdates not found. Install with: sudo pacman -S pacman-contrib" >&2 && exit 1; fi
if ! command -v /usr/bin/notify-send &>/dev/null; then echo "ERROR: notify-send not found. Install with: sudo pacman -S libnotify" >&2 && exit 1; fi
# Set Traps
trap 'trap_error $? ${FUNCNAME} ${LINENO}' ERR # Set error trap
trap 'trap_exit $?' EXIT # Set exit trap
# Init state & init properties
init_state && persist_properties
# Sync database & exit
if [ "$1" = '--sync' ]; then
if shift && [ $# -eq 0 ]; then
sync_news_db
sync_package_db
sync_updates_db
exit 2
fi
for arg in "$@"; do
case "$arg" in
'news') sync_news_db ;;
'packages') sync_package_db ;;
'updates') sync_updates_db ;;
*) exit 3 ;;
esac
done
exit 2
fi
# Start kitty & exit
if [ "$1" = '--kitty' ] || [ "$1" = '-k' ]; then
shift # Shift argument to next
# Start kitty if not already present
if [ "$TERM" != "xterm-kitty" ]; then
kitty "$SELF" "$@" # Open script in kitty instance
exit 2
fi
fi
# Check number of user arguments
if [ $# -gt 1 ]; then
print_header && show_help && echo && gum_red --bold "Max. 1 argument supported!" && gum_confirm_continue
exit 3
fi
# User action argument
local user_action="$1"
# -------------------------------------------------------------------
while (true); do
# Show menu if user action argument is NOT set
local selected_action && if [ -z "$user_action" ]; then
clear_screen && print_header
local user_input options
options=("Search Package" "System Info" "Upgrade System" "Remove Orphans" "Merge Configurations" "Refresh Mirrorlist" "Downgrade Packages" "Clear Cache" "Reset Keyring" "Settings" "Help" "Quit")
user_input=$(gum_choose --height=15 --selected="$user_input" "${options[@]}") || { clear_screen && exit 2; }
case "$user_input" in # Set user action to selected action
'Search Package') selected_action='search' ;;
'System Info') selected_action='info' ;;
'Upgrade System') selected_action='upgrade' ;;
'Remove Orphans') selected_action='orphans' ;;
'Merge Configurations') selected_action='merge' ;;
'Refresh Mirrorlist') selected_action='refresh' ;;
'Downgrade Packages') selected_action='downgrade' ;;
'Clear Cache') selected_action='cache' ;;
'Reset Keyring') selected_action='reset' ;;
'Settings') selected_action='settings' ;;
'Help') selected_action='help' ;;
'Quit') clear_screen && exit 2 ;;
esac
fi
# Set if user arg is available and no menu was shown
[ -z "$selected_action" ] && selected_action="$user_action"
# Execute action
local skip_confirm="false"
case "$selected_action" in # Execute action
'search') { print_header && show_search; } || { ret=$? && { [ "$ret" = 2 ]; } && skip_confirm="true"; } ;;
'info') { print_header && show_system_info; } || { ret=$? && { [ "$ret" = 2 ]; } && skip_confirm="true"; } ;;
'upgrade') { print_header && show_upgrade; } || { ret=$? && { [ "$ret" = 2 ]; } && skip_confirm="true"; } ;;
'orphans') { print_header && show_orphans; } || { ret=$? && { [ "$ret" = 2 ]; } && skip_confirm="true"; } ;;
'merge') { print_header && show_merge; } || { ret=$? && { [ "$ret" = 2 ]; } && skip_confirm="true"; } ;;
'refresh') { print_header && show_refresh; } || { ret=$? && { [ "$ret" = 2 ]; } && skip_confirm="true"; } ;;
'downgrade') { print_header && show_downgrade; } || { ret=$? && { [ "$ret" = 2 ]; } && skip_confirm="true"; } ;;
'cache') { print_header && show_clear_cache; } || { ret=$? && { [ "$ret" = 2 ]; } && skip_confirm="true"; } ;;
'reset') { print_header && show_reset_keyring; } || { ret=$? && { [ "$ret" = 2 ]; } && skip_confirm="true"; } ;;
'settings') { print_header && show_settings; } || { ret=$? && { [ "$ret" = 2 ]; } && skip_confirm="true"; } ;;
'help') { print_header && show_help; } || { ret=$? && { [ "$ret" = 2 ]; } && skip_confirm="true"; } ;;
'version') { print_header && show_version; } || { ret=$? && { [ "$ret" = 2 ]; } && skip_confirm="true"; } ;;
'notify') action_notify_updates || { ret=$? && { [ "$ret" = 2 ] || [ "$ret" = 3 ]; } && skip_confirm="true"; } ;;
'check') action_check_updates_available || { ret=$? && { [ "$ret" = 2 ] || [ "$ret" = 3 ]; } && skip_confirm="true"; } ;;
*) print_header && show_help && echo && gum_red --bold "Action '${selected_action}' not available!" ;;
esac
# Cleanup run (order is important!)
unset selected_action
[ -n "$user_action" ] && [ "$skip_confirm" = "true" ] && exit 2 # User arg IS avaiable & skip confirm -> exit
[ -z "$user_action" ] && [ "$skip_confirm" = "true" ] && continue # User arg NOT available & skip confirm -> continue
[ -z "$user_action" ] && [ "$skip_confirm" = "false" ] && { gum_confirm_continue || continue; } # User arg NOT available & confirm is canceled -> continue
[ -n "$user_action" ] && [ "$skip_confirm" = "false" ] && gum_confirm_continue # User arg IS avaiable -> continue
[ -n "$user_action" ] && exit 2 # User arg IS avaiable -> exit
done
}
# ///////////////////////////////////////////////////////////////////
# TRAP FUNCTIONS
# ///////////////////////////////////////////////////////////////////
# RETURN CODES
# 0 : success (confirm)
# 1 : error (confirm)
# 2 : success (no confirm)
# 3 : error (no confirm)
# 130 : cancel (no confirm)
trap_exit() {
rm -rf "$ARCH_OS_TMP"
[ "$1" != 2 ] && [ "$1" != 3 ] && [ "$1" != 130 ] && gum_confirm_continue
[ "$1" = 2 ] && exit 0 # Exit with 0 if return code is 2
exit "$1"
}
trap_error() {
[ "$1" != 2 ] && [ "$1" != 3 ] && [ "$1" != 130 ] && gum_fail "${BASH_COMMAND} failed ($1) in function '${2}' (line ${3})"
return "$1"
}
# ///////////////////////////////////////////////////////////////////
# STATE FUNCTIONS
# ///////////////////////////////////////////////////////////////////
init_state() {
touch "$STATE_DB" && source "$STATE_DB" && persist_state && return 0
return 1
}
persist_state() {
{ # Write state.db
echo "LATEST_UPDATE_CHECK=\"${LATEST_UPDATE_CHECK}\""
echo "LATEST_SYSTEM_UPGRADE=\"${LATEST_SYSTEM_UPGRADE}\""
echo "LATEST_ARCH_LINUX_NEWS_DATE=\"${LATEST_ARCH_LINUX_NEWS_DATE}\""
} >"$STATE_DB" && return 0
return 1
}
print_timestamp() { date +"%Y-%m-%d %H:%M:%S"; }
# ///////////////////////////////////////////////////////////////////
# PROPERTIES FUNCTIONS
# ///////////////////////////////////////////////////////////////////
init_properties() {
# Create working dirs
mkdir -p "$ARCH_OS_HOME"
mkdir -p "$ARCH_OS_TMP"
mkdir -p "${ARCH_OS_HOME}/config"
mkdir -p "${ARCH_OS_HOME}/database"
mkdir -p "${HOME}/.config/autostart"
# Migrate: < 1.5.5
[ -f "${ARCH_OS_HOME}/arch-os.conf" ] && mv -f "${ARCH_OS_HOME}/arch-os.conf" "${ARCH_OS_HOME}/settings.conf"
[ -f "${ARCH_OS_HOME}/kitty.conf" ] && mv -f "${ARCH_OS_HOME}/kitty.conf" "${ARCH_OS_HOME}/config/kitty.conf"
[ -f "${ARCH_OS_HOME}/packages.db" ] && mv -f "${ARCH_OS_HOME}/packages.db" "${ARCH_OS_HOME}/database/packages.db"
[ -f "${ARCH_OS_HOME}/news.db" ] && mv -f "${ARCH_OS_HOME}/news.db" "${ARCH_OS_HOME}/database/news.db"
# Migrate: < 1.5.7
[ -f "${ARCH_OS_HOME}/settings.conf" ] && mv -f "${ARCH_OS_HOME}/settings.conf" "${ARCH_OS_HOME}/config/settings.conf"
# -------------------------------------------------------------------
# Source config
touch "$ARCH_OS_CONF"
source "$ARCH_OS_CONF"
# Create blacklist.conf
touch "$ARCH_OS_BLACKLIST"
# Set default properties
[ -z "$AUTOSTART_NOTIFY" ] && AUTOSTART_NOTIFY="true"
[ -z "$AUTOSTART_DELAY" ] && AUTOSTART_DELAY="60"
[ -z "$AUR_MANGER_REPO" ] && AUR_MANGER_REPO="paru"
[ -z "$AUR_SUPPORT" ] && command -v /usr/bin/paru &>/dev/null && AUR_SUPPORT="true"
[ -z "$AUR_REVIEW" ] && AUR_REVIEW="false"
[ -z "$ARCH_UPGRADE_CONFIRM" ] && ARCH_UPGRADE_CONFIRM="true"
[ -z "$ARCH_DOWNLOAD_TIMEOUT" ] && ARCH_DOWNLOAD_TIMEOUT="false"
[ -z "$FLATPAK_SUPPORT" ] && command -v /usr/bin/flatpak &>/dev/null && FLATPAK_SUPPORT="true"
[ -z "$FLATPAK_UPGRADE_CONFIRM" ] && FLATPAK_UPGRADE_CONFIRM="false"
[ -z "$NEWS_QUANTITY" ] && NEWS_QUANTITY="3"
[ -z "$ORPHANS_CONFIRM" ] && ORPHANS_CONFIRM="false"
[ -z "$SHOW_SYSTEM_LOG" ] && SHOW_SYSTEM_LOG="true"
[ -z "$SHOW_SERVICE_LIST" ] && SHOW_SERVICE_LIST="true"
[ -z "$SHOW_UNKNOWN_PKG_LIST" ] && SHOW_UNKNOWN_PKG_LIST="false"
return 0
}
persist_properties() {
# Validate properties
[ "$AUTOSTART_DELAY" -gt 500 ] && AUTOSTART_DELAY="500" # Set to max 500
[ "$AUTOSTART_DELAY" -lt 10 ] && AUTOSTART_DELAY="10" # Set to min 10
[ "$NEWS_QUANTITY" -gt 10 ] && NEWS_QUANTITY="10" # Set to max 10
[ "$NEWS_QUANTITY" -lt 0 ] && NEWS_QUANTITY="0" # Set to min 0
# Check AUR binary
if [ "$AUR_SUPPORT" = "true" ]; then
local error && unset error
[ -z "$error" ] && ! command -v /usr/bin/paru &>/dev/null && error="/usr/bin/paru not found"
[ -z "$error" ] && ! /usr/bin/paru --version &>/dev/null && error="/usr/bin/paru is not working"
[ -n "$error" ] && {
gum_fail "$error"
notify_send "Error" "$error"
! gum_confirm --timeout=3s "Disable AUR_SUPPORT?" && gum_fail "Canceled" && exit 3
AUR_SUPPORT="false" && gum_warn "AUR_SUPPORT was disabled"
}
fi
# Check Flatpak binary
if [ "$FLATPAK_SUPPORT" = "true" ]; then
local error && unset error
[ -z "$error" ] && ! command -v /usr/bin/flatpak &>/dev/null && error="/usr/bin/flatpak not found"
[ -z "$error" ] && ! /usr/bin/flatpak --version &>/dev/null && error="/usr/bin/flatpak is not working"
[ -n "$error" ] && {
gum_fail "$error"
notify_send "Error" "$error"
! gum_confirm --timeout=3s "Disable FLATPAK_SUPPORT?" && gum_fail "Canceled" && exit 3
FLATPAK_SUPPORT="false" && gum_warn "FLATPAK_SUPPORT was disabled"
}
fi
# Toggle settings
if [ "$AUTOSTART_NOTIFY" = "true" ]; then
{
echo "[Desktop Entry]"
echo "Type=Application"
echo "Name=Arch OS Manager"
echo "Icon=${WORKING_DIR}/docs/logo.svg"
echo "Exec=bash -c 'sleep ${AUTOSTART_DELAY} && ${SELF} notify'"
} >"${HOME}/.config/autostart/arch-os.desktop"
else
rm -f "${HOME}/.config/autostart/arch-os.desktop"
fi
{ # Write properties
echo "ARCH_UPGRADE_CONFIRM=${ARCH_UPGRADE_CONFIRM}"
echo "ARCH_DOWNLOAD_TIMEOUT=${ARCH_DOWNLOAD_TIMEOUT}"
echo "AUR_MANGER_REPO=${AUR_MANGER_REPO}"
echo "AUR_SUPPORT=${AUR_SUPPORT}"
echo "AUR_REVIEW=${AUR_REVIEW}"
echo "FLATPAK_SUPPORT=${FLATPAK_SUPPORT}"
echo "FLATPAK_UPGRADE_CONFIRM=${FLATPAK_UPGRADE_CONFIRM}"
echo "ORPHANS_CONFIRM=${ORPHANS_CONFIRM}"
echo "AUTOSTART_NOTIFY=${AUTOSTART_NOTIFY}"
echo "AUTOSTART_DELAY=${AUTOSTART_DELAY}"
echo "NEWS_QUANTITY=${NEWS_QUANTITY}"
echo "SHOW_SYSTEM_LOG=${SHOW_SYSTEM_LOG}"
echo "SHOW_SERVICE_LIST=${SHOW_SERVICE_LIST}"
echo "SHOW_UNKNOWN_PKG_LIST=${SHOW_UNKNOWN_PKG_LIST}"
} >"$ARCH_OS_CONF"
# Source again
source "$ARCH_OS_CONF"
}
# ///////////////////////////////////////////////////////////////////
# DATABASE FUNCTIONS
# ///////////////////////////////////////////////////////////////////
sync_updates_db() {
# Remove database tmp file
mkdir -p "${ARCH_OS_TMP}"
local tmp_db="${ARCH_OS_TMP}/update.db.tmp"
rm -f "$tmp_db"
touch "$tmp_db"
# Pacman updates
while timeout 30 tail --pid=$(pgrep checkupdates) -f /dev/null &>/dev/null; do sleep 1; done
pgrep checkupdates &>/dev/null && gum_log_fail "Timeout after 30 seconds" && exit 3
while IFS= read -r line; do
[ -n "$line" ] && echo "$line" | sed 's/\x1b\[[0-9;]*m//g' | awk '{print "pacman," $1 "," $2 "," $4}' >>"$tmp_db"
done < <(/usr/bin/checkupdates || echo)
# AUR updates
if [ "$AUR_SUPPORT" = 'true' ] && /usr/bin/paru -Qua &>/dev/null; then
while read -r line; do
[ -n "$line" ] && echo "$line" | sed 's/\x1b\[[0-9;]*m//g' | awk '{print "aur," $1 "," $2 "," $4}' >>"$tmp_db"
done < <(/usr/bin/paru -Qua)
fi
# Flatpak updates
if [ "$FLATPAK_SUPPORT" = "true" ]; then
while read -r line; do
[ -n "$line" ] && echo "$line" | awk '{print "flatpak," $1 "," $2 "," ($3 == "" ? "latest" : $3)}' >>"$tmp_db"
done < <(flatpak remote-ls --updates --columns=application,version,branch | tail -n +1)
fi
# Perists update.db
mv -f "$tmp_db" "$UPDATES_DB"
# Persist state
LATEST_UPDATE_CHECK="$(print_timestamp)" && persist_state
return 0
}
sync_news_db() {
if [ -n "$NEWS_QUANTITY" ] && [ "$NEWS_QUANTITY" -gt 0 ]; then
curl -sf https://archlinux.org/feeds/news/ >"$NEWS_DB"
fi
return 0
}
sync_package_db() {
local tmp_db_default="${ARCH_OS_TMP}/packages-pac.db"
local tmp_db_aur="${ARCH_OS_TMP}/packages-aur.db"
! /usr/bin/pacman -Slq >"$tmp_db_default" && return 3
# Add AUR packages
if [ "$AUR_SUPPORT" = "true" ]; then
/usr/bin/paru -Slqa >"$tmp_db_aur" || rm -f "$tmp_db_aur"
[ -f "$tmp_db_aur" ] && cat "$tmp_db_aur" >>"$tmp_db_default"
fi
# Sort and remove redundant entries
#sort "$tmp_db_default" | uniq >"${tmp_db_default}.trim"
sort "$tmp_db_default" >"${tmp_db_default}.trim"
mv -f "${tmp_db_default}.trim" "$PACKAGES_DB"
return 0
}
# ///////////////////////////////////////////////////////////////////
# ACTION FUNCTIONS
# ///////////////////////////////////////////////////////////////////
action_check_updates_available() { # Check & print package updates
# Check if updates available
sync_updates_db && [ ! -s "$UPDATES_DB" ] && return 3
# Print updates in checkupdates format (g = green | b = bold | r = reset)
while IFS=',' read -r manager package_name current_version new_version; do
echo "${package_name} ${current_version} ${new_version}" |
awk -v r="$(tput sgr0 2>/dev/null)" \
-v b="$(tput bold 2>/dev/null)" \
-v g="$(tput setaf 2 2>/dev/null)" \
'{ printf "%s%s%s %s%s%s%s -> %s%s%s%s\n",
b, $1, r, # Package
b, g, $2, r, # Current version
b, g, $3, r # New version
}'
done <"$UPDATES_DB"
return 2
}
# -------------------------------------------------------------------
action_notify_updates() { # Notify on new updates
local update_result update_count update_txt
update_result="$(action_check_updates_available)" || true
update_count=0 && [ -n "$update_result" ] && update_count=$(echo "$update_result" | wc -l)
if [ "$update_count" -gt 0 ]; then
[ "$update_count" = 1 ] && update_txt="${update_count} Update available"
[ "$update_count" -gt 1 ] && update_txt="${update_count} Updates available"
notify_send "System Upgrade" "$update_txt"
echo "$update_result"
return 2
fi
return 3
}
# ///////////////////////////////////////////////////////////////////
# PRINT INFO FUNCTIONS
# ///////////////////////////////////////////////////////////////////
print_no_internet_info() {
for i in {1..3}; do
timeout 5 ping -c 1 -W 2 8.8.8.8 &>/dev/null && return 0
sleep 2
done
gum_fail "No Internet Connection" && return 3
}
# -------------------------------------------------------------------
print_system_error_logs() { journalctl -p 3 -b --quiet --no-pager | grep -E '^[A-Za-z]{3} [ 0-9]{1,2} [0-9:]{8} ' | grep -vf <(awk 'NF' "$ARCH_OS_BLACKLIST"); }
print_service_running() { systemctl list-units --type=service --state=running --plain --no-legend | while read -r line; do echo "${line}"; done; }
print_service_failed() { if systemctl --failed | grep -q 'failed'; then systemctl --failed --quiet | while read -r line; do echo "${line//● /}" | awk '{print $1}'; done; fi; }
# -------------------------------------------------------------------
show_news_info() { # Show Arch Linux News
if [ -n "$NEWS_QUANTITY" ] && [ "$NEWS_QUANTITY" -gt 0 ] && gum_title "Arch Linux News"; then
# Helper functions
print_news_date() { echo -n "$(<"$NEWS_DB")" | xmllint --xpath "string(//item[$1]/pubDate)" - | date -f - "+%Y/%m/%d"; }
print_news_title() { echo -n "$(<"$NEWS_DB")" | xmllint --xpath "string(//item[$1]/title)" -; }
print_news_url() { echo -n "$(<"$NEWS_DB")" | xmllint --xpath "string(//item[$1]/link)" - | awk '{$1=$1; print}'; }
# Sync db
print_no_internet_info || return 3
! gum_spin --title 'Synchronize News Database...' -- bash -c "${SELF} --sync news" && gum_fail "Synchronize Database (news) failed" && return 3
# Check unread news
local unread_news="false" && [ "$LATEST_ARCH_LINUX_NEWS_DATE" != "$(print_news_date 1)" ] && unread_news="true"
# Print news
for ((i = 1; i <= NEWS_QUANTITY; i++)); do
[ "$i" = "1" ] && [ "$unread_news" = "true" ] && gum_info "$(print_news_date "$i") | $(print_news_title "$i")" && continue
gum_mesg "$(print_news_date "$i") | $(print_news_title "$i")"
done
echo # New line
# Unread news?
if [ $unread_news = "true" ]; then
# Open in browser / print url (if xdg-utils is installed)
local open_browser="false"
command -v /usr/bin/xdg-open &>/dev/null && gum_confirm "Open in Browser?" && open_browser="true"
[ $open_browser = "true" ] && xdg-open "$(print_news_url 1)" &>/dev/null
[ $open_browser = "false" ] && gum_warn "Please open: $(print_news_url 1)" && echo
# Finish
! gum_confirm "Have you read the News?" && return 0
LATEST_ARCH_LINUX_NEWS_DATE="$(print_news_date 1)" && persist_state
fi
fi
return 0
}
# -------------------------------------------------------------------
show_update_info() { # Show package updates
gum_title "Update Information"
# Sync db
print_no_internet_info || return 3
! gum_spin --title 'Synchronize Update Database...' -- bash -c "${SELF} --sync updates" && gum_fail "Synchronize Database (updates) failed" && return 3
# Check if updates available
if ! [ -s "$UPDATES_DB" ]; then
gum_info "Your system is up to date"
return 0
fi
# Check max length
local manager_length=0 pkg_length=0 version_length=0 update_length=0
while IFS=',' read -r manager package version update; do
[ "${#manager}" -gt "$manager_length" ] && manager_length="${#manager}"
[ "${#package}" -gt "$pkg_length" ] && pkg_length="${#package}"
[ "${#version}" -gt "$version_length" ] && version_length="${#version}"
[ "${#update}" -gt "$update_length" ] && update_length="${#update}"
done <"$UPDATES_DB"
# Print updates
local reset="\033[0m" bold="\033[1m" green="\033[32m"
while IFS=',' read -r manager package version update; do
printf " • ${bold}%-${pkg_length}s ${reset}%-${version_length}s %-3s ${bold}${green}%-${update_length}s ${reset}${bold}%-s ${reset}%-${manager_length}s\n" \
"$package" "$version" "➜" "$update" "∷" "$manager" # ⟲ ⥄ ⇦ ➤ ➜ ≣
done <"$UPDATES_DB"
}
# -------------------------------------------------------------------
show_health_info() { # Show system health information
gum_title "System Health"
# Sync db
local sync_actions=()
[ "$1" = "--sync-updates" ] && sync_actions+=(updates)
[ ! -f "$PACKAGES_DB" ] && sync_actions+=(packages)
print_no_internet_info || return 3
[ -n "${sync_actions[*]}" ] && ! gum_spin --title 'Synchronize Database...' -- bash -c "${SELF} --sync ${sync_actions[*]}" && gum_fail "Synchronize Database (updates, packages) failed" && return 3
# Package info
gum_key_value_white "Arch Packages" "$(pacman -Qn | wc -l)"
[ "$AUR_SUPPORT" = "true" ] && gum_key_value_white "AUR Packages" "$(/usr/bin/paru -Qm &>/dev/null && /usr/bin/paru -Qm | wc -l || echo Error)"
# flatpak list --columns=application | tail -n +1 | wc -l
[ "$FLATPAK_SUPPORT" = "true" ] && gum_key_value_white "Flatpak Packages" "$(flatpak list --app | wc -l)"
# Gnome extensions count
command -v /usr/bin/gnome-extensions &>/dev/null && gum_key_value_white "GNOME Extensions" "$(gnome-extensions list --enabled | wc -l)"
# Services count
gum_key_value_white "Running Services" "$(systemctl list-units --type=service --state=running --plain --no-legend | wc -l)"
# Service Failure
service_count=$(print_service_failed | wc -l)
if [ "$service_count" -gt "0" ]; then
gum_key_value_red "Service Failure" "${service_count}"
else
gum_key_value_green "Service Failure" "${service_count}"
fi
# System Log
log_count=$(print_system_error_logs | wc -l)
if [ "$log_count" -gt "0" ]; then
gum_key_value_yellow "System Log" "${log_count}"
else
gum_key_value_green "System Log" "${log_count}"
fi
# Check pending updates
local pending_updates=0
[ -s "$UPDATES_DB" ] && pending_updates=$(wc -l <"$UPDATES_DB")
if [ "$pending_updates" -gt "0" ]; then
gum_key_value_yellow "Pending Updates" "${pending_updates}"
else
gum_key_value_green "Pending Updates" "${pending_updates}"
fi
# Check pacdiff
local pacdiff_info pacdiff_count
pacdiff_info="$(pacdiff -o)"
[ -n "$pacdiff_info" ] && pacdiff_count="$(echo "$pacdiff_info" | wc -l)"
[ -z "$pacdiff_info" ] && pacdiff_count="0"
if [ "$pacdiff_count" -gt "0" ]; then
gum_key_value_yellow "Pending Merges" "${pacdiff_count}"
else
gum_key_value_green "Pending Merges" "${pacdiff_count}"
fi
# Check orphans
local orphans_packages orphans_count
local pkg_manager="/usr/bin/pacman" && [ "$AUR_SUPPORT" = "true" ] && pkg_manager="/usr/bin/paru"
orphans_packages="$($pkg_manager -Qtdq &>/dev/null && $pkg_manager -Qtdq)"
orphans_count="$(echo "$orphans_packages" | wc -w)"
if [ "$orphans_count" -gt "0" ]; then
gum_key_value_yellow "Orphaned Packages" "${orphans_count}"
else
gum_key_value_green "Orphaned Packages" "${orphans_count}"
fi
# Unknown pkgs
local unknown_pkgs=()
while read -r pkg; do if ! grep -q "$pkg" "$PACKAGES_DB"; then unknown_pkgs+=("$pkg"); fi; done < <(pacman -Qqm)
if [ -n "${unknown_pkgs[*]}" ]; then
if [ "$SHOW_UNKNOWN_PKG_LIST" = "true" ]; then
unknown_pkgs=$(printf "%s, " "${unknown_pkgs[@]}")
unknown_pkgs=${unknown_pkgs%, }
local IFS=', ' && gum_key_value_yellow "Unknown Packages" "${unknown_pkgs}"
else
local IFS=', ' && gum_key_value_yellow "Unknown Packages" "${#unknown_pkgs[*]}"
fi
else
gum_key_value_green "Unknown Packages" "${#unknown_pkgs[*]}"
fi
}
# ///////////////////////////////////////////////////////////////////
# SEARCH
# ///////////////////////////////////////////////////////////////////
# shellcheck disable=SC2086
show_search() { # Search & manage packages
local search_filter pkg_name pkg_info_remote pkg_info_local pkg_is_aur pkg_is_installed
while (true); do
print_header && gum_title "Package Search"
# Sync db
print_no_internet_info || return 3
[ ! -f "$PACKAGES_DB" ] && ! gum_spin --title 'Synchronize Package Database...' -- bash -c "${SELF} --sync packages" && gum_fail "Synchronize Database (packages) failed" && return 3
# -------------------------------------------------------------------
# Select package if not exists
if [ -z "$pkg_name" ]; then
# Helper
list_results() {
local pkg_manager pkg_manager_result
pkg_manager="/usr/bin/pacman" && [ "$AUR_SUPPORT" = "true" ] && pkg_manager="/usr/bin/paru"
! pkg_manager_result="$(LANG=en_US.UTF-8 $pkg_manager -Ss $1)" && return 1
local pkg_name pkg_desc
echo "$pkg_manager_result" | while IFS= read -r line; do
if [ -z "$pkg_name" ]; then
pkg_name="$(echo -e "$line" | cut -d ' ' -f 1)"
else
pkg_desc=$(echo "${line}" | awk '{$1=$1; print}')
echo -e "${pkg_name}: ${pkg_desc}" | awk '{print (length($0) > 110 ? substr($0, 1, 110) "..." : $0)}' # Cut after 110 chars and print
unset pkg_name
fi
done
}
# Search filter
! search_filter=$(gum_input --placeholder="Search Package...") && gum_warn "Canceled" && return 2
[ -z "$search_filter" ] && gum_fail "Search was empty" && return 3
gum_key_value_white "$(print_filled_space "Search Filter")" "$search_filter"
# Filter results
local filter_pkgs_results && ! filter_pkgs_results="$(list_results "$search_filter" | tac)"
[ -z "$filter_pkgs_results" ] && gum_warn "No Results" && return 3
echo && gum_title "Package Information"
mapfile -t search_result_array < <(echo "$filter_pkgs_results")
! pkg_name=$(gum_filter --limit 1 --height "20" --placeholder "Filter..." "${search_result_array[@]}") && gum_warn "Canceled" && return 2
# Set package name
pkg_name="$(echo "$pkg_name" | cut -d':' -f1 | cut -d'/' -f2)"
else
gum_key_value_white "$(print_filled_space "Search Filter")" "$search_filter"
echo && gum_title "Package Information"
fi
# -------------------------------------------------------------------
# Helper function
print_package_value() {
local result && result="$(echo "$1" | grep -i "^${2}" | sed -E "s/^${2}\s*:\s*//" || echo "unavailable")"
echo "$result" | awk '{print (length($0) > 110 ? substr($0, 1, 110) "..." : $0)}' # Cut after 110 chars and print
}
# Fetch general package infos
local pkg_manager="/usr/bin/pacman" && [ "$AUR_SUPPORT" = "true" ] && pkg_manager="/usr/bin/paru"
pkg_info_remote="$(LANG=en_US.UTF-8 $pkg_manager -Si $pkg_name)" # Uninstalled
pkg_is_aur="false" && [ "$(print_package_value "$pkg_info_remote" "Repository")" = "aur" ] && pkg_is_aur="true"
pkg_is_installed="false" && /usr/bin/pacman -Q $pkg_name &>/dev/null && pkg_is_installed="true"
# Get installed package info
if [ "$pkg_is_installed" = "true" ]; then
pkg_info_local="$(LANG=en_US.UTF-8 $pkg_manager -Qi $pkg_name)" # Installed
fi
# Print general package info
local pkg_text && pkg_text="${pkg_name}:$(print_package_value "$pkg_info_remote" "Version")"
gum_key_value_white "$(print_filled_space "Package")" "$pkg_text"
gum_key_value_white "$(print_filled_space "Description")" "$(print_package_value "$pkg_info_remote" "Description")"
# Repo
local pkg_repo && pkg_repo="$(print_package_value "$pkg_info_remote" "Repository")"
if [ "$pkg_repo" = "core" ] || [ "$pkg_repo" = "extra" ]; then
gum_key_value_white "$(print_filled_space "Repository")" "$pkg_repo"
else
gum_key_value_yellow "$(print_filled_space "Repository")" "$pkg_repo"
fi
gum_key_value_white "$(print_filled_space "Dependencies")" "$(print_package_value "$pkg_info_remote" "Depends On" | wc -w)"
# Repo Info
if [ "$pkg_is_aur" = "true" ]; then # AUR package info
gum_key_value_white "$(print_filled_space "AUR URL")" "$(print_package_value "$pkg_info_remote" "AUR URL")"
gum_key_value_white "$(print_filled_space "AUR Maintainer")" "$(print_package_value "$pkg_info_remote" "Maintainer")"
gum_key_value_white "$(print_filled_space "AUR Votes")" "$(print_package_value "$pkg_info_remote" "Votes")"
gum_key_value_white "$(print_filled_space "AUR Popularity")" "$(print_package_value "$pkg_info_remote" "Popularity")"
gum_key_value_white "$(print_filled_space "AUR Modified")" "$(print_package_value "$pkg_info_remote" "Last Modified" | date -f - "+%Y-%m-%d %H:%M")"
# Check outdated packages
local outdated && outdated="$(print_package_value "$pkg_info_remote" "Out Of Date")"
[ "$outdated" = "No" ] && gum_key_value_white "$(print_filled_space "AUR Outdated")" "no"
[ "$outdated" != "No" ] && gum_key_value_red "$(print_filled_space "AUR Outdated")" "$(echo "$outdated" | date -f - "+%Y-%m-%d %H:%M")"
else
# Non AUR package info
gum_key_value_white "$(print_filled_space "Package URL")" "$(print_package_value "$pkg_info_remote" "URL")"
gum_key_value_white "$(print_filled_space "Package Date")" "$(print_package_value "$pkg_info_remote" "Build Date" | date -f - "+%Y-%m-%d %H:%M")"
fi
# Installed/Not installed package info
if [ "$pkg_is_installed" = "true" ]; then # Installed package info
gum_key_value_white "$(print_filled_space "Install Date")" "$(print_package_value "$pkg_info_local" "Install Date" | date -f - "+%Y-%m-%d %H:%M")"
gum_key_value_white "$(print_filled_space "Install Version")" "$(print_package_value "$pkg_info_local" "Version")"
gum_key_value_white "$(print_filled_space "Install Reason")" "$(print_package_value "$pkg_info_local" "Install Reason")"
gum_key_value_green "$(print_filled_space "Installed")" "yes"
else # Not installed package info
gum_key_value_yellow "$(print_filled_space "Installed")" "no"
fi
# Show package options menu
echo && gum_title "Options"
# Dynamic package entries
local options=()
[ "$pkg_is_aur" = "true" ] && [ "$AUR_SUPPORT" = "true" ] && options+=("Show PKGBUILD")
[ "$pkg_is_installed" = "false" ] && options+=("Install")
[ "$pkg_is_installed" = "true" ] && options+=("Remove")
# Show downgrade entry if package is installed and not from AUR
command -v /usr/bin/downgrade &>/dev/null && [ "$pkg_is_installed" = "true" ] && [ "$pkg_is_aur" = "false" ] && options+=("Downgrade")
options+=("Done")
# Show menu
local user_input=''
! user_input=$(gum_choose --selected="Done" --height=6 "${options[@]}") && gum_warn "Canceled" && return 2
case "$user_input" in # Set user action to selected action
'Install')
! gum_confirm "Install?" && clear_screen && continue
local pkg_manager_args=()
[ "$ARCH_DOWNLOAD_TIMEOUT" = "false" ] && pkg_manager_args+=('--disable-download-timeout')
if [ "$pkg_is_aur" = "true" ]; then
[ "$AUR_REVIEW" = "false" ] && pkg_manager_args+=('--skipreview')
if /usr/bin/paru -Sq "${pkg_manager_args[@]}" $pkg_name; then gum_info "Install successful"; else gum_fail "Installing ${pkg_name} failed"; fi
else
if sudo /usr/bin/pacman -Sq "${pkg_manager_args[@]}" $pkg_name; then gum_info "Install successful"; else gum_fail "Installing ${pkg_name} failed"; fi
fi
;;
'Remove')
! gum_confirm "Remove?" && clear_screen && continue
if sudo /usr/bin/pacman -Rns $pkg_name; then gum_info "Remove successful"; else gum_fail "Removing ${pkg_name} failed"; fi
;;
'Show PKGBUILD')
clear_screen && print_header && gum_title "PKGBUILD"
/usr/bin/paru -Gp $pkg_name
;;
'Downgrade')
! gum_confirm "Downgrade?" && clear_screen && continue
if sudo downgrade $pkg_name; then gum_info "Downgrade successful"; else gum_fail "Downgrading ${pkg_name} failed"; fi
;;
'Done') gum_mesg "Done" && return 2 ;;
*) unset pkg_name && gum_fail "Action '${user_input}' not available" && return 3 ;;
esac
gum_confirm_continue
clear_screen
done
return 0
}
# ///////////////////////////////////////////////////////////////////
# SYSTEM INFO
# ///////////////////////////////////////////////////////////////////
show_system_info() { # System info
local options user_input system_logs
if [ "$SHOW_SYSTEM_LOG" = "true" ]; then
# Show system logs
gum_title "System Information"
system_logs=$(print_system_error_logs)
if [ -n "$system_logs" ]; then
local log_counter=0
echo -e "$system_logs" | while read -r line; do gum_log_fail "$line" && ((log_counter++)) && [ $log_counter -gt 25 ] && echo && gum_warn "You have more than 25 Logs. Output stopped." && break; done
else
gum_log_info "No System Log available"
fi
echo # Print new line
fi
# Show service health
[ "$SHOW_SERVICE_LIST" = "true" ] && gum_title "Service Information" && print_service_running | while read -r line; do gum_log_info "${line}"; done && echo
# Failed services
services_failed="$(print_service_failed)"
if [ -n "$services_failed" ]; then
gum_title "Failed Services" && echo -e "$services_failed" | while read -r line; do gum_log_fail "${line}"; done && echo
fi
# Show system health
show_health_info --sync-updates && echo
# Show menu
gum_title "Options"
options=("Edit Blacklist" "Done")
! user_input=$(gum_choose --height=5 --selected="Done" "${options[@]}") && gum_warn "Canceled" && return 2
case "$user_input" in
'Edit Blacklist')
clear_screen && print_header && gum_title "Edit Blacklist"
local line_count && line_count=$(wc -l <"${ARCH_OS_BLACKLIST}") # Count properties by line
# Open editor with count of properties + 2
# BUG: gum write does not accept height greater than 7
if gum_write --show-line-numbers --height="$((line_count + 2))" --placeholder="Add log message to hide in system log (line by line)..." --value="$(<"$ARCH_OS_BLACKLIST")" >"${ARCH_OS_BLACKLIST}.new"; then
# If success: save/move file, remove spaces and re-init properties
awk '{$1=$1; print}' "${ARCH_OS_BLACKLIST}.new" >"$ARCH_OS_BLACKLIST" && init_properties && persist_properties || return 1
rm -f "${ARCH_OS_BLACKLIST}.new"
gum_info "Saved: ${ARCH_OS_BLACKLIST}" && return 0
else
rm -f "${ARCH_OS_BLACKLIST}.new" # Remove tmp properties
gum_warn "Canceled" && return 3
fi
;;
'Done') gum_mesg "Done" && return 2 ;;
*) gum_fail "Option '${user_input}' not available" && return 3 ;;
esac
return 0
}
# ///////////////////////////////////////////////////////////////////
# UPGRADE
# ///////////////////////////////////////////////////////////////////
show_upgrade() { # Update packages
# Show infos
show_news_info || return $?
show_update_info || return $?
echo && show_health_info || return $?
if [ ! -s "$UPDATES_DB" ]; then
gum_confirm_continue
return 2
fi
# Start upgrade system
echo && ! gum_confirm "Start System Upgrade?" && return 2
clear_screen && print_header && gum_title "Upgrade System Packages"
# Prepare args
local pkg_manager_args=()
[ "$ARCH_DOWNLOAD_TIMEOUT" = "false" ] && pkg_manager_args+=('--disable-download-timeout')
[ "$ARCH_UPGRADE_CONFIRM" = "false" ] && pkg_manager_args+=('--noconfirm')
# Upgrade system packages
! sudo /usr/bin/pacman -Syuq "${pkg_manager_args[@]}" && gum_fail "System Upgrade failed" && return 3
# Upgrade AUR packages
if [ "$AUR_SUPPORT" = "true" ]; then
gum_mesg_strong "Upgrading AUR Packages..."
[ "$AUR_REVIEW" = "false" ] && pkg_manager_args+=('--skipreview')
! /usr/bin/paru -Suaq "${pkg_manager_args[@]}" && gum_fail "AUR Upgrade failed" && return 3
fi
# Upgrade flatpak packages
if [ "$FLATPAK_SUPPORT" = "true" ]; then
if [ -n "$(flatpak remote-ls --updates)" ]; then # Check if flatpak updates available
if [ "$FLATPAK_UPGRADE_CONFIRM" = "false" ]; then # Do auto flatpak update
! gum_spin --title 'Upgrading Flatpak Apps...' -- bash -c "flatpak update -y --noninteractive" && gum_fail "Flatpak Upgrade failed" && return 3
else # Do Interactive flatpak update
gum_mesg_strong "Upgrading Flatpak Apps" && ! flatpak update && gum_fail "Flatpak Upgrade failed" && return 3
fi
gum_mesg_strong "Flatpak Upgrade finished"
else # Up to date
gum_mesg_strong "Flatpak is up to date"
fi
fi
# Resync packages & updates db
print_no_internet_info || return 3
! gum_spin --title 'Synchronize Update Database...' -- bash -c "${SELF} --sync packages updates" && gum_fail "Synchronize Database failed" && return 3
# Finish
LATEST_SYSTEM_UPGRADE="$(print_timestamp)" && persist_state
gum_info "System Upgrade finished"
echo # Print new line
show_health_info || return $?
return 0
}
# ///////////////////////////////////////////////////////////////////
# ORPHANS
# ///////////////////////////////////////////////////////////////////
show_orphans() { # Remove orphaned packages
gum_title "Remove Package Orphans"
! gum_confirm "Continue?" && return 2
local pkg_manager_args=() && [ "$ORPHANS_CONFIRM" = "false" ] && pkg_manager_args+=('--noconfirm')
# Remove pacman orphans
# Alternative: ! sudo /usr/bin/pacman -Rsu --noconfirm $(/usr/bin/pacman -Qqd) 2>/dev/null && gum_fail "Failed" && return 3
# shellcheck disable=SC2046
if /usr/bin/pacman -Qtdq &>/dev/null; then
! sudo /usr/bin/pacman -Rns "${pkg_manager_args[@]}" $(/usr/bin/pacman -Qtdq) && gum_fail "Remove System Orphans failed" && return 3
else
gum_mesg_strong "No orphaned system packages found"
fi
# Remove unused flatpaks
if [ "$FLATPAK_SUPPORT" = "true" ]; then
if [ "$ORPHANS_CONFIRM" = "false" ]; then # Do auto flatpak orphans
! gum_spin --title 'Removing Flatpak Orphans...' -- bash -c "flatpak uninstall -y --noninteractive --unused" && gum_fail "Remove Flatpak Orphans failed" && return 3
gum_mesg_strong "Remove Flatpak Orphans finished"
else # Do Interactive flatpak orphans
gum_mesg_strong "Remove Flatpak Orphans" && ! flatpak uninstall --unused && gum_fail "Remove Flatpak Orphans failed" && return 3
fi
fi
gum_info "Done"
return 0
}
# ///////////////////////////////////////////////////////////////////
# MERGE
# ///////////////////////////////////////////////////////////////////
show_merge() { # Merge updated config files
if ! command -v /usr/bin/pacdiff &>/dev/null || ! command -v meld &>/dev/null; then
gum_title "Install Pacdiff Tools"
! gum_confirm "Continue?" && return 2
local pkg_manager_args=()
[ "$ARCH_DOWNLOAD_TIMEOUT" = "false" ] && pkg_manager_args+=('--disable-download-timeout')
! sudo /usr/bin/pacman -Sq --needed "${pkg_manager_args[@]}" meld && gum_warn "Canceled" && return 3
# Hide meld app
if gum_confirm "Hide App Icon in GNOME Menu?"; then
echo -e '[Desktop Entry]\nType=Application\nHidden=true' >"${HOME}/.local/share/applications/org.gnome.Meld.desktop"
else
rm -f "${HOME}/.local/share/applications/org.gnome.Meld.desktop"
fi
clear_screen && print_header # Clean install output & print new header
fi
gum_title "Merge Pacdiff Configurations"
! gum_confirm "Continue?" && return 2
# List & show pacdiff config files
local pacdiff_files=() && while IFS= read -r line; do pacdiff_files+=("$line"); done < <(pacdiff -o)
[ ${#pacdiff_files[@]} -eq 0 ] && gum_info "Nothing to do" && return 0
for file in "${pacdiff_files[@]}"; do gum_warn "$file"; done
# Merge files
echo && ! sudo DIFFPROG=meld pacdiff && echo -e '\n' && gum_warn "Canceled" && return 3
gum_info "Done"
return 0
}
# ///////////////////////////////////////////////////////////////////
# REFRESH
# ///////////////////////////////////////////////////////////////////
show_refresh() { # Refresh mirrorlist with reflector
if ! command -v /usr/bin/reflector &>/dev/null; then
gum_title "Install Reflector" # Install missing pkgs
! gum_confirm "Continue?" && return 2
local pkg_manager_args=()
[ "$ARCH_DOWNLOAD_TIMEOUT" = "false" ] && pkg_manager_args+=('--disable-download-timeout')
! sudo /usr/bin/pacman -Sq --needed "${pkg_manager_args[@]}" reflector && gum_warn "Canceled" && return 3
clear_screen && print_header # Clean install output & print new header
fi
gum_title "Refresh Pacman Mirrorlist"
! gum_confirm "Continue?" && return 2
# Refresh mirrorlist with reflector and return if user press ctrl + c
! gum_spin --title 'Waiting for Reflector...' -- bash -c "reflector --latest 5 --protocol https --sort rate --save $MIRRORLIST_TMP &> /dev/null; wait; exit 0" && gum_fail "Failed" && return 3
# Clean reflector result (list only servers)
local mirrorlist_cleaned && mirrorlist_cleaned=$(grep -v '^#' "$MIRRORLIST_TMP" | sed '/^$/d;s/^[[:space:]#]*//')
echo -e "$mirrorlist_cleaned" >"$MIRRORLIST_TMP"
! [ -s "$MIRRORLIST_TMP" ] && gum_fail "New mirrorlist is empty" && return 3
# Print cleaned mirrorlist
while IFS= read -r line || [ -n "$line" ]; do gum_log_info "$line"; done < <(cat "$MIRRORLIST_TMP")
# Edit mirrorlist?
echo && gum_confirm "Edit Mirrorlist?" && clear_screen && print_header && gum_title "New Mirrorlist" && if gum_write --show-line-numbers --height="6" --value="$(cat "$MIRRORLIST_TMP")" >"${MIRRORLIST_TMP}.new"; then
# Refresh & re-print new mirrorlist
mv -f "${MIRRORLIST_TMP}.new" "$MIRRORLIST_TMP"
while IFS= read -r line || [[ -n "$line" ]]; do gum_log_info "$line"; done < <(cat "$MIRRORLIST_TMP") && echo
else
rm -f "${ARCH_OS_BLACKLIST}.new"
while IFS= read -r line || [[ -n "$line" ]]; do gum_log_info "$line"; done < <(cat "$MIRRORLIST_TMP") && echo
gum_warn "Edit canceled"
fi
# Save mirrorlist?
! gum_confirm "Save Mirrorlist?" && gum_warn "New mirrorlist was ignored" && return 2
# Check new mirrorlist
! [ -s "$MIRRORLIST_TMP" ] && gum_fail "New mirrorlist is empty" && return 3
# Save mirrorlist and set correct permissions