]> code.delx.au - monosys/blob - scripts/multiboot-setup.sh
multiboot-setup.sh: fixed help
[monosys] / scripts / multiboot-setup.sh
1 #!/bin/bash
2
3 set -e
4
5 SYSLINUX_CFG="syslinux/syslinux.cfg"
6 REFIND_CFG="System/Library/CoreServices/refind.conf"
7
8 function setup_bootloader {
9 install_syslinux
10 install_refind
11 rm -rf distros
12 }
13
14 function install_syslinux {
15 rm -rf syslinux
16 mkdir syslinux
17 cp -R /usr/lib/syslinux/bios/* syslinux/
18
19 echo "UI menu.c32" >> "$SYSLINUX_CFG"
20
21 echo "Install syslinux:"
22 echo " # syslinux -i -d syslinux /dev/sdX"
23 }
24
25 function install_refind {
26 rm -rf System
27 mkdir -p System/Library/CoreServices
28 cp -R /usr/share/refind/* System/Library/CoreServices/
29 cp System/Library/CoreServices/{refind_x64.efi,boot.efi}
30
31 echo "timeout 0" >> "$REFIND_CFG"
32 echo "scanfor manual" >> "$REFIND_CFG"
33 }
34
35 function setup_iso {
36 mount_iso
37 set_boot_vars
38 copy_boot_files
39 configure_syslinux
40 configure_refind
41 umount_iso
42 }
43
44 function mount_iso {
45 umount_iso
46 sudo mount "$ISOFILE" /mnt
47 }
48
49 function umount_iso {
50 sudo umount /mnt || true
51 }
52
53 function set_boot_vars {
54 if [[ "$ISOFILE" == *ubuntu*.iso ]]; then
55 set_ubuntu_boot_vars
56 elif [[ "$ISOFILE" == *fedora*.iso ]]; then
57 set_fedora_boot_vars
58 else
59 echo "Unsupported ISO! $ISOFILE"
60 fi
61 }
62
63 function set_ubuntu_boot_vars {
64 version="$(basename "$ISOFILE" | cut -d- -f2)"
65 menulabel="Ubuntu $version"
66 unpackdir="distros/ubuntu_$(generate_safe_filename "$version")"
67 kernel="/mnt/casper/vmlinuz.efi"
68 initrd="/mnt/casper/initrd.lz"
69 bootparams="boot=casper iso-scan/filename=/${unpackdir}/$(basename "$ISOFILE")"
70 }
71
72 function set_fedora_boot_vars {
73 version="$(basename "$ISOFILE" .iso | sed 's/.*x86_64-//')"
74 menulabel="Fedora $version"
75 unpackdir="distros/fedora_$(generate_safe_filename "$version")"
76 kernel="/mnt/isolinux/vmlinuz0"
77 initrd="/mnt/isolinux/initrd0.img"
78 bootparams="root=live:CDLABEL=$(basename "$ISOFILE" .iso) rootfstype=auto iso-scan/filename=/${unpackdir}/$(basename "$ISOFILE")"
79 }
80
81 function generate_safe_filename {
82 echo -n "$1" | tr -c '[:alnum:]\n' '_'
83 }
84
85 function copy_boot_files {
86 mkdir -p "${unpackdir}"
87 ln "$ISOFILE" "${unpackdir}/"
88 cp "$kernel" "$initrd" "${unpackdir}/"
89 }
90
91 function configure_syslinux {
92 cat <<EOT >> "$SYSLINUX_CFG"
93
94 LABEL $(basename $unpackdir)
95 MENU LABEL ${menulabel}
96 LINUX /${unpackdir}/$(basename ${kernel})
97 INITRD /${unpackdir}/$(basename ${initrd})
98 APPEND ${bootparams}
99 EOT
100 }
101
102 function configure_refind {
103 cat <<EOT >> "$REFIND_CFG"
104
105 menuentry "${menulabel}"
106 loader /${unpackdir}/$(basename ${kernel})
107 initrd /${unpackdir}/$(basename ${initrd})
108 options "${bootparams}"
109 }
110 EOT
111 }
112
113 if [ "$1" = "reset" ]; then
114 setup_bootloader
115 elif [[ "$1" == *.iso ]]; then
116 ISOFILE="$1"
117 setup_iso
118 else
119 echo "Usage: [reset|/path/to/ubuntu.iso]"
120 fi