-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsysupdate-legacy.sh
More file actions
executable file
·562 lines (474 loc) · 21.2 KB
/
sysupdate-legacy.sh
File metadata and controls
executable file
·562 lines (474 loc) · 21.2 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
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
#!/bin/bash
# System Update Manager
# --- Configuration ---
LOG_DIR="/tmp/update_logs"
LOG_BASE_NAME="system_update_$(date +%Y%m%d_%H%M%S)"
APT_LOG="${LOG_DIR}/${LOG_BASE_NAME}_apt.log"
FLATPAK_LOG="${LOG_DIR}/${LOG_BASE_NAME}_flatpak.log"
# Check for verbose mode
VERBOSE=false
if [[ "$1" == "-v" ]] || [[ "$1" == "--verbose" ]]; then
VERBOSE=true
fi
mkdir -p "$LOG_DIR"
# --- Color Definitions ---
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
WHITE='\033[1;37m'
BOLD='\033[1m'
DIM='\033[2m'
NC='\033[0m' # No Color
# --- Enhanced Spinner Frames ---
SPIN_FRAMES=("⠋" "⠙" "⠹" "⠸" "⠼" "⠴" "⠦" "⠧" "⠇" "⠏")
# --- Utility Functions ---
# Function to show status with enhanced spinner
show_status() {
local task_name="$1"
local status_file="$2"
local max_len="$3"
local delay=0.1
local spin_index=0
# Use default max_len if not provided
if [ -z "$max_len" ]; then
max_len=${#task_name}
fi
while [ ! -f "$status_file" ]; do
printf "\r${CYAN}%s${NC} %-*s" "${SPIN_FRAMES[$spin_index]}" "$max_len" "$task_name"
spin_index=$(( (spin_index + 1) % ${#SPIN_FRAMES[@]} ))
sleep "$delay"
done
# Task finished, show final status
local exit_code
exit_code=$(cat "$status_file" 2>/dev/null)
# Handle empty or invalid exit code
if [[ -z "$exit_code" || ! "$exit_code" =~ ^[0-9]+$ ]]; then
exit_code="1"
fi
if [ "$exit_code" -eq 0 ]; then
printf "\r${GREEN}✅${NC} %-*s ${GREEN}SUCCESS${NC}\n" "$max_len" "$task_name"
else
printf "\r${RED}❌${NC} %-*s ${RED}FAILED (Exit Code: %s)${NC}\n" "$max_len" "$task_name" "$exit_code"
fi
}
# Function to manage both status displays concurrently with colors
manage_status_displays() {
local apt_task="$1"
local apt_status_file="$2"
local apt_count_file="$3"
local apt_error_file="$4"
local flatpak_task="$5"
local flatpak_status_file="$6"
local flatpak_count_file="$7"
local flatpak_error_file="$8"
local delay=0.1
local apt_finished=false
local flatpak_finished=false
local spin_index=0
# Calculate the maximum task name length for alignment
local apt_len=${#apt_task}
local flatpak_len=${#flatpak_task}
local max_len=$apt_len
if [ "$flatpak_len" -gt "$max_len" ]; then
max_len=$flatpak_len
fi
# Hide cursor during animation to prevent occlusion
printf "\033[?25l"
# Start display - write two lines that we'll keep updating
printf "${CYAN}%s${NC} ${BOLD}%-*s${NC}\n" "${SPIN_FRAMES[0]}" "$max_len" "$apt_task"
printf "${CYAN}%s${NC} ${BOLD}%-*s${NC}" "${SPIN_FRAMES[0]}" "$max_len" "$flatpak_task"
while [ "$apt_finished" = false ] || [ "$flatpak_finished" = false ]; do
# Move back to start of second line (where we are now)
printf "\r"
# Check and update Flatpak line first (since we're on it)
if [ "$flatpak_finished" = false ]; then
if [ -f "$flatpak_status_file" ]; then
local flatpak_exit_code
flatpak_exit_code=$(cat "$flatpak_status_file" 2>/dev/null)
if [[ -z "$flatpak_exit_code" || ! "$flatpak_exit_code" =~ ^[0-9]+$ ]]; then
flatpak_exit_code="1"
fi
printf "\033[K" # Clear current line
if [ "$flatpak_exit_code" -eq 0 ]; then
local flatpak_count
flatpak_count=$(cat "$flatpak_count_file" 2>/dev/null || echo "0")
if [ "$flatpak_count" -eq 0 ]; then
printf "${GREEN}✓${NC} ${BOLD}%-*s${NC} ${DIM}Already up to date${NC}" "$max_len" "$flatpak_task"
else
printf "${GREEN}✓${NC} ${BOLD}%-*s${NC} ${GREEN}%s updated${NC}" "$max_len" "$flatpak_task" "$flatpak_count"
fi
else
local flatpak_error
flatpak_error=$(cat "$flatpak_error_file" 2>/dev/null | head -1)
if [ -z "$flatpak_error" ]; then
printf "${RED}✗${NC} ${BOLD}%-*s${NC} ${RED}Failed${NC}" "$max_len" "$flatpak_task"
else
printf "${RED}✗${NC} ${BOLD}%-*s${NC} ${RED}%s${NC}" "$max_len" "$flatpak_task" "$flatpak_error"
fi
fi
flatpak_finished=true
else
printf "\033[K${CYAN}%s${NC} ${BOLD}%-*s${NC}" "${SPIN_FRAMES[$spin_index]}" "$max_len" "$flatpak_task"
fi
else
# Flatpak already finished, just redraw it
local flatpak_exit
flatpak_exit=$(cat "$flatpak_status_file" 2>/dev/null || echo "1")
printf "\033[K"
if [ "$flatpak_exit" -eq 0 ]; then
local flatpak_count
flatpak_count=$(cat "$flatpak_count_file" 2>/dev/null || echo "0")
if [ "$flatpak_count" -eq 0 ]; then
printf "${GREEN}✓${NC} ${BOLD}%-*s${NC} ${DIM}Already up to date${NC}" "$max_len" "$flatpak_task"
else
printf "${GREEN}✓${NC} ${BOLD}%-*s${NC} ${GREEN}%s updated${NC}" "$max_len" "$flatpak_task" "$flatpak_count"
fi
else
printf "${RED}✗${NC} ${BOLD}%-*s${NC} ${RED}Failed${NC}" "$max_len" "$flatpak_task"
fi
fi
# Now move up to APT line and update it
printf "\033[1A\r"
if [ "$apt_finished" = false ]; then
if [ -f "$apt_status_file" ]; then
local apt_exit_code
apt_exit_code=$(cat "$apt_status_file" 2>/dev/null)
if [[ -z "$apt_exit_code" || ! "$apt_exit_code" =~ ^[0-9]+$ ]]; then
apt_exit_code="1"
fi
printf "\033[K" # Clear current line
if [ "$apt_exit_code" -eq 0 ]; then
local apt_count
apt_count=$(cat "$apt_count_file" 2>/dev/null || echo "0")
if [ "$apt_count" -eq 0 ]; then
printf "${GREEN}✓${NC} ${BOLD}%-*s${NC} ${DIM}Already up to date${NC}" "$max_len" "$apt_task"
else
printf "${GREEN}✓${NC} ${BOLD}%-*s${NC} ${GREEN}%s updated${NC}" "$max_len" "$apt_task" "$apt_count"
fi
else
local apt_error
apt_error=$(cat "$apt_error_file" 2>/dev/null | head -1)
if [ -z "$apt_error" ]; then
printf "${RED}✗${NC} ${BOLD}%-*s${NC} ${RED}Failed${NC}" "$max_len" "$apt_task"
else
printf "${RED}✗${NC} ${BOLD}%-*s${NC} ${RED}%s${NC}" "$max_len" "$apt_task" "$apt_error"
fi
fi
apt_finished=true
else
printf "\033[K${CYAN}%s${NC} ${BOLD}%-*s${NC}" "${SPIN_FRAMES[$spin_index]}" "$max_len" "$apt_task"
fi
else
# APT already finished, just redraw it
local apt_exit
apt_exit=$(cat "$apt_status_file" 2>/dev/null || echo "1")
printf "\033[K"
if [ "$apt_exit" -eq 0 ]; then
local apt_count
apt_count=$(cat "$apt_count_file" 2>/dev/null || echo "0")
if [ "$apt_count" -eq 0 ]; then
printf "${GREEN}✓${NC} ${BOLD}%-*s${NC} ${DIM}Already up to date${NC}" "$max_len" "$apt_task"
else
printf "${GREEN}✓${NC} ${BOLD}%-*s${NC} ${GREEN}%s updated${NC}" "$max_len" "$apt_task" "$apt_count"
fi
else
printf "${RED}✗${NC} ${BOLD}%-*s${NC} ${RED}Failed${NC}" "$max_len" "$apt_task"
fi
fi
# Move back down to second line for next iteration
printf "\n"
sleep "$delay"
spin_index=$(( (spin_index + 1) % ${#SPIN_FRAMES[@]} ))
# Break early if both finished
[ "$apt_finished" = true ] && [ "$flatpak_finished" = true ] && break
done
# Move cursor below both lines and restore cursor visibility
printf "\n"
printf "\033[?25h"
}
# --- Table Display Functions ---
# Display APT packages table with version transitions
# Reads from file with format: PACKAGE|OLD_VERSION|NEW_VERSION
display_apt_table() {
local data_file="$1"
if [[ ! -s "$data_file" ]]; then
return 0
fi
# Calculate column widths dynamically
local max_name=12 max_old=11 max_new=11
while IFS='|' read -r name old_ver new_ver; do
[[ ${#name} -gt $max_name ]] && max_name=${#name}
[[ ${#old_ver} -gt $max_old ]] && max_old=${#old_ver}
[[ ${#new_ver} -gt $max_new ]] && max_new=${#new_ver}
done < "$data_file"
# Add padding and cap widths
max_name=$((max_name + 2)); [[ $max_name -gt 40 ]] && max_name=40
max_old=$((max_old + 2)); [[ $max_old -gt 25 ]] && max_old=25
max_new=$((max_new + 2)); [[ $max_new -gt 25 ]] && max_new=25
local total_width=$((max_name + max_old + max_new + 4))
echo
echo -e " ${BOLD}${WHITE}APT Packages Updated:${NC}"
echo
printf " ${DIM}%-${max_name}s %-${max_old}s %-${max_new}s${NC}\n" "Package" "Old Version" "New Version"
printf " ${DIM}"; printf '─%.0s' $(seq 1 $total_width); printf "${NC}\n"
while IFS='|' read -r name old_ver new_ver; do
# Truncate if needed
[[ ${#name} -gt $((max_name - 2)) ]] && name="${name:0:$((max_name - 5))}..."
[[ ${#old_ver} -gt $((max_old - 2)) ]] && old_ver="${old_ver:0:$((max_old - 5))}..."
[[ ${#new_ver} -gt $((max_new - 2)) ]] && new_ver="${new_ver:0:$((max_new - 5))}..."
printf " ${WHITE}%-${max_name}s${NC} ${DIM}%-${max_old}s${NC} ${GREEN}%-${max_new}s${NC}\n" \
"$name" "$old_ver" "$new_ver"
done < "$data_file"
}
# Display Flatpak apps table
# Reads from file with format: APP_NAME|BRANCH|SIZE
display_flatpak_table() {
local data_file="$1"
if [[ ! -s "$data_file" ]]; then
return 0
fi
# Calculate column widths dynamically
local max_name=15 max_branch=8 max_size=10
while IFS='|' read -r name branch size; do
[[ ${#name} -gt $max_name ]] && max_name=${#name}
[[ ${#branch} -gt $max_branch ]] && max_branch=${#branch}
[[ ${#size} -gt $max_size ]] && max_size=${#size}
done < "$data_file"
# Add padding and cap widths
max_name=$((max_name + 2)); [[ $max_name -gt 45 ]] && max_name=45
max_branch=$((max_branch + 2))
max_size=$((max_size + 2))
local total_width=$((max_name + max_branch + max_size + 4))
echo
echo -e " ${BOLD}${WHITE}Flatpak Applications Updated:${NC}"
echo
printf " ${DIM}%-${max_name}s %-${max_branch}s %-${max_size}s${NC}\n" "Application" "Branch" "Size"
printf " ${DIM}"; printf '─%.0s' $(seq 1 $total_width); printf "${NC}\n"
while IFS='|' read -r name branch size; do
[[ ${#name} -gt $((max_name - 2)) ]] && name="${name:0:$((max_name - 5))}..."
printf " ${WHITE}%-${max_name}s${NC} ${DIM}%-${max_branch}s${NC} ${CYAN}%-${max_size}s${NC}\n" \
"$name" "$branch" "$size"
done < "$data_file"
}
# --- Task Functions (truly silent) ---
# Function to handle apt updates and upgrades (runs in background)
run_apt_updates_background() {
local status_file="$1"
local package_count_file="$2"
local error_file="$3"
local packages_list_file="$4"
local exit_code=0
local package_count=0
local upgraded_count=0
local newly_installed_count=0
local apt_output
# Use tee to save output in real-time while capturing it
{
# Run apt update first
if ! sudo apt update 2>&1 | tee "$APT_LOG"; then
echo "FAILED_UPDATE" >> "$APT_LOG"
exit_code=1
else
# Run the actual upgrade (append to same log)
sudo apt full-upgrade -y 2>&1 | tee -a "$APT_LOG"
exit_code=${PIPESTATUS[0]}
fi
} > /tmp/apt_output_$$.tmp 2>&1
# Read the captured output for parsing
apt_output=$(cat /tmp/apt_output_$$.tmp)
rm -f /tmp/apt_output_$$.tmp
if [ "$exit_code" -eq 0 ] || echo "$apt_output" | grep -q "^0 upgraded"; then
# Parse multiple apt output formats
# Format 1: "X upgraded, Y newly installed, Z to remove and A not upgraded"
local apt_summary_line
apt_summary_line=$(echo "$apt_output" | grep -E "^[0-9]+ (upgraded|newly installed|to remove)" | tail -1)
if [ -n "$apt_summary_line" ]; then
# Extract upgraded count
upgraded_count=$(echo "$apt_summary_line" | sed -n 's/^\([0-9]\+\) upgraded.*/\1/p')
[ -z "$upgraded_count" ] && upgraded_count=0
# Extract newly installed count
newly_installed_count=$(echo "$apt_summary_line" | sed -n 's/.*\([0-9]\+\) newly installed.*/\1/p')
[ -z "$newly_installed_count" ] && newly_installed_count=0
package_count=$((upgraded_count + newly_installed_count))
else
# Check for other indicators
if echo "$apt_output" | grep -q "All packages are up to date"; then
package_count=0
else
# Count actual installations
package_count=$(echo "$apt_output" | grep -c "^Setting up " || echo "0")
fi
fi
echo "$package_count" >"$package_count_file"
# Extract package details (name|old_version|new_version) from Unpacking lines
# Format: "Unpacking package-name (new-version) over (old-version) ..."
if [ -n "$packages_list_file" ]; then
echo "$apt_output" | \
grep -E "^Unpacking [^ ]+ \([^)]+\) over \([^)]+\)" | \
sed -E 's/^Unpacking ([^ ]+) \(([^)]+)\) over \(([^)]+)\).*/\1|\3|\2/' | \
sort -u > "$packages_list_file"
fi
echo "0" >"$status_file"
else
# Extract error message
echo "$apt_output" | grep -E "(E:|ERROR:|Failed)" | head -1 >"$error_file"
if [ ! -s "$error_file" ]; then
echo "Package upgrade failed" >"$error_file"
fi
echo "1" >"$status_file"
fi
}
# Function to handle flatpak updates (runs in background)
run_flatpak_updates_background() {
local status_file="$1"
local package_count_file="$2"
local error_file="$3"
local packages_list_file="$4"
local exit_code=0
local package_count=0
local flatpak_output
# Use tee to save output in real-time while capturing it
flatpak_output=$(flatpak update -y 2>&1 | tee "$FLATPAK_LOG")
exit_code=${PIPESTATUS[0]}
# Re-read the log for parsing (in case tee didn't capture everything)
if [ -f "$FLATPAK_LOG" ]; then
flatpak_output=$(cat "$FLATPAK_LOG")
fi
if [ "$exit_code" -eq 0 ]; then
# ROBUST PARSING: Handle multiple flatpak output formats
# Primary method: Count from numbered list
local numbered_apps
numbered_apps=$(echo "$flatpak_output" | grep -E "^[[:space:]]*[0-9]+\." |
grep -v "\.Locale\|\.Extension\|\.Platform\|\.GL\.\|\.Sdk" |
awk '{print $2}' | sort -u | wc -l || echo "0")
# Secondary method: Count from action lines
local action_apps
action_apps=$(echo "$flatpak_output" | grep -E "^(Updating|Installing) " |
grep -v "\.Locale\|\.Extension\|\.Platform\|\.GL\.\|\.Sdk" |
awk -F'/' '{print $1}' | awk '{print $2}' | sort -u | wc -l || echo "0")
# Use the most reliable count
if [ "$numbered_apps" -gt 0 ]; then
package_count=$numbered_apps
elif [ "$action_apps" -gt 0 ]; then
package_count=$action_apps
else
# Check if already up to date
if echo "$flatpak_output" | grep -q "Nothing to do"; then
package_count=0
fi
fi
echo "$package_count" >"$package_count_file"
# Extract app details (name|branch|size) from numbered list lines
# Format: " 1. com.discordapp.Discord stable u flathub < 113.3 MB"
if [ -n "$packages_list_file" ]; then
echo "$flatpak_output" | \
grep -E "^\s*[0-9]+\." | \
grep -v '\.Locale\|\.Extension\|\.Platform\|\.GL\.\|\.Sdk' | \
sed -E 's/^\s*[0-9]+\.\s+//' | \
awk -F'\t' '{
name=$1; branch=$2; size=$NF;
gsub(/^[[:space:]]+|[[:space:]]+$/, "", name);
gsub(/^[[:space:]]+|[[:space:]]+$/, "", branch);
gsub(/^<[[:space:]]*/, "", size);
gsub(/[[:space:]]+$/, "", size);
if (name != "") print name "|" branch "|" size
}' | sort -u > "$packages_list_file"
fi
echo "0" >"$status_file"
else
# Extract error message
echo "$flatpak_output" | grep -E "(error:|Error:|Failed)" | head -1 >"$error_file"
if [ ! -s "$error_file" ]; then
echo "Flatpak update failed" >"$error_file"
fi
echo "1" >"$status_file"
fi
}
# --- Script Execution ---
# --- Prettier Header with Colors ---
echo
echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e " ${BOLD}${WHITE}System Update Manager${NC} ${DIM}v2.0${NC}"
echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo
# Request sudo password upfront
echo -e "${YELLOW}▸ Authentication required for system updates${NC}"
if ! sudo -v; then
echo -e "${RED}✗ Failed to obtain sudo privileges. Exiting.${NC}"
exit 1
fi
echo -e "${GREEN}✓ Authentication successful${NC}"
echo
# Create temporary status files
APT_STATUS_FILE=$(mktemp)
FLATPAK_STATUS_FILE=$(mktemp)
APT_COUNT_FILE=$(mktemp)
FLATPAK_COUNT_FILE=$(mktemp)
APT_ERROR_FILE=$(mktemp)
FLATPAK_ERROR_FILE=$(mktemp)
APT_PACKAGES_FILE=$(mktemp)
FLATPAK_PACKAGES_FILE=$(mktemp)
# Ensure status files are empty before starting
rm -f "$APT_STATUS_FILE" "$FLATPAK_STATUS_FILE" "$APT_COUNT_FILE" "$FLATPAK_COUNT_FILE" "$APT_ERROR_FILE" "$FLATPAK_ERROR_FILE" "$APT_PACKAGES_FILE" "$FLATPAK_PACKAGES_FILE"
# Start both background tasks
run_apt_updates_background "$APT_STATUS_FILE" "$APT_COUNT_FILE" "$APT_ERROR_FILE" "$APT_PACKAGES_FILE" &
APT_PID=$!
run_flatpak_updates_background "$FLATPAK_STATUS_FILE" "$FLATPAK_COUNT_FILE" "$FLATPAK_ERROR_FILE" "$FLATPAK_PACKAGES_FILE" &
FLATPAK_PID=$!
# Show starting message
echo -e "${BOLD}Updating your system...${NC}"
if [ "$VERBOSE" = true ]; then
echo -e "${DIM}Verbose mode enabled - logs are being written to:${NC}"
echo -e "${DIM} • $APT_LOG${NC}"
echo -e "${DIM} • $FLATPAK_LOG${NC}"
echo -e "${DIM}You can monitor them in real-time with: tail -f <logfile>${NC}"
fi
echo
# Show concurrent status displays
manage_status_displays "APT packages" "$APT_STATUS_FILE" "$APT_COUNT_FILE" "$APT_ERROR_FILE" "Flatpak applications" "$FLATPAK_STATUS_FILE" "$FLATPAK_COUNT_FILE" "$FLATPAK_ERROR_FILE"
# Wait for all background tasks to complete
wait $APT_PID
wait $FLATPAK_PID
# Read exit codes from status files
APT_EXIT_CODE=$(cat "$APT_STATUS_FILE" 2>/dev/null)
FLATPAK_EXIT_CODE=$(cat "$FLATPAK_STATUS_FILE" 2>/dev/null)
# Handle empty or invalid exit codes
if [[ -z "$APT_EXIT_CODE" || ! "$APT_EXIT_CODE" =~ ^[0-9]+$ ]]; then
APT_EXIT_CODE="1"
fi
if [[ -z "$FLATPAK_EXIT_CODE" || ! "$FLATPAK_EXIT_CODE" =~ ^[0-9]+$ ]]; then
FLATPAK_EXIT_CODE="1"
fi
# Get final counts for summary
APT_COUNT=$(cat "$APT_COUNT_FILE" 2>/dev/null || echo "0")
FLATPAK_COUNT=$(cat "$FLATPAK_COUNT_FILE" 2>/dev/null || echo "0")
echo
echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e " ${BOLD}${WHITE}Update Summary${NC}"
echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
if [ "$APT_EXIT_CODE" -eq 0 ] && [ "$FLATPAK_EXIT_CODE" -eq 0 ]; then
echo -e " ${GREEN}✓ All updates completed successfully${NC}"
else
echo -e " ${YELLOW}⚠ Some updates encountered issues${NC}"
fi
echo -e " ${DIM}APT packages updated: ${BOLD}$APT_COUNT${NC}"
echo -e " ${DIM}Flatpak apps updated: ${BOLD}$FLATPAK_COUNT${NC}"
# Display package tables if updates occurred
if [[ "$APT_COUNT" -gt 0 ]]; then
display_apt_table "$APT_PACKAGES_FILE"
fi
if [[ "$FLATPAK_COUNT" -gt 0 ]]; then
display_flatpak_table "$FLATPAK_PACKAGES_FILE"
fi
echo
echo -e " ${DIM}Logs saved to:${NC}"
echo -e " ${DIM}• $APT_LOG${NC}"
echo -e " ${DIM}• $FLATPAK_LOG${NC}"
echo
# Clean up temp files
rm -f "$APT_STATUS_FILE" "$FLATPAK_STATUS_FILE" "$APT_COUNT_FILE" "$FLATPAK_COUNT_FILE" "$APT_ERROR_FILE" "$FLATPAK_ERROR_FILE" "$APT_PACKAGES_FILE" "$FLATPAK_PACKAGES_FILE"
# Check if debug log exists and has content
if [ -f "${LOG_DIR}/${LOG_BASE_NAME}_flatpak_debug.log" ]; then
echo -e " ${DIM}• ${LOG_DIR}/${LOG_BASE_NAME}_flatpak_debug.log (debug info)${NC}"
fi