From fc352e466162ba2b8147b4919904ca9bd40f4bc5 Mon Sep 17 00:00:00 2001 From: Reuben Miller Date: Thu, 11 Jan 2024 20:56:38 +0100 Subject: [PATCH] fixup! fixup! fixup! fixup! fix(build): auto detection when to use when compressing the image using xz --- run-bakery | 10 ---------- scripts/compress.sh | 18 ++++++++---------- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/run-bakery b/run-bakery index 1956756..b4cea79 100755 --- a/run-bakery +++ b/run-bakery @@ -5,17 +5,7 @@ set -e DOCKER=${DOCKER:-docker} RUGPI_IMAGE=${RUGPI_IMAGE:-ghcr.io/silitics/rugpi-bakery:latest} -OPTIONS=() -if command -V id >/dev/null >&2; then - UID=$(id -u) - GID=$(id -g) - OPTIONS+=( - --user "$UID:$GID" - ) -fi - $DOCKER run --rm --privileged \ - "${OPTIONS[@]}" \ -v "$(pwd)":/project \ -v /dev:/dev \ --pull always \ diff --git a/scripts/compress.sh b/scripts/compress.sh index 9587e05..dce4ced 100755 --- a/scripts/compress.sh +++ b/scripts/compress.sh @@ -3,22 +3,20 @@ set -e SUDO= -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 +requires_sudo() { + if stat --help >/dev/null 2>&1; then + IMAGE_OWNER=$(stat -c "%u" justfile) + else + # bsd version + IMAGE_OWNER=$(stat -f "%u %g" justfile) fi - rm -f .dummy_compress - rm -f .dummy_compress.xz - return "$failed" + [ "$IMAGE_OWNER" = 0 ] } # 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 +if requires_sudo; then echo "xz test file returned a warning, so compressing using sudo" >&2 SUDO=sudo fi