-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
executable file
·116 lines (101 loc) · 4.57 KB
/
build.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
#!/bin/bash
BUILD_DIR="/tmp/build"
CHROOT_DIR="${BUILD_DIR}/chroot"
STAGING_DIR="${BUILD_DIR}/staging"
PACKAGES="linux-image-amd64 linux-headers-amd64"
PACKAGES="${PACKAGES} dbus systemd-sysv live-boot xz-utils"
PACKAGES="${PACKAGES} locales console-setup"
PACKAGES="${PACKAGES} vim git htop tmux zsh curl wget"
PACKAGES="${PACKAGES} man less"
PACKAGES="${PACKAGES} ifupdown2 bridge-utils ifenslave isc-dhcp-client"
PACKAGES="${PACKAGES} iproute2 net-tools ethtool tcpdump iputils-ping"
PACKAGES="${PACKAGES} cryptsetup cryptsetup-initramfs"
PACKAGES="${PACKAGES} dropbear-bin dropbear-initramfs"
PACKAGES="${PACKAGES} mdadm lvm2"
PACKAGES="${PACKAGES} gdisk parted debootstrap"
PACKAGES="${PACKAGES} dosfstools e2fsprogs xfsprogs"
PACKAGES="${PACKAGES} openssh-server"
PACKAGES="${PACKAGES} cron"
PACKAGES="${PACKAGES} ipmitool lm-sensors"
PACKAGES="${PACKAGES} python3-netifaces python3-dialog"
PACKAGES="${PACKAGES} grub-efi grub-pc-bin rsync"
PACKAGES="${PACKAGES} ca-certificates"
PACKAGES="${PACKAGES} zfs-dkms zfs-initramfs zfsutils-linux"
PACKAGES="${PACKAGES} nvme-cli smartmontools pciutils usbutils"
debootstrap --arch=amd64 --variant=minbase bullseye "${CHROOT_DIR}" http://deb.debian.org/debian/
cp -R files/rootfs/* "${CHROOT_DIR}/"
chroot "${CHROOT_DIR}" apt-get -qq update
chroot "${CHROOT_DIR}" env DEBIAN_FRONTEND=noninteractive apt-get -qqy dist-upgrade
chroot "${CHROOT_DIR}" env DEBIAN_FRONTEND=noninteractive apt-get -qqy install --no-install-recommends ${PACKAGES}
chroot "${CHROOT_DIR}" dkms install "$(basename ${CHROOT_DIR}/usr/src/zfs-* | tr '-' '/')" -k "$(basename ${CHROOT_DIR}/lib/modules/*)"
mkdir "${CHROOT_DIR}/etc/systemd/system/[email protected]"
printf "[Service]\nExecStart=\nExecStart=-/sbin/agetty --autologin root --noclear %%I \$TERM\n" > "${CHROOT_DIR}/etc/systemd/system/[email protected]/override.conf"
echo en_US.UTF-8 UTF-8 > "${CHROOT_DIR}/etc/locale.gen"
chroot "${CHROOT_DIR}" locale-gen
echo root:root | chroot "${CHROOT_DIR}" chpasswd
git clone https://github.com/lukas2511/dotfiles.git "${CHROOT_DIR}/root/.dotfiles"
ln -s .dotfiles/zshrc "${CHROOT_DIR}/root/.zshrc"
chroot "${CHROOT_DIR}" chsh -s /usr/bin/zsh root
echo "AUTO -all" >> "${CHROOT_DIR}/etc/mdadm/mdadm.conf"
rm -rf "${CHROOT_DIR}/var/lib/apt/lists" "${CHROOT_DIR}/var/cache/apt/"*
rm -rf "${CHROOT_DIR}/dev"/*
rm -rf "${CHROOT_DIR}/proc"/*
rm -rf "${CHROOT_DIR}/sys"/*
mkdir -p "${STAGING_DIR}"
cp -R files/staging/* "${STAGING_DIR}/"
cp install.py "${CHROOT_DIR}/root/install.py"
chmod a+x "${CHROOT_DIR}/root/install.py"
mksquashfs "${CHROOT_DIR}" "${STAGING_DIR}/live/filesystem.squashfs" -b 1048576 -comp xz -Xdict-size 100%
cp ${CHROOT_DIR}/boot/vmlinuz-* "${STAGING_DIR}/live/vmlinuz"
cp ${CHROOT_DIR}/boot/initrd.img-* "${STAGING_DIR}/live/initrd"
mkdir -p "${BUILD_DIR}/tmp"
cat > "${BUILD_DIR}/tmp/grub-embed.cfg" << 'EOF'
if ! [ -d "$cmdpath" ]; then
# On some firmware, GRUB has a wrong cmdpath when booted from an optical disc.
# https://gitlab.archlinux.org/archlinux/archiso/-/issues/183
if regexp --set=1:isodevice '^(\([^)]+\))\/?[Ee][Ff][Ii]\/[Bb][Oo][Oo][Tt]\/?$' "$cmdpath"; then
cmdpath="${isodevice}/EFI/BOOT"
fi
fi
configfile "${cmdpath}/grub.cfg"
EOF
cp /usr/lib/ISOLINUX/isolinux.bin "${STAGING_DIR}/isolinux/"
cp /usr/lib/syslinux/modules/bios/* "${STAGING_DIR}/isolinux/"
cp -r /usr/lib/grub/x86_64-efi/* "${STAGING_DIR}/boot/grub/x86_64-efi/"
grub-mkstandalone -O x86_64-efi \
--modules="part_gpt part_msdos fat iso9660" \
--locales="" \
--themes="" \
--fonts="" \
--output="${STAGING_DIR}/EFI/BOOT/BOOTx64.EFI" \
"boot/grub/grub.cfg=${BUILD_DIR}/tmp/grub-embed.cfg"
(cd "${STAGING_DIR}" && \
dd if=/dev/zero of=efiboot.img bs=1M count=5 && \
mkfs.vfat efiboot.img && \
mmd -i efiboot.img ::/EFI ::/EFI/BOOT && \
mcopy -vi efiboot.img \
${STAGING_DIR}/EFI/BOOT/BOOTx64.EFI \
${STAGING_DIR}/boot/grub/grub.cfg \
::/EFI/BOOT/
)
xorriso \
-as mkisofs \
-iso-level 3 \
-o "debian-custom.iso" \
-full-iso9660-filenames \
-volid "DEBLIVE" \
--mbr-force-bootable -partition_offset 16 \
-joliet -joliet-long -rational-rock \
-isohybrid-mbr /usr/lib/ISOLINUX/isohdpfx.bin \
-eltorito-boot \
isolinux/isolinux.bin \
-no-emul-boot \
-boot-load-size 4 \
-boot-info-table \
--eltorito-catalog isolinux/isolinux.cat \
-eltorito-alt-boot \
-e --interval:appended_partition_2:all:: \
-no-emul-boot \
-isohybrid-gpt-basdat \
-append_partition 2 C12A7328-F81F-11D2-BA4B-00A0C93EC93B ${STAGING_DIR}/efiboot.img \
"${STAGING_DIR}"