+++ /dev/null
-#!/bin/bash
-
-set -eu
-
-PARTITION_LABEL="multiboot"
-MULTIBOOT_MNT="/mnt/multiboot"
-
-function cmd_format {
- if [ ! -b "${1:-}" ]; then
- echo "Usage: $0 format /dev/sdX"
- exit 1
- fi
- set -x
-
- sudo -k
- DISK_DEVICE="$1"
- PARTITION_DEVICE="${DISK_DEVICE}1"
- echo -ne 'label: dos\ntype=c, bootable\n' | sudo sfdisk "$DISK_DEVICE"
- sudo mkfs.vfat -n "$PARTITION_LABEL" "$PARTITION_DEVICE"
-}
-
-function cmd_grub {
- DISK_DEVICE="$(findmnt -n -o source "$MULTIBOOT_MNT" | sed 's/[0-9]*$//')"
- if [ ! -b "$DISK_DEVICE" ]; then
- echo "ERROR! Could not find disk to install bootloader. Try using mount."
- exit 1
- fi
- set -x
-
- sudo -k
- install_grub_bios
- install_grub_efi
- install_grub_cfg
-}
-
-function cmd_grubcfg {
- set -x
- install_grub_cfg
-}
-
-function install_grub_bios {
- sudo grub-install \
- --target=i386-pc \
- --boot-directory="$MULTIBOOT_MNT" \
- "$DISK_DEVICE"
-}
-
-function install_grub_efi {
- for arch in i386-efi x86_64-efi; do
- sudo grub-install \
- --target="$arch" \
- --no-nvram \
- --removable \
- --efi-directory="$MULTIBOOT_MNT" \
- --boot-directory="$MULTIBOOT_MNT" \
- "$DISK_DEVICE"
- done
-}
-
-function install_grub_cfg {
- print_grub_cfg | sudo tee "${MULTIBOOT_MNT}/grub/grub.cfg" > /dev/null
-}
-
-function cmd_mount {
- set -x
-
- PARTITION_DEVICE="$(readlink -f "/dev/disk/by-label/${PARTITION_LABEL}")"
- sudo mkdir -p "$MULTIBOOT_MNT"
- while sudo umount "$PARTITION_DEVICE" &> /dev/null; do true; done
- sudo mount "$PARTITION_DEVICE" "$MULTIBOOT_MNT" -o "uid=$(whoami)"
-}
-
-function cmd_umount {
- set -x
-
- sudo umount "$MULTIBOOT_MNT"
- sudo rmdir "$MULTIBOOT_MNT"
-}
-
-function cmd_freedos {
- set -x
-
- local SYSLINUX_VERSION="6.03"
- local SYSLINUX_URL="https://www.kernel.org/pub/linux/utils/boot/syslinux/syslinux-${SYSLINUX_VERSION}.tar.gz"
- local FREEDOS_URL="http://www.freedos.org/download/download/FD12LITE.zip"
-
- curl -fL "$SYSLINUX_URL" | \
- tar xz --no-same-owner --strip-components=3 -C "$MULTIBOOT_MNT" \
- "syslinux-${SYSLINUX_VERSION}/bios/memdisk/memdisk"
-
- curl -fL "$FREEDOS_URL" > "${MULTIBOOT_MNT}/FD12LITE.zip"
-}
-
-function cmd_memtest {
- curl -fL "https://www.memtest.org/download/5.01/memtest86+-5.01.bin.gz" | \
- zcat - > "${MULTIBOOT_MNT}/memtest.bin"
-}
-
-function print_grub_cfg {
- cat <<EOT
-insmod all_video
-insmod part_msdos
-insmod progress
-insmod regexp
-search --set=root --label $PARTITION_LABEL
-
-function setup_arch {
- menuentry "\$1" {
- loopback loop \$1
- linux (loop)/arch/boot/x86_64/vmlinuz img_label=${PARTITION_LABEL} img_loop=\$1 archisobasedir=arch earlymodules=loop
- initrd (loop)/arch/boot/x86_64/archiso.img
- }
-}
-for iso in /archlinux-*.iso; do
- if [ -f "\$iso" ]; then
- setup_arch \$iso
- fi
-done
-
-function setup_debian {
- menuentry "\$1" {
- linux \$1/vmlinuz
- initrd \$1/initrd.gz
- }
-}
-for d in /debian-*-hd-media; do
- if [ -d "\$d" ]; then
- setup_debian \$d
- fi
-done
-
-if [ -f /memdisk -a -f /FD12LITE.zip ]; then
- menuentry /FD12LITE.zip {
- if [ \${grub_platform} = pc ]; then
- linux16 /memdisk raw
- initrd16 /FD12LITE.zip
- else
- echo "FreeDOS only works with BIOS boot."
- sleep 3
- fi
- }
-fi
-
-if [ -f /memtest.bin ]; then
- menuentry "/memtest" {
- linux16 /memtest.bin
- }
-fi
-
-function setup_fedora {
- menuentry "\$1" {
- loopback loop \$1
- probe -s iso_label -l (loop)
- linux (loop)/isolinux/vmlinuz root=live:CDLABEL=\$iso_label rd.live.image quiet iso-scan/filename=\$1
- initrd (loop)/isolinux/initrd.img
- }
-}
-for iso in /Fedora-Workstation-Live-*.iso; do
- if [ -f "\$iso" ]; then
- setup_fedora \$iso
- fi
-done
-
-function setup_ubuntu {
- menuentry "\$1" {
- loopback loop \$1
- linux (loop)/casper/vmlinuz* boot=casper quiet iso-scan/filename=\$1
- initrd (loop)/casper/initrd*
- }
-}
-for iso in /ubuntu-*-desktop-*.iso; do
- if [ -f "\$iso" ]; then
- setup_ubuntu \$iso
- fi
-done
-
-EOT
-}
-
-CMD="cmd_${1:-}"
-shift || true
-
-if [ "$(type -t -- "$CMD")" = "function" ]; then
- "${CMD}" "$@"
-else
- echo "Usage: $0 [format|mount|grub|grubcfg|freedos|memtest|umount]"
- exit 1
-fi