@@ -11,9 +11,9 @@ monitor_progress() {
1111 local current_package=0
1212 local update_started=0
1313 local phase=" Downloading" # Start with the Downloading phase
14-
14+
1515 # Tail the log file and process each line
16- tail -f " $log_file " | while IFS= read -r line; do
16+ tail -n 1000 - f " $log_file " | while IFS= read -r line; do
1717 # Check if the transactional-update process has started
1818 if [[ " $line " =~ Options:\ -c \ dup ]]; then
1919 update_started=1
@@ -31,12 +31,27 @@ monitor_progress() {
3131
3232 echo " $progress %"
3333 fi
34+
35+ if [[ " $line " =~ In\ cache\ .* \( ([0-9]+)/([0-9]+)\) ]]; then
36+ current_package=${BASH_REMATCH[1]}
37+ total_packages=${BASH_REMATCH[2]}
38+
39+ # Calculate overall progress for downloading
40+ local progress=$(( current_package * 100 / (2 * total_packages)) )
41+
42+ echo " $progress %"
43+ fi
3444
3545 # Switch to Installation phase when "Checking for file conflicts:" line appears
3646 if [[ " $line " == * " Checking for file conflicts:" * ]] && [[ " $phase " == " Downloading" ]]; then
3747 phase=" Installing"
3848 current_package=0 # Reset current package for installation phase
3949 fi
50+
51+ if [[ " $line " == * " Preparing" * ]] && [[ " $phase " == " Downloading" ]]; then
52+ phase=" Installing"
53+ current_package=0 # Reset current package for installation phase
54+ fi
4055
4156 # Parse the progress for installing
4257 if [[ " $phase " == " Installing" && " $line " =~ \(\ * ([0-9]+)/([0-9]+)\)\ Installing:\ .* | \(\ * ([0-9]+)/([0-9]+)\)\ Removing:\ .* ]]; then
@@ -60,15 +75,20 @@ monitor_progress() {
6075}
6176
6277run_update () {
78+ echo " 0%"
6379 # Run the transactional-update command and redirect output to the log file
64- transactional-update -c run zypper --non-interactive dup --allow-vendor-change > " $log_file " 2>&1 &
80+ transactional-update -c dup > " $log_file " 2>&1 &
6581 pid=$!
6682
6783 # Start the monitor_progress function in the background
6884 monitor_progress &
85+ pid2=$!
6986
7087 # Wait for the transactional-update command to finish
7188 wait $pid
89+ pkill $pid2 || true
90+ pkill -P $$ tail || true
91+ echo " 100%"
7292}
7393
7494check_update () {
@@ -134,7 +154,6 @@ main() {
134154 esac
135155 done
136156
137- echo " 0%"
138157 check_branch
139158 check_update
140159 exit_status=$? # Capture the exit status of check_update
0 commit comments