#!/bin/bash
echo not a script
exit 1

# notes on modifying squashfs images,
# including the ones which contain filesystem images as files
#
# perform any necessary mkdir's as you go


# to modify a squashfs, first extract it somewhere
mount some.squashfs /mnt/sq-src
rm -rf /mnt/sq-mod
cp -ar /mnt/sq-{src,mod}
umount /mnt/sq-src

##
## if the squashfs contains a filesystem image:

    # mount it like a regular disk to modify it
    mount /mnt/sq-mod/some.img /mnt/sq-fs

    # make the changes, then trim and unmount
    fstrim -v /mnt/sq-fs
    umount /mnt/sq-fs

    ##
    ## but you may save additional space by recreating the filesystem image:

        # mount the original image read-only
        mount -r /mnt/sq-mod/some.img /mnt/sq-fs

        # first create a 1GB sparse file for the new filesystem image
        dd if=/dev/zero of=/mnt/sq-mod/new.img bs=1 count=0 seek=1024M

        # if you can use ext2/ext3/ext4, you can build it like this:
        mkfs.ext4 -d /mnt/sq-fs -b 1024 -m 1 -O ^metadata_csum /mnt/sq-mod/new.img

        # or if the mkfs of your filesystem doesn't support building from a folder,
        mkfs.xfs -b size=1024 -m crc=0 /mnt/sq-mod/new.img
        mount /mnt/sq-mod/new.img /mnt/sq-fs2
        rsync -SWaxHAX /mnt/sq-fs{,2}/
        umount /mnt/sq-fs2

        # at any rate, unmount the original image and replace it with the new one
        umount /mnt/sq-fs
        mv /mnt/sq-mod/{new,some}.img

    # end-if

# end-if

# finally repack the squashfs after making the changes
mksquashfs /mnt/sq-mod new.squashfs -b 1M -comp xz -Xdict-size 100% -Xbcj x86
mv {new,some}.squashfs
