system

the Chamesle handbook, init, live ISO and install helpers
git clone https://github.com/tortr-rs/system
Log | Files | Refs | README | LICENSE

mkiso (3013B)


      1 #!/bin/sh
      2 # mkiso: the Chamesle live ISO, with mag putting chamesle-base, the kernel and profile/packages in its root.
      3 #   mkiso -o chamesle.iso
      4 #   mkiso -a x86 -o chamesle-x86.iso
      5 # MAG is the mag to build with (default: the one in PATH), REPOS a repos file to build from instead of chamesle-base's
      6 set -e
      7 here=$(cd "$(dirname "$0")" && pwd)
      8 profile=$here/profile
      9 work=$PWD/work
     10 out=chamesle.iso
     11 arch=x86_64
     12 while getopts a:p:w:o: o; do
     13 	case $o in
     14 	a) arch=$OPTARG;;
     15 	p) profile=$OPTARG;;
     16 	w) work=$OPTARG;;
     17 	o) out=$OPTARG;;
     18 	*) echo "usage: mkiso [-a arch] [-p profile] [-w workdir] [-o out.iso]" >&2; exit 2;;
     19 	esac
     20 done
     21 : "${MKISOFS:=xorriso -as mkisofs}"
     22 die() { echo "mkiso: $*" >&2; exit 1; }
     23 [ "$(id -u)" = 0 ] || die "run it as root, the files of the image belong to root"
     24 [ -n "$MAG" ] || MAG=$(command -v mag) || die "no mag: put it in PATH or set MAG"
     25 for t in mksquashfs ${MKISOFS%% *} zstd bsdcpio; do command -v $t >/dev/null || die "$t is not installed"; done
     26 
     27 iso=$work/iso rootfs=$work/rootfs
     28 rm -rf "$iso" "$rootfs"
     29 mkdir -p "$iso/boot/limine" "$iso/EFI/BOOT" "$iso/LiveOS" "$rootfs/etc/mag"
     30 cp "${REPOS:-$here/../pkg/chamesle-base/repos}" "$rootfs/etc/mag/repos"
     31 cp -R "$here/../keys" "$rootfs/etc/mag/keys"
     32 echo "$arch" > "$rootfs/etc/mag/arch"
     33 # CACHE is a directory to keep the downloaded packages in between builds
     34 [ -z "$CACHE" ] || { mkdir -p "$CACHE" "$rootfs/var/cache/mag"; cp -R "$CACHE" "$rootfs/var/cache/mag/pkg"; }
     35 MAG_ROOT=$rootfs "$MAG" update
     36 MAG_ROOT=$rootfs "$MAG" install chamesle-base linux-lts $(grep -v '^#' "$profile/packages")
     37 [ -z "$CACHE" ] || cp "$rootfs"/var/cache/mag/pkg/* "$CACHE/"
     38 cp "$here/../pkg/chamesle-base/repos" "$rootfs/etc/mag/repos"
     39 tar -C "$profile/overlay" -cf - . | tar -C "$rootfs" -xf -
     40 rm -rf "$rootfs"/var/cache/mag/pkg "$rootfs"/var/tmp/mag "$rootfs"/boot/initramfs-*
     41 
     42 kver=$(ls "$rootfs/lib/modules" | head -n 1)
     43 [ -f "$rootfs/boot/vmlinuz-lts" ] && [ -n "$kver" ] || die "no kernel in the root"
     44 cp "$rootfs/boot/vmlinuz-lts" "$iso/boot/vmlinuz"
     45 "$here/mkinitramfs" -m "$profile/modules" "$rootfs" "$kver" "$iso/boot/initrd"
     46 
     47 mksquashfs "$rootfs" "$iso/LiveOS/rootfs.sfs" -comp zstd -Xcompression-level 19 -b 256K -noappend -no-progress >/dev/null
     48 
     49 LIMINE=$rootfs/usr/share/limine
     50 cp "$LIMINE"/limine-bios.sys "$LIMINE"/limine-bios-cd.bin "$LIMINE"/limine-uefi-cd.bin "$iso/boot/limine/"
     51 cp "$LIMINE"/BOOTX64.EFI "$iso/EFI/BOOT/"
     52 cp "$profile/limine.conf" "$iso/boot/limine/limine.conf"
     53 
     54 $MKISOFS -R -r -J -V CHAMESLE \
     55 	-b boot/limine/limine-bios-cd.bin -no-emul-boot -boot-load-size 4 -boot-info-table \
     56 	--efi-boot boot/limine/limine-uefi-cd.bin -efi-boot-part --efi-boot-image --protective-msdos-label \
     57 	-o "$out" "$iso" >/dev/null 2>&1 || die "$MKISOFS failed"
     58 # the root's limine, so its stages match the limine-bios.sys on the ISO, run with the root's own musl
     59 "$rootfs"/lib/ld-musl-*.so.1 --library-path "$rootfs/lib:$rootfs/usr/lib" "$rootfs/usr/bin/limine" bios-install "$out" >/dev/null
     60 echo "$out: $(du -h "$out" | cut -f1)"