liuyingdong / rpms / kernel

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