#!/bin/sh ISO_NAME="xilinux-$(date -u +%Y%m%d)" ISO_LABEL="XILINUX" PUBLISHER="davidovski" SYSLINUX_VER=6.04-pre1 TO_MIRROR="file:///var/lib/xib/repo" XI_ARGS="-yq" WORKDIR=/tmp/xiiso chroot=$WORKDIR/chroot isoroot=$WORKDIR/iso iso_pkgs="linux linux-firmware base dracut grub mksh xipkg squashfs-tools lvm2 cryptsetup networkmanager stty xitui neofetch vim nano gnupg dosfstools" cmdline="splash console=tty0 console=ttyS0,9600 root=live:CDLABEL=$ISO_LABEL rd.live.dir=/ rd.live.squashimg=filesystem.squashfs rd.live.debug=1 quiet" grub_mod="all_video disk part_gpt part_msdos linux normal configfile search search_label efi_gop fat iso9660 cat echo ls test true help gzio" mkdir -p $WORKDIR create_basesystem () { mkdir -p $chroot xipkg $XI_ARGS sync xipkg $XI_ARGS -r "$chroot" bootstrap xipkg $XI_ARGS -r "$chroot" install "$iso_pkgs" } configure_system() { cat > $chroot/etc/resolv.conf << EOF nameserver 80.80.80.80 EOF hostname=xilinux echo xilinux > $chroot/etc/hostname cat > $chroot/etc/hosts << EOF 127.0.0.1 localhost ::1 localhost 127.0.1.1 $hostname.local $hostname EOF cp -r ./root $chroot/ cat > $chroot/etc/conf.d/agetty << EOF agetty_options="--autologin root --noclear" EOF xichroot $chroot rc-update add networkmanager [ -d "$chroot/var/lib/xipkg/mirror" ] && rm -rf "$chroot/var/lib/xipkg/mirror" return 0 } build_initramfs () { kernel_version=$(ls $chroot/usr/lib/modules | tail -1) export kernel_version mkdir -p "$chroot"/var/tmp xichroot "$chroot" dracut --nomdadmconf --nolvmconf --xz --add dmsquash-live --add bash --add convertfs --add pollcdrom --force --kver $kernel_version } create_isoroot() { mkdir -p $isoroot/ cp $chroot/boot/vmlinuz-** $isoroot/vmlinuz cp $chroot/boot/initramfs-** $isoroot/initrd.img mkdir -p $isoroot/isolinux } install_syslinux () { curl https://mirrors.edge.kernel.org/pub/linux/utils/boot/syslinux/Testing/$(echo $SYSLINUX_VER | cut -d'-' -f1)/syslinux-$SYSLINUX_VER.tar.xz > syslinux-$SYSLINUX_VER.tar.xz tar -C $WORKDIR -xf syslinux-$SYSLINUX_VER.tar.xz #cp syslinux-$SYSLINUX_VER cp $WORKDIR/syslinux-$SYSLINUX_VER/bios/core/isolinux.bin $isoroot/isolinux/isolinux.bin cp $WORKDIR/syslinux-$SYSLINUX_VER/bios/com32/elflink/ldlinux/ldlinux.c32 $isoroot/isolinux/ldlinux.c32 cat > $isoroot/isolinux/isolinux.cfg << EOF default 1 label 1 kernel /vmlinuz append initrd=/initrd.img $cmdline EOF } build_grub_efi () { mkdir -p $isoroot/boot/grub cat > $isoroot/boot/grub/grub.cfg << EOF set timeout_style=hidden set timeout=0 menuentry "XiLinux" { linux /vmlinuz $cmdline initrd /initrd.img } EOF cksum=$(md5sum $isoroot/boot/grub/grub.cfg | cut -d' ' -f1) mkdir -p $isoroot/efi/boot cat > $WORKDIR/grub_early.$cksum.cfg << EOF search --no-floppy --set=root --label "$ISO_LABEL" set prefix=(\$root)/boot/grub EOF grub-mkimage \ --config="$WORKDIR/grub_early.$cksum.cfg" \ --prefix="/boot/grub" \ --output="$isoroot/efi/boot/bootx64.efi" \ --format="x86_64-efi" \ --compression="xz" \ $grub_mod mformat -i $isoroot/boot/grub/efi.img -C -f 1440 -N 0 :: mcopy -i $isoroot/boot/grub/efi.img -s $isoroot/efi :: } build_iso () { local name=${1:-netinst} mksquashfs $chroot $isoroot/filesystem.squashfs -noappend -no-progress -wildcards -e 'proc/*' 'dev/*' 'sys/*' xorrisofs -output ${ISO_NAME}-${name}.iso \ -joliet \ -rational-rock \ -sysid LINUX \ -volid "$ISO_LABEL" \ -eltorito-boot isolinux/isolinux.bin \ -eltorito-catalog isolinux/boot.cat \ -no-emul-boot \ -boot-load-size 4 \ -boot-info-table \ -eltorito-alt-boot \ -e boot/grub/efi.img \ -no-emul-boot \ -isohybrid-gpt-basdat \ -follow-links \ $isoroot printf "ISO written to $name.iso\n" } create_full_iso () { xipkg $XI_ARGS -r $chroot mirror cat > $chroot/etc/xipkg.conf << EOF include /etc/xipkg.d/default.conf sources { local file:///var/lib/xipkg/mirror/ } default_cmd install EOF build_iso "full" } [ "$#" = 0 ] && { steps=" create_basesystem configure_system build_initramfs create_isoroot install_syslinux build_grub_efi build_iso create_full_iso " } || { steps="$*" } for step in $steps; do $step || { printf "%s\n" "${RED}An error occured!" exit 1 } done