linuxtorvalds / rpms / kernel

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