From 8d5f598488b7333181d1ccb2e7c7a929fc6cc5d8 Mon Sep 17 00:00:00 2001 From: apio Date: Sun, 11 Feb 2024 13:39:51 +0100 Subject: [PATCH] tools: Allow building as root for CI --- .gitea/workflows/build.yaml | 4 ++-- tools/install.sh | 7 +------ tools/make-iso.sh | 14 ++++++++++++-- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index 1468d19e..24b86ace 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -10,8 +10,8 @@ jobs: uses: actions/checkout@v3 - name: Download dependencies run: | - sudo apt update - sudo apt install -y cmake ninja-build nasm genext2fs qemu-system build-essential wget git fakeroot + apt update + apt install -y cmake ninja-build nasm genext2fs qemu-system build-essential wget git fakeroot - name: Set up the toolchain run: | wget https://pub.cloudapio.eu/luna/toolchains/ci-toolchain-arm64.tar.gz --quiet diff --git a/tools/install.sh b/tools/install.sh index b0716466..c915e7ca 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -11,12 +11,6 @@ then exit 1 fi -if [ "$USER" == "root" ] -then - echo "This script must be run under fakeroot instead of as root." - exit 1 -fi - chown -R root:root base cmake --install $LUNA_BUILD_DIR @@ -31,5 +25,6 @@ mkdir -p base/tmp rm -f base/bin ln -s usr/bin base/bin +chown -h root:root base/bin cp $LUNA_ROOT/LICENSE base/etc/skel/LICENSE diff --git a/tools/make-iso.sh b/tools/make-iso.sh index 1076b2de..fdae986f 100755 --- a/tools/make-iso.sh +++ b/tools/make-iso.sh @@ -5,12 +5,22 @@ source $(dirname $0)/env.sh cd $LUNA_ROOT -fakeroot -u -s $LUNA_ROOT/.fakeroot -- tools/install.sh +if [ "$(id -u)" -ne "0" ] +then + export FAKEROOT_SAVE="fakeroot -u -s $LUNA_ROOT/.fakeroot -- " + export FAKEROOT_RESTORE="fakeroot -u -i $LUNA_ROOT/.fakeroot -- " +else + echo "Caution: you are running make-iso.sh as root. This should only be done inside a container, for example in CI." + export FAKEROOT_SAVE="" + export FAKEROOT_RESTORE="" +fi + +${FAKEROOT_SAVE}tools/install.sh disk_space=$(du -s base | awk '{ print $1 }') min_blocks=$(($disk_space / 4)) # This is just the blocks needed for all the files in the file system: this excludes space for the inode table, block group descriptors, etc. blocks=$(($min_blocks + 1024)) # This is the actual number of blocks we're using. -fakeroot -u -i $LUNA_ROOT/.fakeroot -- genext2fs -d base -B 4096 -b $blocks -L luna-rootfs -N 1024 build/ext2fs.bin +${FAKEROOT_RESTORE}genext2fs -d base -B 4096 -b $blocks -L luna-rootfs -N 1024 build/ext2fs.bin mkbootimg luna.json Luna.iso