1

Part of my dialog-based program involves running unsquashfs on a file to extract it to a directory. I'm trying to make a progress bar for this operation to show its progress using the --gauge option. What I've tried is this:

unsquashfs -f -q -d extract_directory filesystem.squashfs | dialog --title "Progress" --gauge "Unsquashing filesystem..." 7 60

I've also tried unsquashfs with other options like -i and -n, and none of them seem to work. The progress bar does display, but it is always stuck at 0%. Is it possible to make it work? I don't mind using hacky workarounds if they are needed.

1
  • well -n disables the progress bar, so that's not going to help. Commented Jan 8, 2022 at 13:55

1 Answer 1

0

It's not going to be that easy: dialog --gauge expects the percentages from stdin, as one number per line.

However, unsquashfs doesn't have that kind of output! It uses console control characters to update its progress bar, probably (at least it doesn't link against libncurses).

The important part is line 145 in progressbar.c in the squashfs-tools source code:

    printf("\r[");
…
    printf(" %3d%%", percentage);

The control character \r jumps to the beginning of the current line, then that line is overwritten with the progress bar, then the percentage is finally printed.

so you'll probably need something like

unsquashfs linux.squash | tr $'\r' $'\n' | sed -ne 's/^.* \([[:digit:]]*\)\%$/\1/p' | dialog --gauge

but I doubt it will work. Most probably, there will be buffering, and all your percentages will appear at once (try without the | dialog --gauge).

Honestly, the progressbar of unsquashfs does work. Simply show that instead of a dialog showing the same?

Other than that, there's things like libraries which can uncompress squashfs, and I guess you could use these to build your own program that outputs percentages instead of anything else. Or, you could add a command line switch to mksquashfs and unsquashfs's source code and make them do that – probably the easiest solution here.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.