pengqianheng / rpms / kernel

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