libdevuansdk

common library for devuan's simple distro kits
git clone https://git.parazyd.org/libdevuansdk
Log | Files | Refs | Submodules | README | LICENSE

iso (3613B)


      1 #!/usr/bin/env zsh
      2 # shellcheck shell=bash
      3 # Copyright (c) 2016-2021 Ivan J. <parazyd@dyne.org>
      4 # This file is part of libdevuansdk
      5 #
      6 # This source code is free software: you can redistribute it and/or modify
      7 # it under the terms of the GNU General Public License as published by
      8 # the Free Software Foundation, either version 3 of the License, or
      9 # (at your option) any later version.
     10 #
     11 # This software is distributed in the hope that it will be useful,
     12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14 # GNU General Public License for more details.
     15 #
     16 # You should have received a copy of the GNU General Public License
     17 # along with this source code. If not, see <http://www.gnu.org/licenses/>.
     18 
     19 vars+=(MKEFI)
     20 
     21 iso_prepare_strap()
     22 {
     23 	fn iso_prepare_strap
     24 	req=(strapdir)
     25 	ckreq || return 1
     26 
     27 	notice "Preparing strapdir for Live CD"
     28 
     29 	cat <<EOF | sudo tee "$strapdir/isoprep" >/dev/null
     30 #!/bin/sh
     31 apt-get update
     32 apt-get --yes --force-yes install dialog live-boot live-boot-initramfs-tools || exit 1
     33 apt-get --yes --force-yes --purge autoremove || exit 1
     34 EOF
     35 
     36 	chroot-script -d isoprep || { zerr; return 1; }
     37 }
     38 
     39 iso_setup_isolinux()
     40 {
     41 	fn iso_setup_isolinux
     42 	req=(workdir strapdir)
     43 	ckreq || return 1
     44 
     45 	notice "Setting up isolinux"
     46 
     47 	pushd "$workdir" || { zerr; return 1; }
     48 	sudo mkdir -p binary/{live,isolinux}
     49 	act "Copyring kernel and initrd"
     50 	sudo cp "$strapdir/boot/"vmlinuz* binary/live/vmlinuz || { zerr; return 1; }
     51 	sudo cp "$strapdir/boot/"initrd*  binary/live/initrd.img || { zerr; return 1; }
     52 	#sudo cp "$strapdir/boot/memtest86+.bin binary/live/memtest || { zerr; return 1; }
     53 
     54 	sudo cp "$R/extra/syslinux/isolinux.bin" binary/isolinux || { zerr; return 1; }
     55 	sudo cp "$R"/extra/syslinux/*.c32 binary/isolinux || { zerr; return 1; }
     56 	popd
     57 }
     58 
     59 iso_write_isolinux_cfg()
     60 {
     61 	fn iso_write_isolinux_cfg
     62 	req=(workdir arch os)
     63 	ckreq || return 1
     64 
     65 	notice "Writing isolinux configuration"
     66 
     67 	cat <<EOF | sudo tee "$workdir/binary/isolinux/isolinux.cfg" >/dev/null
     68 ui vesamenu.c32
     69 prompt 0
     70 menu title ${os} boot menu
     71 timeout 300
     72 
     73 label live-${arch}
     74 menu label ^${os} live (${arch})
     75 menu default
     76 linux /live/vmlinuz
     77 append initrd=/live/initrd.img boot=live
     78 
     79 endtext
     80 EOF
     81 }
     82 
     83 iso_squash_strap()
     84 {
     85 	fn iso_squash_strap
     86 	req=(workdir strapdir)
     87 	ckreq || return 1
     88 
     89 	notice "Creating squashfs out of strapdir"
     90 
     91 	case "$arch" in
     92 	amd64|i386)
     93 		_compfilt="-Xbcj x86"
     94 		;;
     95 	arm*)
     96 		_compfilt="-Xbcj arm"
     97 		;;
     98 	*)
     99 		_compfilt=""
    100 		;;
    101 	esac
    102 
    103 	pushd "$workdir" || { zerr; return 1; }
    104 	sudo mksquashfs "$strapdir" binary/live/filesystem.squashfs \
    105 		-comp xz ${=_compfilt} -noappend || { zerr; return 1; }
    106 	popd
    107 }
    108 
    109 iso_xorriso_build()
    110 {
    111 	fn iso_xorriso_build
    112 	req=(workdir image_name)
    113 	ckreq || return 1
    114 
    115 	notice "Building iso..."
    116 	isoname="${image_name}-live.iso"
    117 
    118 	if [[ -n "$MKEFI" ]]; then
    119 		uefi_opt="-eltorito-alt-boot -e boot/grub/efiboot.img -isohybrid-gpt-basdat -no-emul-boot"
    120 	fi
    121 
    122 	isohybrid="$R/extra/syslinux/isohdpfx.bin"
    123 
    124 	mkdir -p "$R/dist"
    125 	pushd "$workdir"
    126 	sudo xorriso -as mkisofs -r -J -joliet-long -l \
    127 		-isohybrid-mbr "$isohybrid" \
    128 		-partition_offset 16 \
    129 		-A "${os} Live - ${arch}" \
    130 		-b isolinux/isolinux.bin \
    131 		-c isolinux/boot.cat \
    132 		-no-emul-boot \
    133 		-boot-load-size 4 \
    134 		-boot-info-table \
    135 		${=uefi_opt} \
    136 		-o "$R/dist/$isoname" \
    137 		binary || { zerr; return 1; }
    138 	popd
    139 
    140 	act "Calculating sha256 checksums"
    141 	pushd "$R/dist" || { zerr; return 1; }
    142 	sha256sum "$isoname" > "${isoname}.sha256"
    143 	popd
    144 
    145 	if [[ "$DEBUG" = 1 ]]; then
    146 		return
    147 	fi
    148 
    149 	sudo rm -rf "$workdir"
    150 
    151 	notice "Done! Thanks for being patient!"
    152 }