-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyBackUpTool.sh
More file actions
executable file
·584 lines (537 loc) · 23.4 KB
/
myBackUpTool.sh
File metadata and controls
executable file
·584 lines (537 loc) · 23.4 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
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
#!/bin/bash
# ==============================================================================
# myBackUpTool v1.0.8 - Futuristic Backup Utility
# ==============================================================================
# ------------------------------------------------------------------------------
# Configuration
# ------------------------------------------------------------------------------
CONFIG_FILE="${HOME}/.myBackUpTool.conf"
SETTINGS_FILE="${HOME}/.myBackUpTool.settings"
LOG_FILE="${HOME}/myBackUpTool.log"
TEMP_DIR="/tmp"
THEME_FILE="/tmp/myBackUpTool_theme.rc"
# Default defaults
DEFAULT_REMOTE="gdrive:myBackUpTool_Data"
DEFAULT_THEME="matrix"
DEFAULT_IGNORES="*/node_modules/* */.next/*"
VERSION="v1.5.0"
# Create config files
if [ ! -f "$CONFIG_FILE" ]; then touch "$CONFIG_FILE"; fi
save_setting() {
local key="$1"
local val="$2"
if [ -f "$SETTINGS_FILE" ]; then
grep -v "^${key}=" "$SETTINGS_FILE" > "${SETTINGS_FILE}.tmp"
mv "${SETTINGS_FILE}.tmp" "$SETTINGS_FILE"
fi
echo "${key}=${val}" >> "$SETTINGS_FILE"
}
read_setting() {
local key="$1"
local default="$2"
if [ -f "$SETTINGS_FILE" ]; then
local val=$(grep "^${key}=" "$SETTINGS_FILE" | cut -d'=' -f2-)
if [ -n "$val" ]; then echo "$val"; return; fi
fi
echo "$default"
}
CURRENT_REMOTE=$(read_setting "REMOTE" "$DEFAULT_REMOTE")
CURRENT_THEME=$(read_setting "THEME" "$DEFAULT_THEME")
# ------------------------------------------------------------------------------
# Graceful Exit
# ------------------------------------------------------------------------------
cleanup_and_exit() {
pkill -P $$ 2>/dev/null
rm -f "${TEMP_DIR}"/backup_*.zip
rm -f "${TEMP_DIR}"/job_*.log
local reset="\033[0m"
local color="\033[0;32m"
[ "$CURRENT_THEME" == "retro" ] && color="\033[0;33m"
[ "$CURRENT_THEME" == "dracula" ] && color="\033[0;35m"
[ "$CURRENT_THEME" == "oceanic" ] && color="\033[0;36m"
clear
echo -e "${color}"
echo "----------------------------------------"
echo " SYSTEM HALTED EXECUTION "
echo "----------------------------------------"
echo " Backup aborted by user."
echo -e "${reset}"
exit 130
}
trap cleanup_and_exit INT
# ------------------------------------------------------------------------------
# Theme Setup
# ------------------------------------------------------------------------------
setup_theme() {
local theme_name=$(read_setting "THEME" "matrix")
# Defaults
local screen="(GREEN,BLACK,ON)"
local dialog="(GREEN,BLACK,OFF)"
local title="(GREEN,BLACK,ON)"
local border="(GREEN,BLACK,ON)"
local button_act="(BLACK,GREEN,OFF)"
local button_inact="(GREEN,BLACK,OFF)"
case $theme_name in
retro) # Amber/Black
screen="(YELLOW,BLACK,ON)"
dialog="(YELLOW,BLACK,OFF)"
title="(YELLOW,BLACK,ON)"
border="(YELLOW,BLACK,ON)"
button_act="(BLACK,YELLOW,OFF)"
button_inact="(YELLOW,BLACK,OFF)"
;;
dracula) # Purple/DarkGray (Simulated with Mag/Black for safety)
screen="(MAGENTA,BLACK,ON)"
dialog="(WHITE,BLACK,OFF)"
title="(MAGENTA,BLACK,ON)"
border="(MAGENTA,BLACK,ON)"
button_act="(WHITE,MAGENTA,OFF)"
button_inact="(MAGENTA,BLACK,OFF)"
;;
oceanic) # Cyan/Blue
screen="(CYAN,BLUE,ON)"
dialog="(WHITE,BLUE,OFF)"
title="(CYAN,BLUE,ON)"
border="(CYAN,BLUE,ON)"
button_act="(BLUE,CYAN,OFF)"
button_inact="(CYAN,BLUE,OFF)"
;;
cyberpunk)
screen="(MAGENTA,BLACK,ON)"
dialog="(CYAN,BLACK,OFF)"
title="(MAGENTA,BLACK,ON)"
border="(CYAN,BLACK,ON)"
button_act="(BLACK,MAGENTA,OFF)"
button_inact="(CYAN,BLACK,OFF)"
;;
classic)
screen="(WHITE,BLUE,ON)"
dialog="(BLACK,WHITE,OFF)"
title="(BLUE,WHITE,ON)"
border="(BLUE,WHITE,ON)"
button_act="(WHITE,RED,OFF)"
button_inact="(BLACK,WHITE,OFF)"
;;
solarized) # Base03/Yellow/Blue
screen="(CYAN,BLACK,ON)"
dialog="(WHITE,BLACK,OFF)"
title="(YELLOW,BLACK,ON)"
border="(CYAN,BLACK,ON)"
button_act="(WHITE,MAGENTA,OFF)"
button_inact="(CYAN,BLACK,OFF)"
;;
monokai) # Dark/Pink/Green
screen="(WHITE,BLACK,OFF)" # Plain dark
dialog="(WHITE,BLACK,OFF)"
title="(MAGENTA,BLACK,ON)"
border="(GREEN,BLACK,ON)"
button_act="(BLACK,MAGENTA,OFF)"
button_inact="(GREEN,BLACK,OFF)"
;;
synthwave) # Deep Purple/Neon
screen="(MAGENTA,BLACK,ON)" # Can't do real purple bg in all terms, using Magenta Text on Black
dialog="(CYAN,BLACK,OFF)"
title="(YELLOW,BLACK,ON)"
border="(MAGENTA,BLACK,ON)"
button_act="(BLACK,CYAN,OFF)"
button_inact="(MAGENTA,BLACK,OFF)"
;;
*) ;;
esac
cat > "$THEME_FILE" <<EOF
aspect = 0
separate_widget = ""
tab_len = 0
visit_items = OFF
use_shadow = OFF
use_colors = ON
screen_color = $screen
shadow_color = (BLACK,BLACK,OFF)
dialog_color = $dialog
title_color = $title
border_color = $border
button_active_color = $button_act
button_inactive_color = $button_inact
button_key_active_color = $button_act
button_key_inactive_color = $button_inact
button_label_active_color = $button_act
button_label_inactive_color = $button_inact
inputbox_color = $dialog
inputbox_border_color = $border
searchbox_color = $dialog
searchbox_title_color = $title
searchbox_border_color = $border
menubox_color = $dialog
menubox_border_color = $border
item_color = $dialog
item_selected_color = $button_act
tag_color = $title
tag_selected_color = $button_act
tag_key_color = $title
tag_key_selected_color = $button_act
check_color = $dialog
check_selected_color = $button_act
uarrow_color = $title
darrow_color = $title
itemhelp_color = $dialog
form_active_text_color = $button_act
form_text_color = $dialog
form_item_readonly_color = $dialog
gauge_color = $title
border2_color = $border
inputbox_border2_color = $border
searchbox_border2_color = $border
menubox_border2_color = $border
EOF
export DIALOGRC="$THEME_FILE"
}
boot_animation() {
# Fake BIOS/boot sequence
local p=0
(
echo "10"; echo "XXX"; echo "Initializing Kernel..."; echo "XXX"; sleep 0.2
echo "20"; echo "XXX"; echo "Loading Modules..."; echo "XXX"; sleep 0.2
echo "40"; echo "XXX"; echo "Mounting Virtual Filesystems..."; echo "XXX"; sleep 0.2
echo "60"; echo "XXX"; echo "Checking Network Uplink..."; echo "XXX"; sleep 0.3
echo "80"; echo "XXX"; echo "Loading Configuration..."; echo "XXX"; sleep 0.2
echo "100"; echo "XXX"; echo "System Ready."; echo "XXX"; sleep 0.5
) | dialog --title "myBackUpTool OS v1.4" --gauge "Booting..." 8 50 0
}
shutdown_animation() {
(
echo "10"; echo "XXX"; echo "Saving Session State..."; echo "XXX"; sleep 0.2
echo "50"; echo "XXX"; echo "Disconnecting Remotes..."; echo "XXX"; sleep 0.2
echo "100"; echo "XXX"; echo "Powering Down."; echo "XXX"; sleep 0.5
) | dialog --title "Shutdown" --gauge "Exiting..." 8 50 0
clear
}
# ------------------------------------------------------------------------------
# Helper Functions
# ------------------------------------------------------------------------------
check_dependencies() {
for cmd in dialog zip rclone curl; do
if ! command -v $cmd &> /dev/null; then echo "Error: Missing $cmd"; exit 1; fi
done
}
log_message() {
local timestamp=$(date "+%Y-%m-%d %H:%M:%S")
echo "[$timestamp] $1" >> "$LOG_FILE"
}
send_telegram_notification() {
local msg="$1"
local file_name="$2"
local bot_token=$(read_setting "TG_BOT_TOKEN" "")
local chat_id=$(read_setting "TG_CHAT_ID" "")
if [ -n "$bot_token" ] && [ -n "$chat_id" ]; then
local text="✅ <b>Backup Successful</b>%0A📂 File: $file_name%0A☁️ Remote: $CURRENT_REMOTE%0A🕒 Time: $(date)"
if [ "$msg" != "" ]; then text="$msg"; fi
# Simple URL encoding (very basic)
text="${text// /%20}"
curl -s -X POST "https://api.telegram.org/bot${bot_token}/sendMessage" \
-d chat_id="${chat_id}" \
-d text="${text}" \
-d parse_mode="HTML" >> "$LOG_FILE" 2>&1
fi
}
# ------------------------------------------------------------------------------
# Settings
# ------------------------------------------------------------------------------
manage_ignores() {
while true; do
local cur=$(read_setting "IGNORES" "$DEFAULT_IGNORES")
local cmd=$(dialog --title "Expert Ignore Manager" --menu "Current: $cur\n\nOperation:" 18 70 6 \
"ADD_CUSTOM" "Add Manual Pattern" "ADD_COMMON" "Add Presets" "REMOVE" "Remove Patterns" "BACK" "Back" 3>&1 1>&2 2>&3)
case $cmd in
ADD_CUSTOM)
local new=$(dialog --inputbox "Pattern:" 8 60 3>&1 1>&2 2>&3)
[ -n "$new" ] && save_setting "IGNORES" "$cur $new"
;;
ADD_COMMON)
local presets=("*/node_modules/*" "Node" "off" "*/.git/*" "Git" "off" "*/.next/*" "NextJS" "off" "*/dist/*" "Dist" "off" "*.log" "Logs" "off")
local sel=$(dialog --checklist "Select:" 20 60 10 "${presets[@]}" 3>&1 1>&2 2>&3)
if [ -n "$sel" ]; then
eval "adds=($sel)"
for i in "${adds[@]}"; do [[ " $cur " != *" $i "* ]] && cur="$cur $i"; done
save_setting "IGNORES" "$cur"
fi
;;
REMOVE)
local items=(); for i in $cur; do items+=("$i" "" "off"); done
[ ${#items[@]} -eq 0 ] && continue
local rem=$(dialog --checklist "Remove:" 20 60 10 "${items[@]}" 3>&1 1>&2 2>&3)
if [ -n "$rem" ]; then
eval "dels=($rem)"
local new_l=""
for i in $cur; do
local keep=true; for d in "${dels[@]}"; do [ "$i" == "$d" ] && keep=false; done
[ "$keep" == "true" ] && new_l="$new_l $i"
done
save_setting "IGNORES" "$(echo $new_l | xargs)"
fi
;;
BACK) return ;;
*) ;;
esac
done
}
settings_menu() {
while true; do
local th=$(read_setting "THEME" "matrix")
local rem=$(read_setting "REMOTE" "$DEFAULT_REMOTE")
local cmd=$(dialog --title "Configuration" --menu "Settings:" 18 60 9 \
"THEME" "Theme [$th]" \
"REMOTE" "Remote [$rem]" \
"IGNORES" "Manage Ignores" \
"AUTOMATION" "Backup Scheduler" \
"NOTIFICATIONS" "Telegram Alerts" \
"CLOUD_SETUP" "Setup Cloud Access" \
"BACK" "Back" 3>&1 1>&2 2>&3)
case $cmd in
THEME)
local n=$(dialog --menu "Theme:" 15 50 8 "matrix" "Matrix" "retro" "Retro (Amber)" "cyberpunk" "Cyberpunk" "dracula" "Dracula" "oceanic" "Oceanic" "solarized" "Solarized Dark" "monokai" "Monokai Pro" "synthwave" "Synthwave '84" "classic" "Classic" 3>&1 1>&2 2>&3)
[ -n "$n" ] && save_setting "THEME" "$n" && CURRENT_THEME="$n" && setup_theme
;;
REMOTE)
local rlist=$(rclone listremotes)
if [ -n "$rlist" ]; then
local options=()
while read -r line; do options+=("$line" "Remote"); done <<< "$rlist"
options+=("MANUAL" "Enter Path Manually")
local sel=$(dialog --menu "Select Cloud Provider:" 15 50 6 "${options[@]}" 3>&1 1>&2 2>&3)
if [ "$sel" == "MANUAL" ]; then
local n=$(dialog --inputbox "Remote Path (e.g. gdrive:Backup):" 8 60 "$rem" 3>&1 1>&2 2>&3)
[ -n "$n" ] && save_setting "REMOTE" "$n" && CURRENT_REMOTE="$n"
elif [ -n "$sel" ]; then
# Configure Folder
local folder=$(read_setting "REMOTE_FOLDER" "myBackUpTool_Data")
local new_f=$(dialog --inputbox "Folder on ${sel%:} (Default: $folder):" 8 60 "$folder" 3>&1 1>&2 2>&3)
[ -z "$new_f" ] && new_f="$folder"
save_setting "REMOTE_FOLDER" "$new_f"
local n="${sel}${new_f}"
save_setting "REMOTE" "$n" && CURRENT_REMOTE="$n"
fi
else
local n=$(dialog --inputbox "No Remotes Found. Enter Path:" 8 60 "$rem" 3>&1 1>&2 2>&3)
[ -n "$n" ] && save_setting "REMOTE" "$n" && CURRENT_REMOTE="$n"
fi
;;
IGNORES) manage_ignores ;;
AUTOMATION)
local sch_cmd=$(dialog --menu "Backup Scheduler" 15 50 6 "ENABLE" "Set/Edit Schedule" "DISABLE" "Disable Schedule" "STATUS" "Check Status" 3>&1 1>&2 2>&3)
case $sch_cmd in
ENABLE) schedule_backup ;;
DISABLE) remove_schedule ;;
STATUS)
local s=$(crontab -l 2>/dev/null | grep "$0")
if [ -n "$s" ]; then dialog --msgbox "Active: $s" 6 60; else dialog --msgbox "No Backup Scheduled." 6 40; fi
;;
esac
;;
NOTIFICATIONS)
local bot=$(read_setting "TG_BOT_TOKEN" "")
local chat=$(read_setting "TG_CHAT_ID" "")
local cmd=$(dialog --menu "Telegram Notifications" 15 60 6 "TOKEN" "Set Bot Token" "CHATID" "Set Chat ID" "TEST" "Send Test Message" "BACK" "Back" 3>&1 1>&2 2>&3)
case $cmd in
TOKEN)
local n=$(dialog --inputbox "Enter Bot Token:" 8 60 "$bot" 3>&1 1>&2 2>&3)
[ -n "$n" ] && save_setting "TG_BOT_TOKEN" "$n"
;;
CHATID)
local n=$(dialog --inputbox "Enter Chat ID:" 8 60 "$chat" 3>&1 1>&2 2>&3)
[ -n "$n" ] && save_setting "TG_CHAT_ID" "$n"
;;
TEST)
send_telegram_notification "Test Message from myBackUpTool" "Test File"
dialog --msgbox "Message sent (check logs if failed)." 6 40
;;
esac
;;
CLOUD_SETUP)
clear
echo "---------------------------------------------------------"
echo " SYSTEM: Launching Cloud Configuration Wizard (rclone) "
echo "---------------------------------------------------------"
echo "Follow instructions to add 'gdrive' or other remotes."
echo "Press ENTER to begin..."
read
rclone config
dialog --msgbox "Configuration wizard completed." 6 40
;;
BACK) return ;;
*) ;;
esac
done
}
info_section() {
local r=$(read_setting "REMOTE" "$DEFAULT_REMOTE")
local t=$(read_setting "THEME" "matrix")
local v="$VERSION"
dialog --title "About" --msgbox "myBackUpTool $v\n\nCreated By: not_jarod\nSource: https://github.com/a2-stuff/myBackUpTool\n\nTheme: $t\nRemote: $r\n\nFeatures: Multi-threaded, Exclusion Manager, Matrix UI." 15 65
}
# ------------------------------------------------------------------------------
# Directory Manager
# ------------------------------------------------------------------------------
manage_directories() {
# Simplified for brevity in v1.0.8, functionality same
while true; do
local opts=(); local i=1
while read l; do [ -n "$l" ] && opts+=("$i" "$l") && ((i++)); done < "$CONFIG_FILE"
local cmd=$(dialog --menu "Targets:" 15 60 6 "ADD" "Add" "REMOVE" "Remove" "BACK" "Back" "${opts[@]}" 3>&1 1>&2 2>&3)
case $cmd in
ADD)
local r=$(dialog --title "Select Root Directory" --dselect "$HOME/" 10 60 3>&1 1>&2 2>&3)
if [ -d "$r" ]; then
local s=(); while read d; do [ "$d" != "$r" ] && s+=("$d" "" "off"); done < <(find "$r" -maxdepth 1 -type d 2>/dev/null)
local a=$(dialog --checklist "Add:" 20 60 10 "${s[@]}" 3>&1 1>&2 2>&3)
if [ -n "$a" ]; then eval "p=($a)"; for x in "${p[@]}"; do grep -qFx "$x" "$CONFIG_FILE" || echo "$x" >> "$CONFIG_FILE"; done; fi
fi
;;
REMOVE)
local opts=(); while read l; do [ -n "$l" ] && opts+=("$l" "" "off"); done < "$CONFIG_FILE"
[ ${#opts[@]} -gt 0 ] && local r=$(dialog --checklist "Remove:" 15 60 8 "${opts[@]}" 3>&1 1>&2 2>&3)
if [ -n "$r" ]; then
mv "$CONFIG_FILE" "${CONFIG_FILE}.bak"
touch "$CONFIG_FILE"
eval "d=($r)"
while read l; do
k=true; for x in "${d[@]}"; do [ "$x" == "$l" ] && k=false; done; [ "$k" == true ] && echo "$l" >> "$CONFIG_FILE"
done < "${CONFIG_FILE}.bak"; rm "${CONFIG_FILE}.bak"
fi
;;
BACK) return ;;
esac
done
}
# ------------------------------------------------------------------------------
# Backup Logic (Advanced UI)
# ------------------------------------------------------------------------------
perform_backup() {
local mode=$1
local dest=$(read_setting "REMOTE" "$DEFAULT_REMOTE")
local ig=$(read_setting "IGNORES" "$DEFAULT_IGNORES")
set -f # Disable globbing for pattern split
local args=(); for p in $ig; do args+=("-x" "$p"); done
set +f
local targets=()
if [ "$mode" == "interactive" ]; then
local opts=(); while read l; do [ -n "$l" ] && opts+=("$l" "" "on"); done < "$CONFIG_FILE"
[ ${#opts[@]} -eq 0 ] && dialog --msgbox "No targets." 6 40 && return
local s=$(dialog --checklist "Backup:" 15 60 8 "${opts[@]}" 3>&1 1>&2 2>&3)
[ $? -ne 0 ] && return
eval "targets=($s)"
else
while read l; do [ -n "$l" ] && targets+=("$l"); done < "$CONFIG_FILE"
fi
[ ${#targets[@]} -eq 0 ] && return
local total=${#targets[@]}
local counter=0
local step_size=$((100 / total)) # approximate
for src in "${targets[@]}"; do
((counter++))
local pct=$(( (counter - 1) * 100 / total ))
local dirn=$(basename "$src")
local ts=$(date "+%Y-%m-%d_%H%M%S")
local zn="backup_${dirn}_${ts}.zip"
local zp="${TEMP_DIR}/${zn}"
local job_log="${TEMP_DIR}/job_current.log"
: > "$job_log"
if [ "$mode" == "interactive" ]; then
# v1.2.2 Unified Dashboard: Single Gauge with Streaming Logs
: > "$job_log"
touch "${TEMP_DIR}/progress.flag"
# 1. Start Worker in Background (writes to log)
(
echo "[$(date +%T)] Init: Batch $counter of $total" >> "$job_log"
parent_dir=$(dirname "$src")
base_name=$(basename "$src")
echo "[$(date +%T)] Compressing $base_name..." >> "$job_log"
if (cd "$parent_dir" && zip -r -v "$zp" "$base_name" "${args[@]}" >> "$job_log" 2>&1); then
echo "[$(date +%T)] Uploading to $dest..." >> "$job_log"
if rclone copy -v "$zp" "$dest" >> "$job_log" 2>&1; then
rm -f "$zp"
echo "[$(date +%T)] Success: $dirn" >> "$job_log"
echo "SUCCESS" > "${TEMP_DIR}/status.flag"
else
echo "[$(date +%T)] Upload FAILED" >> "$job_log"
echo "FAIL" > "${TEMP_DIR}/status.flag"
fi
else
echo "[$(date +%T)] Zip FAILED" >> "$job_log"
echo "FAIL" > "${TEMP_DIR}/status.flag"
fi
rm -f "${TEMP_DIR}/progress.flag"
) &
bg_pid=$!
# 2. Main Loop: Feed Gauge with Log Tail
# We simulate progress % based on time or stages if we can't get real numbers
# or just pulse. Let's do a pulse visual.
local p=0
while [ -f "${TEMP_DIR}/progress.flag" ]; do
# Get last 15 lines of log
local logs=$(tail -n 15 "$job_log")
# Update Gauge
echo "XXX"
echo "$p"
echo "$logs"
echo "XXX"
# Pulse effect
p=$(( (p + 5) % 100 ))
sleep 0.5
done | dialog --title "Processing: $dirn ($counter/$total)" --gauge "Initializing..." 20 80 0
wait $bg_pid
if [ "$(cat "${TEMP_DIR}/status.flag" 2>/dev/null)" == "SUCCESS" ]; then
log_message "Success: $dirn"
send_telegram_notification "" "$zn"
else
# Capture Error Detail
local err_msg=$(tail -n 1 "$job_log" | grep -v "Batch" | grep -v "XXX")
[ -z "$err_msg" ] && err_msg="Unknown Error. Check logs."
log_message "Failure: $dirn - $err_msg"
dialog --msgbox "Error processing $dirn.\n\nDetail: $err_msg" 8 60
fi
rm -f "${TEMP_DIR}/status.flag"
else
# Auto (Quiet)
parent_dir=$(dirname "$src")
base_name=$(basename "$src")
if (cd "$parent_dir" && zip -r -q "$zp" "$base_name" "${args[@]}") && rclone copy "$zp" "$dest"; then
rm -f "$zp"
send_telegram_notification "" "$zn"
else
log_message "Auto Backup Failed for $dirn"
fi
fi
# Increment percentage
pct=$(( counter * 100 / total ))
done
[ "$mode" == "interactive" ] && dialog --msgbox "Sequence Complete." 6 40
}
schedule_backup() {
local t=$(dialog --inputbox "Time:" 8 40 "03:00" 3>&1 1>&2 2>&3)
[ -n "$t" ] && (crontab -l 2>/dev/null | grep -v "$0" ; echo "${t:3:2} ${t:0:2} * * * /bin/bash $(realpath "$0") --backup-all >> ${LOG_FILE} 2>&1") | crontab -
dialog --msgbox "Scheduled for $t daily." 6 40
}
remove_schedule() {
(crontab -l 2>/dev/null | grep -v "$0") | crontab -; dialog --msgbox "Removed." 6 40
}
view_logs() {
tail -n 30 "$LOG_FILE" > "${TEMP_DIR}/lv"; dialog --textbox "${TEMP_DIR}/lv" 20 75; rm "${TEMP_DIR}/lv"
}
# ------------------------------------------------------------------------------
# Entry
# ------------------------------------------------------------------------------
check_dependencies
if [ "$1" == "--backup-all" ]; then
perform_backup "automated"
exit 0
fi
setup_theme
boot_animation
while true; do
CHOICE=$(dialog --clear --backtitle "myBackUpTool $VERSION" --title "Main Menu" --menu "Select:" 17 60 7 \
1 "Backup" 2 "Dirs" 3 "Settings" 4 "Logs" 5 "Info" 6 "Exit" 3>&1 1>&2 2>&3)
case $CHOICE in
1) perform_backup "interactive" ;; 2) manage_directories ;; 3) settings_menu ;; 4) view_logs ;;
5) info_section ;; 6) shutdown_animation; break ;; *) shutdown_animation; break ;;
esac
done