summaryrefslogtreecommitdiff
path: root/scripts/mkiso.sh
blob: cc1d4ecd3c63e5477ac99f27bdbc71bc062f96c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/sh

ISO_NAME="xilinux-$(date -u +%Y%m%d)"
ISO_LABEL="xilinux"
PUBLISHER="davidovski"
SYSLINUX_VER=6.04-pre1

XI_ARGS=""

chroot=/tmp/chroot
isoroot=/tmp/iso
iso_pkgs="linux linux-firmware base dracut grub bash xipkg squashfs-tools lvm2 cryptsetup networkmanager stty"

create_basesystem () {
    mkdir -p "$chroot"

    xi $XI_ARGS sync
    [ ! -d "$chroot" ] && xi -r "$chroot" bootstrap
    xi $XI_ARGS -r "$chroot" install "$iso_pkgs"

    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

    xichroot $SYSROOT passwd 

    xichroot "$chroot"
}

build_initramfs () {
    kernel_version=$(ls $chroot/usr/lib/modules | tail -1)
    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 /tmp -xf syslinux-$SYSLINUX_VER.tar.xz
    #cp syslinux-$SYSLINUX_VER
    cp /tmp/syslinux-$SYSLINUX_VER/bios/core/isolinux.bin $isoroot/isolinux/isolinux.bin
    cp /tmp/syslinux-$SYSLINUX_VER/bios/com32/elflink/ldlinux/ldlinux.c32 $isoroot/isolinux/ldlinux.c32
}

build_iso () {
    cat > $isoroot/isolinux/isolinux.cfg << EOF
default 1

label 1
    kernel /vmlinuz
    append initrd=/initrd.img splash console=tty0 console=ttyS0,9600 root=live:CDLABEL=xilinux rd.live.dir=/ rd.live.squashimg=filesystem.squashfs rd.live.debug=1



EOF

    mksquashfs $chroot $isoroot/filesystem.squashfs -noappend -no-progress -e "/proc/*" -e "/dev/*" -e "/sys/*"
    genisoimage -r -V "$ISO_LABEL" -cache-inodes -J -l \
        -allow-limited-size -udf \
        -b isolinux/isolinux.bin -c isolinux/boot.cat \
        -no-emul-boot -boot-load-size 4 -boot-info-table \
        -p "$PUBLISHER <xi@davidovski.xyz>" \
        -A "$ISO_LABEL" -o "$ISO_NAME.iso" $isoroot
}


[ "$#" = 0 ] && {
    create_basesystem
    build_initramfs
    create_isoroot
    install_syslinux
    build_iso
} || {
    for task in $*; do
        $task
    done
}