TheChymera / mkstage4

Bash Utility for Creating Stage 4 Tarballs
GNU General Public License v3.0
104 stars 22 forks source link

Quoted arguments to `--use-compress-prog=` (we use `-T0` for `xz`) fail due to inability to match quotation marks. #46

Closed TheChymera closed 2 years ago

TheChymera commented 2 years ago
decohost /home/chymera/src/mkstage4 # ./mkstage4.sh -C xz -s stage4-amd64-musl-clang-20220911 --exclude=/etc/ssh/ssh_host*
Are you sure that you want to make a stage 4 tarball of the system
located under the following directory?
/

WARNING: since all data is saved by default the user should exclude all
security- or privacy-related files and directories, which are not
already excluded by mkstage4 options (such as -c), manually per cmdline.
example: $ mkstage4.sh -s /my-backup --exclude=/etc/ssh/ssh_host*

COMMAND LINE PREVIEW:
tar -cpP --ignore-failed-read --xattrs-include='*.*' --numeric-owner --use-compress-prog='/usr/bin/xz -T0' --exclude=/dev/* --exclude=/var/tmp/* --exclude=/media/* --exclude=/mnt/*/* --exclude=/proc/* --exclude=/run/* --exclude=/sys/* --exclude=/tmp/* --exclude=/var/lock/* --exclude=/var/log/* --exclude=/var/run/* --exclude=/var/lib/docker/* --exclude=/home/chymera/src/mkstage4/stage4-amd64-musl-clang-20220911.tar.xz --exclude=/var/db/repos/gentoo/* --exclude=/var/cache/distfiles/* --exclude=/etc/ssh/ssh_host* -f /home/chymera/src/mkstage4/stage4-amd64-musl-clang-20220911.tar.xz /

Type "yes" to continue or anything else to quit: yes
tar: 0': Cannot stat: No such file or directory
tar: Error is not recoverable: exiting now

Technically it should work: https://www.gnu.org/software/tar/manual/html_section/Compression.html but it does now.

Other workarounds such as double quotes or using argument shorthands without the equal sign also fail to work.

One fix might be to re-write the logic to use export XZ_DEFAULTS="-T 0" and leverage the J argument of tar (more here).

bug initially reported by ppw, informally.

TheChymera commented 2 years ago

Disabled feature temporarily: https://github.com/TheChymera/mkstage4/commit/df3d89d5a265a9c30e7d4484fc3d84c410dc5deb

ppw0 commented 2 years ago

Hi there. So, as discussed, the simplest solution is to remove the quotes and replace the array subscript @ with * for --use-compress-prog when constructing the TAR_OPTIONS array. So the full code would look something like this:

COMP_OPTIONS=("${COMPRESS_AVAILABLE[$COMPRESS_TYPE]}")
if [[ "${COMPRESS_AVAILABLE[$COMPRESS_TYPE]}" == *"/xz" ]]
then
    COMP_OPTIONS+=( "-T0" )
fi

# Generic tar options:
TAR_OPTIONS=(
    -cpP
    --ignore-failed-read
    --xattrs-include='*.*'
    --numeric-owner
    --use-compress-prog="${COMP_OPTIONS[*]}"
        )

Hope this helps!

TheChymera commented 2 years ago

@ppw0 should be fixed as of https://github.com/TheChymera/mkstage4/commit/8099ec1c8b540c745180a429601e6adcf45c77dc — feel free to reopen or comment if this is not the case. And thanks for your help!

TheChymera commented 2 years ago

Solved as of https://github.com/TheChymera/mkstage4/commit/999415bda6835fd374066914697ac67a677c26de