jfaracco / rpms / kernel-auto

Forked from rpms/kernel-auto 3 years ago
Clone

Blame SOURCES/parallel_xz.sh

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