-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-stage1.sh
executable file
·83 lines (74 loc) · 2.98 KB
/
build-stage1.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
#!/bin/bash
# Copyright (C) 2021 Piotr Chmielnicki
#
# 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, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
set -e
set -x
USERLAND_ROOT='/userland'
cd "$(dirname $(readlink -f "${0}"))"
if [ "${BUILD_STAGE}" != 1 ]
then
echo "Error: this script should no be run manually." >&2
exit -1
fi
### Bootstrap ###
cat conf/sources.list-build > /etc/apt/sources.list
sed -i "s,SECMIRROR,${DEBIAN_SECURITY_MIRROR}," /etc/apt/sources.list
sed -i "s,MIRROR,${DEBIAN_MIRROR}," /etc/apt/sources.list
sed -i "s,RELEASE,${DEBIAN_RELEASE}," /etc/apt/sources.list
apt-get update -y
apt-get dist-upgrade -y
apt-get install xorriso isolinux syslinux-utils syslinux-efi dosfstools \
fusefat squashfs-tools debootstrap parted git -y
mkdir -p -m 0700 "${USERLAND_ROOT}" /iso-content
### Setup userland ###
stage2="$(find ./build-stage2-enabled.d -type l,f | sort)"
for script in ${stage2}
do
DEBIAN_RELEASE="${DEBIAN_RELEASE}" ARCH="${ARCH}" DEBIAN_MIRROR="${DEBIAN_MIRROR}" \
USERLAND_ROOT="${USERLAND_ROOT}" BUILD_STAGE=2 "$script"
done
### Setup legacy BIOS boot ###
cp /usr/lib/ISOLINUX/isolinux.bin \
/usr/lib/syslinux/modules/bios/ldlinux.c32 \
"${USERLAND_ROOT}/vmlinuz" \
"${USERLAND_ROOT}/initrd.img" \
conf/syslinux.cfg \
/iso-content/
### Setup UEFI boot ###
EFI_OPTS=''
if [ "${ARCH}" = 'amd64' ]
then
mknod /dev/fuse c 10 229
mkdir -m 0000 /esp
head -c 96M /dev/zero > /iso-content/efi64.img
mkfs.fat --mbr=y -F 16 /iso-content/efi64.img
fusefat -o rw+ /iso-content/efi64.img /esp
mkdir -p /esp/EFI/BOOT
cp /usr/lib/syslinux/modules/efi64/ldlinux.e64 /esp/EFI/BOOT/
cp /usr/lib/SYSLINUX.EFI/efi64/syslinux.efi /esp/EFI/BOOT/BOOTX64.EFI
cp "${USERLAND_ROOT}/vmlinuz" \
"${USERLAND_ROOT}/initrd.img" \
conf/syslinux.cfg /esp/
sync
umount /esp
EFI_OPTS='-append_partition 2 28732ac11ff8d211ba4b00a0c93ec93b /iso-content/efi64.img -appended_part_as_gpt'
EFI_OPTS="${EFI_OPTS} -eltorito-alt-boot -e --interval:appended_partition_2::: -no-emul-boot"
fi
### Pack all together ###
mksquashfs "${USERLAND_ROOT}" /iso-content/filesystem.squashfs -comp xz -Xdict-size 100%
xorriso -as mkisofs -J -joliet-long -o /output.iso -b isolinux.bin \
-no-emul-boot -boot-info-table --protective-msdos-label --mbr-force-bootable -c boot.cat \
${EFI_OPTS} -V Airgap-OS /iso-content