As written, it would be waited for. For a pulsating progress bar:
#! /bin/sh -
export LC_ALL=C
cd /path/to/dir || exit
{
md5=$(
find . -type f -print0 |
sort -z |
xargs -r0 md5sum |
md5sum
)
exec >&-
zenity --info \
--title="Checksum" \
--text="$md5"
} | zenity --progress \
--auto-close \
--auto-kill \
--pulsate \
--title="${0##*/}" \
--text="Computing checksum"
For an actual progress bar, you'd need to know the number of files to process in advance.
With zsh:
#! /bin/zsh -
export LC_ALL=C
autoload zargs
cd /path/to/dir || exit
{
files=(.//**/*(ND.))
} > >(
zenity --progress \
--auto-close \
--auto-kill \
--pulsate \
--title=$0:t \
--text="Finding files"
)
md5=(
$(
zargs $files -- md5sum \
> >(
awk -v total=$#files '/\/\// {print ++n * 100 / total}' | {
zenity --progress \
--auto-close \
--title=$0:t \
--text="Computing checksum" || kill -s PIPE $$
}) \
| md5sum
)
)
zenity --info \
--title=$0:t \
--text="MD5 sum: $md5[1]"
Note that outside of the C locale, on GNU systems at least, filename order is not deterministic, as some characters sort the same and also filenames are not guaranteed to be made of valid text, hence the LC_ALL=C above.
The C locale order is also very simple (based on byte value) and consistent from system to system and version to version.
Beware that means that error messages if any will be displayed in English instead of the user's language (but then again the Computing checksum, Finding files, etc are not localised either so it's just as well).
Some other improvements over your approach:
- Using
-exec md5sum {} + or -print0 | xargs -r0 md5sum (or zargs equivalent) minimises the number of md5sum invocations, each md5sum invocation being passed a number of files. -exec md5sum {} \; means running one md5sum per file which is very inefficient.
- we sort the list of files before passing to
md5sum. Doing sort -k2 in general doesn't work as file names can contain newline characters. In general, it's wrong to process file paths line-based. You'll notice we use a .// prefix in the zsh approach for awk to be able to count files reliable. Some md5sum implementations also have a -z option for NUL-delimited records.
=in the zenity command? It is probably still invalid code.