How to show a progress bar for mksquashfs and GUI dialogue? (solved)

interpretive language scripts


Moderator: Forum moderators

Post Reply
mow9902
Posts: 196
Joined: Fri Jul 24, 2020 11:57 pm
Has thanked: 15 times
Been thanked: 62 times

How to show a progress bar for mksquashfs and GUI dialogue? (solved)

Post by mow9902 »

Hi,

I often use mksquashfs to compress directories before I copy them to another disk for backup. This works fine. But, if the directory is large, then the command takes a long time. At the moment I simply display a splash message "Working.." for an estimated completion time while it is in process.
I would like to show a GUI progress bar while the process is active. I thought I might be able to do this using the pv command - but even though I have read through many examples online, I just cannot seem to understand the syntax for the command to do what I want. Basically I want to:
- execute a mksquashfs <sourcedirectory> <new name.sfs> and while this is running I would like to display an Xdialog screen or a gtkdialog-splash screen showing the % completion - and if possible the estimated remaining time (although I'm guessing this last bit is probably not possible).

Is there anyone who can help me please.

Last edited by mow9902 on Sat Oct 05, 2024 9:05 pm, edited 1 time in total.
User avatar
fredx181
Posts: 3132
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 380 times
Been thanked: 1333 times
Contact:

Re: help with mksquashfs and GUI progress dialogue

Post by fredx181 »

mow9902 wrote: Fri Oct 04, 2024 7:30 am

Hi,

I often use mksquashfs to compress directories before I copy them to another disk for backup. This works fine. But, if the directory is large, then the command takes a long time. At the moment I simply display a splash message "Working.." for an estimated completion time while it is in process.
I would like to show a GUI progress bar while the process is active. I thought I might be able to do this using the pv command - but even though I have read through many examples online, I just cannot seem to understand the syntax for the command to do what I want. Basically I want to:
- execute a mksquashfs <sourcedirectory> <new name.sfs> and while this is running I would like to display an Xdialog screen or a gtkdialog-splash screen showing the % completion - and if possible the estimated remaining time (although I'm guessing this last bit is probably not possible).

Is there anyone who can help me please.

Here's script "cr-sfs" that I made some time ago already, it should do what you want, using yad for the initial gui and Xdialog for the progress bar.
Usage : e.g. ./cr-sfs /path/to/mydir

cr-sfs.gz
Remove fake .gz extension and make executable
(5.4 KiB) Downloaded 16 times

And the sfs will be created in the same location as the folder you chose.

2024-10-04_10-13-13.png
2024-10-04_10-13-13.png (81.98 KiB) Viewed 489 times
2024-10-04_10-13-45.png
2024-10-04_10-13-45.png (38.01 KiB) Viewed 489 times

EDIT:

... and if possible the estimated remaining time (although I'm guessing this last bit is probably not possible).

Indeed, that's not possible (as far as I know).
EDIT2: If you want to change mksquashfs options, e.g. blocksize, see lines 108-110

User avatar
Jasper
Posts: 2105
Joined: Wed Sep 07, 2022 1:20 pm
Has thanked: 869 times
Been thanked: 490 times

Re: help with mksquashfs and GUI progress dialogue

Post by Jasper »

@mow9902

I guess the issue has been resolved with the assistance of fredx181.

I have come to this late and I wanted to suggest the wonder that is "PackIt-1.24 - a flexible Archiving/Compressing GUI" by @JakeSFR

viewtopic.php?t=6868

I must use this or his other application UExtract several times everyday ......their perfect for me!!

It does not give a percentage of progress per se, but provides information regarding the final output size. So it doesn't fully meet your requirements but both applications are useful to keep in the toolkit.

packit-mksquashfs.png
mow9902
Posts: 196
Joined: Fri Jul 24, 2020 11:57 pm
Has thanked: 15 times
Been thanked: 62 times

Re: How to show a progress bar for mksquashfs and GUI dialogue?

Post by mow9902 »

@fredx181

Thanks for this. However I'd like to use this in several different situations, and need the code for just the second screen you showed ie to execute the mksquashfs command and pipe the progress to the Xdialog screen. I will try to play around with bits and pieces of your code to see if I can do it - but my scripting skills are poor - so if you feel inclined to help me further I'd be grateful.

User avatar
MochiMoppel
Posts: 1245
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 22 times
Been thanked: 446 times

Re: help with mksquashfs and GUI progress dialogue

Post by MochiMoppel »

fredx181 wrote: Fri Oct 04, 2024 8:23 am

Here's script "cr-sfs" that I made some time ago already, it should do what you want, using yad for the initial gui and Xdialog for the progress bar.

@fredx181 Are you sure that the Xdialog progress bar still works as it is supposed to work?
In BW64 Xdialog doesn't show percentage anymore within the bar. I tried one of my old demos. Works in Slacko 5.6, but no percentage display in the bar in BW64:

Code: Select all

#! /bin/bash
COUNT=0
( while :; do
	# Text above gauge bar (enclosed in XXX)
	echo "XXX"
	echo "Value: $COUNT"
	echo "XXX"
	# Text within gauge bar
	echo $COUNT
	# Prepare next while cycle
	COUNT=$((COUNT + 5))
	sleep .3
done) | Xdialog --gauge "" 0 0
User avatar
fredx181
Posts: 3132
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 380 times
Been thanked: 1333 times
Contact:

Re: help with mksquashfs and GUI progress dialogue

Post by fredx181 »

MochiMoppel wrote: Sat Oct 05, 2024 4:21 am
fredx181 wrote: Fri Oct 04, 2024 8:23 am

Here's script "cr-sfs" that I made some time ago already, it should do what you want, using yad for the initial gui and Xdialog for the progress bar.

@fredx181 Are you sure that the Xdialog progress bar still works as it is supposed to work?
...

Yes, you are right, I tested earlier with older Xdialog, the new version in BWpup is built with GTK3, pity that it doesn't display percentage in progress bar.

@mow9902

Anyway, here's a much more basic script, usage e.g. ./cr-sfs /path/to/mydir /path/to/my.sfs and it will directly show the Xdialog progress.
If you use the newest Xdialog the percentage will show above the progress bar (not inside it, see pic below).
If you use the older Xdialog, just remove lines 11, 18 and 19 (edit: and 20 too) (not needed as percentage is probably already showing inside progress bar)
It doesn't do any checking, i.e. if directory exist or if the .sfs possibly exist already .
Tell me if it's still not exactly what you need.

Code: Select all

#!/bin/bash

DIR="$1"
SFS="$2"

COMP="-comp xz -b 512k -Xbcj x86"    # set mksquashfs options

(
script -q -c 'stty rows 40 cols 100; mksquashfs '"'$DIR'"' '"'$SFS'"' '"$COMP"'' |while read -n 250 LINE ; do
NAME="$(basename "$SFS")"
PERC="$(echo $LINE | busybox strings |egrep '[0-9]\%' |awk '{print $NF}' | tail -1)"
echo "XXX"
echo "Creating 4.0 filesystem on:"
echo "\\n"
echo "$NAME"
echo "\\n"
echo "Close this Window to Cancel processing."
echo "\\n"
echo "\\n"
echo "$PERC"
echo "XXX"
echo $LINE | busybox strings |egrep '[0-9]\%'| cut -f1 -d% |awk '{print $NF}'|grep -v '\.' ;done &
) | Xdialog --title "Building Sfs  . . . " --gauge "" 12 90 0

if [ $? -ne 0 ]; then
SQUASHPID=$(ps -eo pid,cmd | grep "mksquashfs $DIR $SFS" | grep -v grep | awk '{ print $1 }')
kill $SQUASHPID
echo "SFS creation canceled"
fi
rm -f typescript

exit 0
Running from BookwormPup with Xdialog built with GTK3
Running from BookwormPup with Xdialog built with GTK3
Screenshot(6).png (19.95 KiB) Viewed 334 times
mow9902
Posts: 196
Joined: Fri Jul 24, 2020 11:57 pm
Has thanked: 15 times
Been thanked: 62 times

Re: How to show a progress bar for mksquashfs and GUI dialogue?

Post by mow9902 »

@fredx181

This should do the trick nicely. Thanks so much for the help.

Post Reply

Return to “Scripts”