Blame SOURCES/parallel_xz.sh

e8eba4
#!/bin/sh
e8eba4
# Reads filenames on stdin, xz-compresses each in place.
e8eba4
# Not optimal for "compress relatively few, large files" scenario!
e8eba4
e8eba4
# How many xz's to run in parallel:
e8eba4
procgroup=""
e8eba4
while test "$#" != 0; do
e8eba4
	# Get it from -jNUM
e8eba4
	N="${1#-j}"
e8eba4
	if test "$N" = "$1"; then
e8eba4
		# Not -j<something> - warn and ignore
e8eba4
		echo "parallel_xz: warning: unrecognized argument: '$1'"
e8eba4
	else
e8eba4
		procgroup="$N"
e8eba4
	fi
e8eba4
	shift
e8eba4
done
e8eba4
e8eba4
# If told to use only one cpu:
e8eba4
test "$procgroup" || exec xargs -r xz
e8eba4
test "$procgroup" = 1 && exec xargs -r xz
e8eba4
e8eba4
# xz has some startup cost. If files are really small,
e8eba4
# this cost might be significant. To combat this,
e8eba4
# process several files (in sequence) by each xz process via -n 16:
e8eba4
exec xargs -r -n 16 -P "$procgroup" xz