Skip to content
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

Fixed no output folder issue #772

Closed
wants to merge 1 commit into from
Closed
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
100 changes: 44 additions & 56 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,6 @@ vhdx_to_raw_img() {
rm -f "$1" || return 1
}

check_image_type() {
local type
type=$(blkid -o value -s TYPE "$1")
echo "$type"
}

mk_overlayfs() { # label lowerdir upperdir merged
local context own
local workdir="$WORK_DIR/worker/$1"
Expand Down Expand Up @@ -198,17 +192,12 @@ mk_overlayfs() { # label lowerdir upperdir merged
sudo mount -vt overlay overlay -olowerdir="$lowerdir",upperdir="$upperdir",workdir="$workdir" "$merged" || return 1
}

mk_image_umount() { # dir imgpath upperdir imgtype
echo "mk_image_umount: $*"
if [ "$4" = "erofs" ]; then
sudo "../bin/$HOST_ARCH/mkfs.erofs" -zlz4hc -T1230768000 --chunksize=4096 --exclude-regex="lost+found" "$2"."$4" "$1" || abort "Failed to make image for $1"
elif [ "$4" = "ext4" ]; then
abort "Not yet implemented"
fi
mk_erofs_umount() { # dir imgpath upperdir
sudo "../bin/$HOST_ARCH/mkfs.erofs" -zlz4hc -T1230768000 --chunksize=4096 --exclude-regex="lost+found" "$2".erofs "$1" || abort "Failed to make erofs image from $1"
sudo umount -v "$1"
sudo rm -f "$2"
sudo mv "$2"."$4" "$2"
if [ -d "$3" ]; then
sudo mv "$2".erofs "$2"
if [ "$3" ]; then
sudo rm -rf "$3"
fi
}
Expand Down Expand Up @@ -496,7 +485,7 @@ update_ksu_zip_name() {
"2306") KERNEL_VER="5.15.104.1";;
"2307") KERNEL_VER="5.15.104.2";;
"2308") KERNEL_VER="5.15.104.3";;
"2309") KERNEL_VER="5.15.104.4";;
"2309"|"2310"|"2311") KERNEL_VER="5.15.104.4";;
*) abort "KernelSU is not supported in this WSA version: $WSA_MAJOR_VER"
esac
KERNELSU_ZIP_NAME=kernelsu-$ARCH-$KERNEL_VER.zip
Expand Down Expand Up @@ -654,40 +643,38 @@ if [ "$GAPPS_BRAND" != 'none' ]; then
echo -e "Extract done\n"
fi

if [ -f "$WORK_DIR/wsa/$ARCH/system.vhdx" ]; then
VM_IMAGES_USE_VHDX=1
echo "Convert vhdx to RAW image"
vhdx_to_raw_img "$WORK_DIR/wsa/$ARCH/system_ext.vhdx" "$WORK_DIR/wsa/$ARCH/system_ext.img" || abort
vhdx_to_raw_img "$WORK_DIR/wsa/$ARCH/product.vhdx" "$WORK_DIR/wsa/$ARCH/product.img" || abort
vhdx_to_raw_img "$WORK_DIR/wsa/$ARCH/system.vhdx" "$WORK_DIR/wsa/$ARCH/system.img" || abort
vhdx_to_raw_img "$WORK_DIR/wsa/$ARCH/vendor.vhdx" "$WORK_DIR/wsa/$ARCH/vendor.img" || abort
echo -e "Convert vhdx to RAW image done\n"
SYSTEMIMAGES_FILE_SYSTEM_TYPE=$(check_image_type "$WORK_DIR/wsa/$ARCH/system.img")
echo "Convert vhdx to RAW image"
vhdx_to_raw_img "$WORK_DIR/wsa/$ARCH/system_ext.vhdx" "$WORK_DIR/wsa/$ARCH/system_ext.img" || abort
vhdx_to_raw_img "$WORK_DIR/wsa/$ARCH/product.vhdx" "$WORK_DIR/wsa/$ARCH/product.img" || abort
vhdx_to_raw_img "$WORK_DIR/wsa/$ARCH/system.vhdx" "$WORK_DIR/wsa/$ARCH/system.img" || abort
vhdx_to_raw_img "$WORK_DIR/wsa/$ARCH/vendor.vhdx" "$WORK_DIR/wsa/$ARCH/vendor.img" || abort
echo -e "Convert vhdx to RAW image done\n"

SYSTEM_IMAGE_TYPE=$(blkid -o value -s TYPE "$WORK_DIR/wsa/$ARCH/system.img")
if [[ "$SYSTEM_IMAGE_TYPE" = "erofs" ]]; then
echo "Mount images"
sudo mkdir -p -m 755 "$ROOT_MNT_RO" || abort
sudo chown "0:0" "$ROOT_MNT_RO" || abort
sudo setfattr -n security.selinux -v "u:object_r:rootfs:s0" "$ROOT_MNT_RO" || abort
if [ "$SYSTEMIMAGES_FILE_SYSTEM_TYPE" = "ext4" ]; then
sudo mount -vo loop,ro "$WORK_DIR/wsa/$ARCH/system.img" "$ROOT_MNT_RO" || abort
sudo mount -vo loop,ro "$WORK_DIR/wsa/$ARCH/vendor.img" "$VENDOR_MNT_RO" || abort
sudo mount -vo loop,ro "$WORK_DIR/wsa/$ARCH/product.img" "$PRODUCT_MNT_RO" || abort
sudo mount -vo loop,ro "$WORK_DIR/wsa/$ARCH/system_ext.img" "$SYSTEM_EXT_MNT_RO" || abort
elif [ "$SYSTEMIMAGES_FILE_SYSTEM_TYPE" = "erofs" ]; then
mount_erofs "$WORK_DIR/wsa/$ARCH/system.img" "$ROOT_MNT_RO" || abort
mount_erofs "$WORK_DIR/wsa/$ARCH/vendor.img" "$VENDOR_MNT_RO" || abort
mount_erofs "$WORK_DIR/wsa/$ARCH/product.img" "$PRODUCT_MNT_RO" || abort
mount_erofs "$WORK_DIR/wsa/$ARCH/system_ext.img" "$SYSTEM_EXT_MNT_RO" || abort
else
abort "Unknown file system type: $SYSTEMIMAGES_FILE_SYSTEM_TYPE"
fi
mount_erofs "$WORK_DIR/wsa/$ARCH/system.img" "$ROOT_MNT_RO" || abort
mount_erofs "$WORK_DIR/wsa/$ARCH/vendor.img" "$VENDOR_MNT_RO" || abort
mount_erofs "$WORK_DIR/wsa/$ARCH/product.img" "$PRODUCT_MNT_RO" || abort
mount_erofs "$WORK_DIR/wsa/$ARCH/system_ext.img" "$SYSTEM_EXT_MNT_RO" || abort
echo -e "done\n"
echo "Create overlayfs"
echo "Create overlayfs for EROFS"
mk_overlayfs system "$ROOT_MNT_RO" "$SYSTEM_MNT_RW" "$ROOT_MNT" || abort
mk_overlayfs vendor "$VENDOR_MNT_RO" "$VENDOR_MNT_RW" "$VENDOR_MNT" || abort
mk_overlayfs product "$PRODUCT_MNT_RO" "$PRODUCT_MNT_RW" "$PRODUCT_MNT" || abort
mk_overlayfs system_ext "$SYSTEM_EXT_MNT_RO" "$SYSTEM_EXT_MNT_RW" "$SYSTEM_EXT_MNT" || abort
echo -e "Create overlayfs done\n"
else
echo -e "Create overlayfs for EROFS done\n"
elif [[ "$SYSTEM_IMAGE_TYPE" = "ext4" ]]; then
echo "Remove read-only flag for read-only EXT4 image"
ro_ext4_img_to_rw "$WORK_DIR/wsa/$ARCH/system_ext.img" || abort
ro_ext4_img_to_rw "$WORK_DIR/wsa/$ARCH/product.img" || abort
ro_ext4_img_to_rw "$WORK_DIR/wsa/$ARCH/system.img" || abort
ro_ext4_img_to_rw "$WORK_DIR/wsa/$ARCH/vendor.img" || abort
echo -e "Remove read-only flag for read-only EXT4 image done\n"

echo "Calculate the required space"
EXTRA_SIZE=10240

Expand Down Expand Up @@ -921,27 +908,20 @@ if [ "$GAPPS_BRAND" != 'none' ]; then
fi
fi

if [ "$VM_IMAGES_USE_VHDX" ]; then
echo "Create system images"
mk_image_umount "$VENDOR_MNT" "$WORK_DIR/wsa/$ARCH/vendor.img" "$VENDOR_MNT_RW" "$SYSTEMIMAGES_FILE_SYSTEM_TYPE" || abort
mk_image_umount "$PRODUCT_MNT" "$WORK_DIR/wsa/$ARCH/product.img" "$PRODUCT_MNT_RW" "$SYSTEMIMAGES_FILE_SYSTEM_TYPE" || abort
mk_image_umount "$SYSTEM_EXT_MNT" "$WORK_DIR/wsa/$ARCH/system_ext.img" "$SYSTEM_EXT_MNT_RW" "$SYSTEMIMAGES_FILE_SYSTEM_TYPE" || abort
mk_image_umount "$ROOT_MNT" "$WORK_DIR/wsa/$ARCH/system.img" "$SYSTEM_MNT_RW" "$SYSTEMIMAGES_FILE_SYSTEM_TYPE" || abort
echo -e "Create system images done\n"
if [[ "$SYSTEM_IMAGE_TYPE" = "erofs" ]]; then
echo "Create EROFS images"
mk_erofs_umount "$VENDOR_MNT" "$WORK_DIR/wsa/$ARCH/vendor.img" "$VENDOR_MNT_RW" || abort
mk_erofs_umount "$PRODUCT_MNT" "$WORK_DIR/wsa/$ARCH/product.img" "$PRODUCT_MNT_RW" || abort
mk_erofs_umount "$SYSTEM_EXT_MNT" "$WORK_DIR/wsa/$ARCH/system_ext.img" "$SYSTEM_EXT_MNT_RW" || abort
mk_erofs_umount "$ROOT_MNT" "$WORK_DIR/wsa/$ARCH/system.img" || abort
echo -e "Create EROFS images done\n"
echo "Umount images"
sudo umount -v "$VENDOR_MNT_RO"
sudo umount -v "$PRODUCT_MNT_RO"
sudo umount -v "$SYSTEM_EXT_MNT_RO"
sudo umount -v "$ROOT_MNT_RO"
echo -e "done\n"
echo "Convert images to vhdx"
qemu-img convert -q -f raw -o subformat=fixed -O vhdx "$WORK_DIR/wsa/$ARCH/system_ext.img" "$WORK_DIR/wsa/$ARCH/system_ext.vhdx" || abort
qemu-img convert -q -f raw -o subformat=fixed -O vhdx "$WORK_DIR/wsa/$ARCH/product.img" "$WORK_DIR/wsa/$ARCH/product.vhdx" || abort
qemu-img convert -q -f raw -o subformat=fixed -O vhdx "$WORK_DIR/wsa/$ARCH/system.img" "$WORK_DIR/wsa/$ARCH/system.vhdx" || abort
qemu-img convert -q -f raw -o subformat=fixed -O vhdx "$WORK_DIR/wsa/$ARCH/vendor.img" "$WORK_DIR/wsa/$ARCH/vendor.vhdx" || abort
rm -f "$WORK_DIR/wsa/$ARCH/"*.img || abort
echo -e "Convert images to vhdx done\n"
else
elif [[ "$SYSTEM_IMAGE_TYPE" = "ext4" ]]; then
echo "Umount images"
sudo find "$ROOT_MNT" -exec touch -ht 200901010000.00 {} \;
sudo umount -v "$VENDOR_MNT"
Expand All @@ -957,6 +937,14 @@ else
echo -e "Shrink images done\n"
fi

echo "Convert images to vhdx"
qemu-img convert -q -f raw -o subformat=fixed -O vhdx "$WORK_DIR/wsa/$ARCH/system_ext.img" "$WORK_DIR/wsa/$ARCH/system_ext.vhdx" || abort
qemu-img convert -q -f raw -o subformat=fixed -O vhdx "$WORK_DIR/wsa/$ARCH/product.img" "$WORK_DIR/wsa/$ARCH/product.vhdx" || abort
qemu-img convert -q -f raw -o subformat=fixed -O vhdx "$WORK_DIR/wsa/$ARCH/system.img" "$WORK_DIR/wsa/$ARCH/system.vhdx" || abort
qemu-img convert -q -f raw -o subformat=fixed -O vhdx "$WORK_DIR/wsa/$ARCH/vendor.img" "$WORK_DIR/wsa/$ARCH/vendor.vhdx" || abort
rm -f "$WORK_DIR/wsa/$ARCH/"*.img || abort
echo -e "Convert images to vhdx done\n"

echo "Remove signature and add scripts"
sudo rm -rf "${WORK_DIR:?}"/wsa/"$ARCH"/\[Content_Types\].xml "$WORK_DIR/wsa/$ARCH/AppxBlockMap.xml" "$WORK_DIR/wsa/$ARCH/AppxSignature.p7x" "$WORK_DIR/wsa/$ARCH/AppxMetadata" || abort
cp "$vclibs_PATH" "$xaml_PATH" "$WORK_DIR/wsa/$ARCH" || abort
Expand Down