Skip to content

Meta: Build without root #11224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 30 additions & 17 deletions Meta/build-image-qemu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@ die() {
exit 1
}

USE_FUSE2FS=0

if [ "$(id -u)" != 0 ]; then
exec sudo -E -- "$0" "$@" || die "this script needs to run as root"
if [ -x /usr/sbin/fuse2fs ] && /usr/sbin/fuse2fs --help 2>&1 |grep fakeroot > /dev/null; then
USE_FUSE2FS=1
else
sudo -E -- "$0" "$@" || die "this script needs to run as root"
exit 0
fi
else
: "${SUDO_UID:=0}" "${SUDO_GID:=0}"
fi
Expand Down Expand Up @@ -67,7 +74,7 @@ if [ -f _disk_image ]; then

echo "checking existing image"
result=0
e2fsck -f -y _disk_image || result=$?
/usr/sbin/e2fsck -f -y _disk_image || result=$?
if [ $result -ge 4 ]; then
rm -f _disk_image
USE_EXISTING=0
Expand Down Expand Up @@ -115,33 +122,39 @@ fi
printf "mounting filesystem... "
mkdir -p mnt
use_genext2fs=0
if [ "$(uname -s)" = "Darwin" ]; then
mount_cmd="fuse-ext2 _disk_image mnt -o rw+,allow_other,uid=501,gid=20"
if [ $USE_FUSE2FS -eq 1 ]; then
mount_cmd="/usr/sbin/fuse2fs _disk_image mnt/ -o fakeroot,rw"
elif [ "$(uname -s)" = "Darwin" ]; then
mount_cmd="fuse-ext2 _disk_image mnt -o rw+,allow_other,uid=501,gid=20"
elif [ "$(uname -s)" = "OpenBSD" ]; then
VND=$(vnconfig _disk_image)
mount_cmd="mount -t ext2fs "/dev/${VND}i" mnt/"
VND=$(vnconfig _disk_image)
mount_cmd="mount -t ext2fs "/dev/${VND}i" mnt/"
elif [ "$(uname -s)" = "FreeBSD" ]; then
MD=$(mdconfig _disk_image)
mount_cmd="fuse-ext2 -o rw+,direct_io "/dev/${MD}" mnt/"
MD=$(mdconfig _disk_image)
mount_cmd="fuse-ext2 -o rw+,direct_io "/dev/${MD}" mnt/"
else
mount_cmd="mount _disk_image mnt/"
mount_cmd="mount _disk_image mnt/"
fi
if ! eval "$mount_cmd"; then
if command -v genext2fs 1>/dev/null ; then
echo "mount failed but genext2fs exists, use it instead"
use_genext2fs=1
else
die "could not mount filesystem and genext2fs is missing"
fi
if command -v genext2fs 1>/dev/null ; then
echo "mount failed but genext2fs exists, use it instead"
use_genext2fs=1
else
die "could not mount filesystem and genext2fs is missing"
fi
else
echo "done"
echo "done"
fi

cleanup() {
if [ -d mnt ]; then
if [ $use_genext2fs = 0 ] ; then
printf "unmounting filesystem... "
umount mnt || ( sleep 1 && sync && umount mnt )
if [ $USE_FUSE2FS -eq 1 ]; then
fusermount -u mnt || (sleep 1 && sync && fusermount -u mnt)
else
umount mnt || ( sleep 1 && sync && umount mnt )
fi
rmdir mnt
else
rm -rf mnt
Expand Down
4 changes: 0 additions & 4 deletions Meta/build-root-filesystem.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ die() {
exit 1
}

if [ "$(id -u)" != 0 ]; then
die "this script needs to run as root"
fi

[ -z "$SERENITY_SOURCE_DIR" ] && die "SERENITY_SOURCE_DIR is not set"
[ -d "$SERENITY_SOURCE_DIR/Base" ] || die "$SERENITY_SOURCE_DIR/Base doesn't exist"

Expand Down