orgads / rpms / kernel

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