Skip to content

Commit

Permalink
Meta: Support building images without root permissions
Browse files Browse the repository at this point in the history
If both the fakeroot and genext2fs tools are installed, mount (and
therefore sudo) is not required. Instead we can set the appropriate file
permissions in the root file system in a fakeroot environment and
then use genext2fs to generate the image.
  • Loading branch information
kissen committed Aug 26, 2021
1 parent eb368a5 commit bbb31f9
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Meta/build-image-qemu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,21 @@ die() {
exit 1
}

# If both the fakeroot and genext2fs tools are installed, no root permissions
# are required. If either tool is missing, we have to fall back to mounting
# the image which does require root.

can_use_fakeroot=0
if (command -v fakeroot 1> /dev/null) && (command -v genext2fs 1> /dev/null); then
can_use_fakeroot=1
fi

if [ "$(id -u)" != 0 ]; then
exec sudo -E -- "$0" "$@" || die "this script needs to run as root"
if [ $can_use_fakeroot = 1 ]; then
exec fakeroot "$0" "$@" || die "simulating root permissions with fakeroot failed"
else
exec sudo -E -- "$0" "$@" || die "this script needs to run as root"
fi
else
: "${SUDO_UID:=0}" "${SUDO_GID:=0}"
fi
Expand Down

0 comments on commit bbb31f9

Please sign in to comment.