Bug#592519: $COMPRESS/$compress does not accept arguments
Hi,
I wanted to say pass options to my compress program, e.g.
# cat /etc/initramfs-tools/conf.d/xz
compress="pxz -Ccrc32 -1" # dev builds should build fast
compress="pxz -Ccrc32 -9ev" # prod builds should boot fast
Unfortunately this code requires the compress (or COMPRESS) be a program,
not a program-plus-options:
2010-07-05 mat 3bdc6b1 if ! command -v "${compress}" >/dev/null 2>&1; then
2010-02-28 bsc 38c90c5 compress=gzip
2010-02-28 bsc 38c90c5 [ "${verbose}" = y ] && \
2010-02-28 bsc 38c90c5 echo "No ${COMPRESS} in ${PATH}, using gzip"
2011-01-25 GTi 9c25269 COMPRESS=gzip
2010-02-28 bsc 38c90c5 fi
This results in:
No xz --check=crc32 -1 in /usr/bin:/sbin:/bin, using gzip
This is incredibly annoying, because immediately AFTER that test,
compress gets used in exactly the way I want:
2010-04-09 bsc 3041c94 [ "${compress}" = lzop ] && compress="lzop -9"
2014-10-16 BHu cf9691d [ "${compress}" = xz ] && compress="xz --check=crc32"
A yukky kludge is to strip everything after a space (but not tab &c):
- if ! command -v "${compress}" >/dev/null 2>&1; then
+ if ! command -v "${compress%% *}" >/dev/null 2>&1; then
Another approach would just be to run the command with --help, or dummy data:
- if ! command -v "${compress}" >/dev/null 2>&1; then
+ if ! "$compress" </dev/null >/dev/null 2>&1; then
If $? is 127, then it's not in $PATH.
In the meantime, I can work around this by creating a wrapper script:
>/ARGH.sh printf '#!/bin/sh\nexec pxz -Ccrc32 -9ev\n'
chmod +x /ARGH.sh
>/etc/initramfs-tools/conf.d/xz echo COMPRESS=/ARGH.sh
update-initramfs -u -k all
...but this makes me sad.
Reply to: