From 11621e15b5dc2a9b4496db89e7adc3e8d0c37ca8 Mon Sep 17 00:00:00 2001 From: ading2210 Date: Thu, 21 Dec 2023 16:58:08 -0800 Subject: [PATCH] more build script improvements --- build_rootfs.sh | 5 +++-- build_squashfs.sh | 36 +++++++++++++++++++++++------------- shim_utils.sh | 2 +- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/build_rootfs.sh b/build_rootfs.sh index 915bf05..96886a8 100755 --- a/build_rootfs.sh +++ b/build_rootfs.sh @@ -8,7 +8,7 @@ if [ "$DEBUG" ]; then fi print_help() { - echo "Usage: ./build_rootfs.sh rootfs_path release_name" + echo "Usage: ./build_rootfs.sh rootfs_path release_name [custom_packages]" } check_deps() { @@ -40,6 +40,7 @@ fi rootfs_dir=$(realpath "${1}") release_name="${2}" +packages="${3-'task-xfce-desktop'}" debootstrap --arch amd64 $release_name $rootfs_dir http://deb.debian.org/debian/ cp -ar rootfs/* $rootfs_dir @@ -49,7 +50,7 @@ for mountpoint in $chroot_mounts; do mount --make-rslave --rbind "/${mountpoint}" "${rootfs_dir}/$mountpoint" done -chroot_command="DEBUG=${DEBUG} release_name=${release_name} /opt/setup_rootfs.sh" +chroot_command="DEBUG=${DEBUG} release_name=${release_name} packages=${packages} /opt/setup_rootfs.sh" chroot $rootfs_dir /bin/bash -c "${chroot_command}" for mountpoint in $chroot_mounts; do diff --git a/build_squashfs.sh b/build_squashfs.sh index c7fc630..dc0863c 100755 --- a/build_squashfs.sh +++ b/build_squashfs.sh @@ -46,34 +46,44 @@ compile_unionfs() { } rootfs_dir=$(realpath $1) -target_dir=$(realpath $2) +old_dir=$(realpath $2) shim_path=$(realpath $3) shim_rootfs="/tmp/shim_rootfs" -modules_squashfs="/tmp/modules.squashfs" +root_squashfs="$rootfs_dir/root.squashfs" +modules_squashfs="$rootfs_dir/modules.squashfs" kernel_dir=/tmp/shim_kernel -initramfs_dir=/tmp/shim_initramfs +unionfs_dir="/tmp/unionfs-fuse" echo "compiling unionfs-fuse" -compile_unionfs /tmp/unionfs /tmp/unionfs-fuse +compile_unionfs $unionfs_dir/unionfs $unionfs_dir -echo "mounting shim" +echo "creating loop device for shim" shim_loop=$(create_loop "${shim_path}") -make_mountable "${shim_loop}p3" -safe_mount "${shim_loop}p3" $shim_rootfs - -echo "extracting modules from shim" -extract_modules $modules_squashfs $shim_rootfs +kernel_loop="${shim_loop}p2" #KERN-A should always be p2 echo "copying shim kernel" +rm -rf $kernel_dir mkdir $kernel_dir -p -kernel_loop="${shim_loop}p2" -dd if=$kernel_loop of=$kernel_dir/kernel.bin bs=1M status=none +dd if=$kernel_loop of=$kernel_dir/kernel.bin bs=1M status=progress echo "extracting initramfs from kernel" extract_initramfs $kernel_dir/kernel.bin $kernel_dir $rootfs_dir +rm -rf $rootfs_dir/init -#todo... +echo "mounting shim" +make_mountable "${shim_loop}p3" +safe_mount "${shim_loop}p3" $shim_rootfs + +echo "extracting and compressing modules from shim" +extract_modules $modules_squashfs $shim_rootfs + +echo "compressing old rootfs" +mksquashfs $old_dir $root_squashfs -noappend -comp gzip + +echo "patching new rootfs" +mv $unionfs_dir/unionfs $rootfs_dir/bin/unionfs +#cp -ar ./squashfs/* $rootfs_dir/ echo "cleaning up" umount $shim_rootfs diff --git a/shim_utils.sh b/shim_utils.sh index 704e27b..fe83aad 100755 --- a/shim_utils.sh +++ b/shim_utils.sh @@ -15,7 +15,7 @@ extract_initramfs() { local stage1_path="$stage1_dir/$stage1_file" #second stage - binwalk --extract $stage1_path --directory=$stage1_dir --run-as=root + binwalk --extract $stage1_path --directory=$stage1_dir --run-as=root > /dev/null local stage2_dir="$stage1_dir/_$stage1_file.extracted/" local cpio_file=$(file $stage2_dir/* | pcregrep -o1 "([0-9A-F]+):\s+ASCII cpio archive") local cpio_path="$stage2_dir/$cpio_file"