This repository has been archived by the owner on Jan 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-iso.sh
executable file
·160 lines (160 loc) · 8.73 KB
/
create-iso.sh
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/bin/bash
#
# MassOS LiveCD ISO Creator - Copyright (C) 2022 MassOS Developers.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# Exit on error.
set -e
# Ensure we are running as root.
if [ $EUID -ne 0 ]; then
echo "Error: $(basename "$0") must be run as root."
exit 1
fi
# Ensure dependencies are present.
which curl &>/dev/null || (echo "Error: curl is required." >&2; exit 1)
which mass-chroot &>/dev/null || (echo "Error: mass-chroot (part of MassOS) is required." >&2; exit 1)
which mkfs.fat &>/dev/null || (echo "Error: mkfs.fat from dosfstools is required." >&2; exit 1)
which mksquashfs &>/dev/null || (echo "Error: mksquashfs from squashfs-tools is required." >&2; exit 1)
which xorriso &>/dev/null || (echo "Error: xorriso from libisoburn is required." >&2; exit 1)
# Ensure that the rootfs file is specified and valid.
if [ -z "$1" ]; then
echo "Error: Rootfs file must be specified." >&2
echo "Usage: $(basename "$0") <rootfs-file-name>.tar.xz" >&2
exit 1
fi
if [ ! -f "$1" ]; then
echo "Error: Specified rootfs file $1 is not valid." >&2
exit 1
fi
# Check if an existring directory exists.
if [ -e "iso-workdir" ]; then
echo "The working directory 'iso-workdir' already exists, please remove" >&2
echo "it before running $(basename "$0")." >&2
exit 1
fi
# Create directories.
mkdir -p iso-workdir/{iso-root,massos-rootfs,mnt,squashfs-tmp,syslinux}
mkdir -p iso-workdir/iso-root/EFI/BOOT
mkdir -p iso-workdir/iso-root/isolinux
mkdir -p iso-workdir/iso-root/LiveOS
mkdir -p iso-workdir/squashfs-tmp/LiveOS
mkdir -p iso-workdir/efitmp
# Download stuff.
echo "Downloading SYSLINUX..."
curl -L https://cdn.kernel.org/pub/linux/utils/boot/syslinux/syslinux-6.03.tar.xz -o iso-workdir/syslinux.tar.xz
tar --no-same-owner -xf iso-workdir/syslinux.tar.xz -C iso-workdir/syslinux --strip-components=1
# Download firmware.
echo "Downloading firmware..."
FW_VER="20220913"
MVER="20220510"
SOF_VER="v2.2.2"
curl -L https://cdn.kernel.org/pub/linux/kernel/firmware/linux-firmware-$FW_VER.tar.xz -o iso-workdir/firmware.tar.xz
curl -L https://github.com/intel/Intel-Linux-Processor-Microcode-Data-Files/archive/microcode-$MVER.tar.gz -o iso-workdir/mcode.tar.gz
curl -L https://github.com/thesofproject/sof-bin/releases/download/$SOF_VER/sof-bin-$SOF_VER.tar.gz -o iso-workdir/sof.tar.gz
# Extract rootfs.
echo "Extracting rootfs..."
tar -xpf "$1" -C iso-workdir/massos-rootfs
ver="$(cat iso-workdir/massos-rootfs/etc/massos-release)"
# Prepare the live system.
echo "Preparing the live system..."
chroot iso-workdir/massos-rootfs /usr/sbin/groupadd -r autologin
chroot iso-workdir/massos-rootfs /usr/sbin/useradd -c "Live User" -G wheel,netdev,lpadmin,autologin -ms /bin/bash massos
echo "massos:massos" | chroot iso-workdir/massos-rootfs /usr/sbin/chpasswd -c SHA512
echo "massos ALL=(ALL) NOPASSWD: ALL" > iso-workdir/massos-rootfs/etc/sudoers.d/live
cat > iso-workdir/massos-rootfs/etc/polkit-1/rules.d/49-live.rules << "END"
polkit.addRule(function(action, subject) {
if (subject.isInGroup("massos")) {
return polkit.Result.YES;
}
});
END
install -m755 livecd-installer iso-workdir/massos-rootfs/usr/bin/livecd-installer
install -m644 livecd-installer.desktop iso-workdir/massos-rootfs/usr/share/applications/livecd-installer.desktop
chroot iso-workdir/massos-rootfs /usr/bin/install -o massos -g massos -dm755 /home/massos/Desktop
chroot iso-workdir/massos-rootfs /usr/bin/install -o massos -g massos -m755 /usr/share/applications/livecd-installer.desktop /home/massos/Desktop/livecd-installer.desktop
install -m644 livecd-files/trust-livecd-installer.desktop iso-workdir/massos-rootfs/etc/xdg/autostart/trust-livecd-installer.desktop
. autologin/autologin.sh
# Install firmware.
echo "Installing firmware..."
mkdir -p iso-workdir/{firmware,mcode,sof}
tar --no-same-owner -xf iso-workdir/firmware.tar.xz -C iso-workdir/firmware --strip-components=1
tar --no-same-owner -xf iso-workdir/mcode.tar.gz -C iso-workdir/mcode --strip-components=1
tar --no-same-owner -xf iso-workdir/sof.tar.gz -C iso-workdir/sof --strip-components=1
install -d iso-workdir/massos-rootfs/usr/lib/firmware
pushd iso-workdir/firmware >/dev/null
patch -sNp1 -i ../../livecd-files/linux-firmware-compression.patch
./copy-firmware.sh -C "$PWD"/../massos-rootfs/usr/lib/firmware
install -t "$PWD"/../massos-rootfs/usr/lib/firmware -Dm644 GPL-2 GPL-3 LICENCE* LICENSE* WHENCE
popd >/dev/null
install -d iso-workdir/massos-rootfs/usr/lib/firmware/intel-ucode
install -m644 iso-workdir/mcode/intel-ucode{,-with-caveats}/* iso-workdir/massos-rootfs/usr/lib/firmware/intel-ucode
pushd iso-workdir/sof >/dev/null
cp -r sof*$SOF_VER "$PWD"/../massos-rootfs/usr/lib/firmware/intel
ln -sf sof-$SOF_VER "$PWD"/../massos-rootfs/usr/lib/firmware/intel/sof
ln -sf sof-tplg-$SOF_VER "$PWD"/../massos-rootfs/usr/lib/firmware/intel/sof-tplg
install -t "$PWD"/../massos-rootfs/usr/lib/firmware/intel/sof -Dm644 LICENCE.Intel LICENCE.NXP Notice.NXP
popd >/dev/null
# Create Squashfs image.
echo "Creating squashfs image..."
cd iso-workdir/massos-rootfs
mksquashfs * ../iso-root/LiveOS/squashfs.img -comp xz -quiet
cd ../..
# Copy kernel and generate initramfs.
echo "Copying kernel..."
cp iso-workdir/massos-rootfs/boot/vmlinuz* iso-workdir/iso-root/vmlinuz
echo "Generating initramfs..."
mass-chroot iso-workdir/massos-rootfs /usr/bin/dracut -q -a dmsquash-live initramfs.img "$(ls iso-workdir/massos-rootfs/usr/lib/modules)" >/dev/null
echo "Copying initramfs..."
mv iso-workdir/massos-rootfs/initramfs.img iso-workdir/iso-root/initramfs.img
# Install bootloader files.
echo "Setting up bootloader..."
# Legacy BIOS.
cp iso-workdir/syslinux/bios/core/isolinux.bin iso-workdir/iso-root/isolinux/isolinux.bin
cp iso-workdir/syslinux/bios/com32/elflink/ldlinux/ldlinux.c32 iso-workdir/iso-root/isolinux/ldlinux.c32
cp iso-workdir/syslinux/bios/com32/lib/libcom32.c32 iso-workdir/iso-root/isolinux/libcom32.c32
cp iso-workdir/syslinux/bios/com32/libutil/libutil.c32 iso-workdir/iso-root/isolinux/libutil.c32
cp iso-workdir/syslinux/bios/com32/menu/vesamenu.c32 iso-workdir/iso-root/isolinux/vesamenu.c32
cp iso-workdir/syslinux/bios/mbr/isohdpfx.bin iso-workdir/iso-root/isolinux/isohdpfx.bin
cp iso-workdir/syslinux/COPYING iso-workdir/iso-root/isolinux/LICENSE-ISOLINUX.txt
cp livecd-files/isolinux.cfg iso-workdir/iso-root/isolinux/isolinux.cfg
cp livecd-files/splash.png iso-workdir/iso-root/isolinux/splash.png
# EFI.
mkdir -p iso-workdir/massos-rootfs/boot/grub
cp livecd-files/grub.cfg iso-workdir/massos-rootfs/boot/grub/grub.cfg
mass-chroot iso-workdir/massos-rootfs /usr/bin/grub-mkstandalone -d /usr/lib/grub/x86_64-efi -O x86_64-efi -o BOOTX64.EFI --compress=xz /boot/grub/grub.cfg >/dev/null
cp iso-workdir/massos-rootfs/BOOTX64.EFI iso-workdir/iso-root/EFI/BOOT/BOOTX64.EFI
chmod +x iso-workdir/iso-root/EFI/BOOT/BOOTX64.EFI
cp iso-workdir/massos-rootfs/usr/share/grub/unicode.pf2 iso-workdir/iso-root/unicode.pf2
cp iso-workdir/massos-rootfs/usr/share/licenses/grub/COPYING iso-workdir/iso-root/EFI/BOOT/LICENSE-BOOTX64.txt
fallocate -l $(($(du -bc iso-workdir/iso-root/EFI/BOOT/{BOOTX64.EFI,LICENSE-BOOTX64.txt} | tail -n1 | cut -f1) + 80000)) iso-workdir/iso-root/EFI/BOOT/efiboot.img
mkfs.fat -F12 iso-workdir/iso-root/EFI/BOOT/efiboot.img -n "MASSOS_EFI"
mount -o loop iso-workdir/iso-root/EFI/BOOT/efiboot.img iso-workdir/efitmp
mkdir -p iso-workdir/efitmp/EFI/BOOT
cp iso-workdir/iso-root/EFI/BOOT/{BOOTX64.EFI,LICENSE-BOOTX64.txt} iso-workdir/efitmp/EFI/BOOT
sync
umount iso-workdir/efitmp
# Copy additional files.
cp livecd-files/autorun.ico iso-workdir/iso-root/autorun.ico
cp livecd-files/autorun.inf iso-workdir/iso-root/autorun.inf
cp livecd-files/README.txt iso-workdir/iso-root/README.txt
cp LICENSE iso-workdir/iso-root/LICENSE.txt
# Create the ISO image.
echo "Creating ISO image..."
xorrisofs -iso-level 3 -d -J -N -R -max-iso9660-filenames -relaxed-filenames -allow-lowercase -V "MASSOS" -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -e EFI/BOOT/efiboot.img -isohybrid-gpt-basdat -no-emul-boot -isohybrid-mbr iso-workdir/iso-root/isolinux/isohdpfx.bin -o "massos-$ver-x86_64-$variant.iso" iso-workdir/iso-root
# Clean up.
echo "Cleaning up..."
rm -rf iso-workdir
# Finishing message.
echo "All done! Output image written to massos-$ver-x86_64-$variant.iso."