more build script improvements

This commit is contained in:
ading2210 2023-12-21 16:58:08 -08:00
parent e399ef002e
commit 11621e15b5
3 changed files with 27 additions and 16 deletions

View File

@ -8,7 +8,7 @@ if [ "$DEBUG" ]; then
fi fi
print_help() { print_help() {
echo "Usage: ./build_rootfs.sh rootfs_path release_name" echo "Usage: ./build_rootfs.sh rootfs_path release_name [custom_packages]"
} }
check_deps() { check_deps() {
@ -40,6 +40,7 @@ fi
rootfs_dir=$(realpath "${1}") rootfs_dir=$(realpath "${1}")
release_name="${2}" release_name="${2}"
packages="${3-'task-xfce-desktop'}"
debootstrap --arch amd64 $release_name $rootfs_dir http://deb.debian.org/debian/ debootstrap --arch amd64 $release_name $rootfs_dir http://deb.debian.org/debian/
cp -ar rootfs/* $rootfs_dir cp -ar rootfs/* $rootfs_dir
@ -49,7 +50,7 @@ for mountpoint in $chroot_mounts; do
mount --make-rslave --rbind "/${mountpoint}" "${rootfs_dir}/$mountpoint" mount --make-rslave --rbind "/${mountpoint}" "${rootfs_dir}/$mountpoint"
done 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}" chroot $rootfs_dir /bin/bash -c "${chroot_command}"
for mountpoint in $chroot_mounts; do for mountpoint in $chroot_mounts; do

View File

@ -46,34 +46,44 @@ compile_unionfs() {
} }
rootfs_dir=$(realpath $1) rootfs_dir=$(realpath $1)
target_dir=$(realpath $2) old_dir=$(realpath $2)
shim_path=$(realpath $3) shim_path=$(realpath $3)
shim_rootfs="/tmp/shim_rootfs" 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 kernel_dir=/tmp/shim_kernel
initramfs_dir=/tmp/shim_initramfs unionfs_dir="/tmp/unionfs-fuse"
echo "compiling 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}") shim_loop=$(create_loop "${shim_path}")
make_mountable "${shim_loop}p3" kernel_loop="${shim_loop}p2" #KERN-A should always be p2
safe_mount "${shim_loop}p3" $shim_rootfs
echo "extracting modules from shim"
extract_modules $modules_squashfs $shim_rootfs
echo "copying shim kernel" echo "copying shim kernel"
rm -rf $kernel_dir
mkdir $kernel_dir -p mkdir $kernel_dir -p
kernel_loop="${shim_loop}p2" dd if=$kernel_loop of=$kernel_dir/kernel.bin bs=1M status=progress
dd if=$kernel_loop of=$kernel_dir/kernel.bin bs=1M status=none
echo "extracting initramfs from kernel" echo "extracting initramfs from kernel"
extract_initramfs $kernel_dir/kernel.bin $kernel_dir $rootfs_dir 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" echo "cleaning up"
umount $shim_rootfs umount $shim_rootfs

View File

@ -15,7 +15,7 @@ extract_initramfs() {
local stage1_path="$stage1_dir/$stage1_file" local stage1_path="$stage1_dir/$stage1_file"
#second stage #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 stage2_dir="$stage1_dir/_$stage1_file.extracted/"
local cpio_file=$(file $stage2_dir/* | pcregrep -o1 "([0-9A-F]+):\s+ASCII cpio archive") local cpio_file=$(file $stage2_dir/* | pcregrep -o1 "([0-9A-F]+):\s+ASCII cpio archive")
local cpio_path="$stage2_dir/$cpio_file" local cpio_path="$stage2_dir/$cpio_file"