imperfectism / rpms / kernel

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