From 8a1a2c1f7cad76e8a1f6fd8f6f94b204b6ebd5b5 Mon Sep 17 00:00:00 2001 From: Reuben Miller Date: Thu, 11 Jan 2024 18:21:58 +0100 Subject: [PATCH] fix(build): auto detection when to use when compressing the image using xz --- scripts/compress.sh | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/scripts/compress.sh b/scripts/compress.sh index a543c0d..d28b3c1 100755 --- a/scripts/compress.sh +++ b/scripts/compress.sh @@ -2,10 +2,24 @@ set -e SUDO= -if [ -n "$CI" ]; then - # use sudo when running in the CI otherwise the following error occurs - # regardless of the owner of the file and folder. - # xz: Cannot set the file group: Operation not permitted + +test_xz() { + # Check if xz can be used without sudo using a dummy file + echo "dummy" > .dummy_compress + failed=0 + if ! xz -0 -v .dummy_compress >/dev/null >&2; then + failed=1 + fi + rm -f .dummy_compress + rm -f .dummy_compress.xz + return "$failed" +} + +# use sudo when running in the CI otherwise the following error occurs +# regardless of the owner of the file and folder. +# xz: Cannot set the file group: Operation not permitted +if ! test_xz; then + echo "xz test file returned a warning, so compressing using sudo" >&2 SUDO=sudo fi