chengshan / rpms / kernel

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