mbp-ubuntu/files/chroot_build.sh

214 lines
6.4 KiB
Bash
Raw Normal View History

2020-04-17 05:53:48 -04:00
#!/bin/bash
set -eu -o pipefail
2020-04-24 06:19:37 -04:00
echo >&2 "===]> Info: Configure environment... "
2020-04-17 05:53:48 -04:00
mount none -t proc /proc
mount none -t sysfs /sys
mount none -t devpts /dev/pts
2020-04-17 12:31:32 -04:00
2020-04-17 05:53:48 -04:00
export HOME=/root
export LC_ALL=C
2022-05-20 07:52:30 -04:00
echo "ubuntu-jammy-live" >/etc/hostname
2020-04-17 05:53:48 -04:00
2020-04-24 06:19:37 -04:00
echo >&2 "===]> Info: Configure and update apt... "
2020-04-17 05:53:48 -04:00
2020-04-24 06:19:37 -04:00
cat <<EOF >/etc/apt/sources.list
2022-05-20 07:52:30 -04:00
deb http://archive.ubuntu.com/ubuntu/ jammy main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ jammy main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ jammy-updates main restricted universe multiverse
2020-04-17 05:53:48 -04:00
EOF
apt-get update
2020-04-24 06:19:37 -04:00
echo >&2 "===]> Info: Install systemd and Ubuntu MBP Repo... "
2020-04-17 05:53:48 -04:00
2020-04-17 12:31:32 -04:00
apt-get install -y systemd-sysv gnupg curl wget
2020-04-17 05:53:48 -04:00
2020-04-17 12:31:32 -04:00
mkdir -p /etc/apt/sources.list.d
2022-09-29 09:25:08 -04:00
curl -s --compressed "https://adityagarg8.github.io/t2-ubuntu-repo/KEY.gpg" | gpg --dearmor | tee /etc/apt/trusted.gpg.d/t2-ubuntu-repo.gpg >/dev/null
curl -s --compressed -o /etc/apt/sources.list.d/t2.list "https://adityagarg8.github.io/t2-ubuntu-repo/t2.list"
2020-04-17 12:31:32 -04:00
apt-get update
2020-04-17 05:53:48 -04:00
2020-04-24 06:19:37 -04:00
echo >&2 "===]> Info: Configure machine-id and divert... "
2020-04-17 05:53:48 -04:00
2020-04-24 06:19:37 -04:00
dbus-uuidgen >/etc/machine-id
2020-04-17 05:53:48 -04:00
ln -fs /etc/machine-id /var/lib/dbus/machine-id
dpkg-divert --local --rename --add /sbin/initctl
ln -s /bin/true /sbin/initctl
2020-04-24 06:19:37 -04:00
echo >&2 "===]> Info: Install packages needed for Live System... "
2020-04-17 05:53:48 -04:00
export DEBIAN_FRONTEND=noninteractive
apt-get install -y -qq -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" \
2020-04-24 06:19:37 -04:00
ubuntu-standard \
2020-05-03 09:04:34 -04:00
sudo \
2020-04-24 06:19:37 -04:00
casper \
discover \
laptop-detect \
os-prober \
network-manager \
resolvconf \
net-tools \
wireless-tools \
wpagui \
locales \
initramfs-tools \
binutils \
linux-generic \
linux-headers-generic \
2020-05-03 09:04:34 -04:00
grub-efi-amd64-signed \
intel-microcode \
2022-02-07 12:14:40 -05:00
thermald \
2022-02-13 03:59:18 -05:00
grub2 \
nautilus-admin
2020-04-24 06:19:37 -04:00
if [[ ${ALTERNATIVE} = t2-external ]]
then
2022-10-18 22:40:43 -04:00
curl -L https://github.com/AdityaGarg8/T2-Ubuntu/releases/download/vKVER-PREL-kernel/linux-headers-KVER-${ALTERNATIVE}_KVER-PREL_amd64.deb > /tmp/headers.deb
curl -L https://github.com/AdityaGarg8/T2-Ubuntu/releases/download/vKVER-PREL-kernel/linux-image-KVER-${ALTERNATIVE}_KVER-PREL_amd64.deb > /tmp/image.deb
else
2022-10-17 12:33:21 -04:00
curl -L https://github.com/t2linux/T2-Ubuntu-Kernel/releases/download/vKVER-PREL/linux-headers-KVER-${ALTERNATIVE}_KVER-PREL_amd64.deb > /tmp/headers.deb
curl -L https://github.com/t2linux/T2-Ubuntu-Kernel/releases/download/vKVER-PREL/linux-image-KVER-${ALTERNATIVE}_KVER-PREL_amd64.deb > /tmp/image.deb
fi
2021-11-20 01:12:54 -05:00
file /tmp/*
2022-08-19 06:37:39 -04:00
apt install /tmp/headers.deb /tmp/image.deb
2021-11-20 23:16:21 -05:00
2020-04-24 06:19:37 -04:00
echo >&2 "===]> Info: Install window manager... "
2020-04-17 05:53:48 -04:00
apt-get install -y -qq -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" \
2020-04-24 06:19:37 -04:00
plymouth-theme-ubuntu-logo \
ubuntu-desktop-minimal \
2020-05-03 09:04:34 -04:00
ubuntu-gnome-wallpapers \
snapd
2020-04-24 06:19:37 -04:00
echo >&2 "===]> Info: Install Graphical installer... "
2020-04-17 05:53:48 -04:00
2020-04-24 06:19:37 -04:00
apt-get install -y -qq -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" \
ubiquity \
ubiquity-casper \
ubiquity-frontend-gtk \
ubiquity-slideshow-ubuntu \
ubiquity-ubuntu-artwork
2020-04-17 05:53:48 -04:00
2022-09-29 09:25:08 -04:00
echo >&2 "===]> Info: Install useful applications and sound configuration... "
2020-04-17 05:53:48 -04:00
apt-get install -y -qq -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" \
2020-04-24 06:19:37 -04:00
git \
curl \
nano \
make \
gcc \
2020-10-18 08:26:37 -04:00
dkms \
2022-09-29 09:25:08 -04:00
iwd \
2022-10-20 15:23:56 -04:00
apple-t2-audio-config \
t2-kernel-script
2020-04-17 05:53:48 -04:00
2020-04-24 06:19:37 -04:00
echo >&2 "===]> Info: Change initramfs format (for grub)... "
sed -i "s/COMPRESS=lz4/COMPRESS=gzip/g" "/etc/initramfs-tools/initramfs.conf"
2020-04-17 05:53:48 -04:00
2022-01-22 11:03:30 -05:00
echo >&2 "===]> Info: Configure drivers... "
2020-04-17 12:31:32 -04:00
# thunderbolt is working for me.
#printf '\nblacklist thunderbolt' >>/etc/modprobe.d/blacklist.conf
2020-04-24 06:19:37 -04:00
2022-02-06 00:27:08 -05:00
printf 'apple-bce' >>/etc/modules-load.d/t2.conf
printf '\n### apple-bce start ###\nhid-apple\nsnd-seq\napple-bce\n### apple-bce end ###' >>/etc/initramfs-tools/modules
2022-01-15 00:38:22 -05:00
printf '\n# display f* key in touchbar\noptions apple-ib-tb fnmode=1\n' >> /etc/modprobe.d/apple-tb.conf
2022-02-06 00:27:08 -05:00
#printf '\n# delay loading of the touchbar driver\ninstall apple-ib-tb /bin/sleep 7; /sbin/modprobe --ignore-install apple-ib-tb' >> /etc/modprobe.d/delay-tb.conf
2022-02-03 08:16:56 -05:00
echo '
#!/usr/bin/env bash
echo "Select Touch Bar mode"
echo
echo "0: Only show F1-F12"
echo "1: Show media and brightness controls, use the fn key to switch to F1-12"
echo "2: Show F1-F12, use the fn key to switch to media and brightness controls"
echo "3: Only show media and brightness controls"
echo "4: Only show the escape key"
read tb
echo "Changing default mode ..."
echo "# display f* key in touchbar" > /etc/modprobe.d/apple-tb.conf
echo "options apple-ib-tb fnmode=$tb" >> /etc/modprobe.d/apple-tb.conf
bash -c "echo $tb > /sys/class/input/*/device/fnmode"
echo "Done!"' | tee /usr/local/bin/touchbar >/dev/null
chmod a+x /usr/local/bin/touchbar
chown root:root /usr/local/bin/touchbar
2020-04-17 12:31:32 -04:00
2020-04-24 06:19:37 -04:00
echo >&2 "===]> Info: Update initramfs... "
2020-04-17 12:31:32 -04:00
2020-04-24 06:19:37 -04:00
## Add custom drivers to be loaded at boot
/usr/sbin/depmod -a "${KERNEL_VERSION}"
update-initramfs -u -v -k "${KERNEL_VERSION}"
2020-04-17 12:31:32 -04:00
2020-04-24 06:19:37 -04:00
echo >&2 "===]> Info: Remove unused applications ... "
2020-04-17 05:53:48 -04:00
apt-get purge -y -qq \
2020-04-24 06:19:37 -04:00
transmission-gtk \
transmission-common \
gnome-mahjongg \
gnome-mines \
gnome-sudoku \
aisleriot \
hitori \
xiterm+thai \
make \
gcc \
vim \
2020-05-03 09:04:34 -04:00
binutils \
linux-generic \
2022-05-20 07:52:30 -04:00
linux-headers-5.15.0-30 \
linux-headers-5.15.0-30-generic \
2020-05-03 09:04:34 -04:00
linux-headers-generic \
2022-05-20 07:52:30 -04:00
linux-image-5.15.0-30-generic \
2020-05-03 09:04:34 -04:00
linux-image-generic \
2022-05-20 07:52:30 -04:00
linux-modules-5.15.0-30-generic \
linux-modules-extra-5.15.0-30-generic
2020-04-17 05:53:48 -04:00
apt-get autoremove -y
2020-04-24 06:19:37 -04:00
echo >&2 "===]> Info: Reconfigure environment ... "
2020-04-17 05:53:48 -04:00
locale-gen --purge en_US.UTF-8 en_US
2020-04-24 06:19:37 -04:00
printf 'LANG="C.UTF-8"\nLANGUAGE="C.UTF-8"\n' >/etc/default/locale
2020-04-17 05:53:48 -04:00
dpkg-reconfigure -f readline resolvconf
2020-04-24 06:19:37 -04:00
cat <<EOF >/etc/NetworkManager/NetworkManager.conf
2020-04-17 05:53:48 -04:00
[main]
plugins=ifupdown,keyfile
2021-12-25 23:52:26 -05:00
2020-04-17 05:53:48 -04:00
[ifupdown]
managed=false
2021-12-25 23:52:26 -05:00
[device]
wifi.scan-rand-mac-address=no
2020-04-17 05:53:48 -04:00
EOF
dpkg-reconfigure network-manager
2020-10-18 08:26:37 -04:00
echo >&2 "===]> Info: Configure Network Manager to use iwd... "
mkdir -p /etc/NetworkManager/conf.d
2022-01-17 06:54:16 -05:00
printf '#[device]\n#wifi.backend=iwd\n' > /etc/NetworkManager/conf.d/wifi_backend.conf
#systemctl enable iwd.service
2020-04-17 05:53:48 -04:00
2020-04-24 06:19:37 -04:00
echo >&2 "===]> Info: Cleanup the chroot environment... "
2020-04-17 05:53:48 -04:00
truncate -s 0 /etc/machine-id
rm /sbin/initctl
dpkg-divert --rename --remove /sbin/initctl
apt-get clean
rm -rf /tmp/* ~/.bash_history
2020-04-17 12:31:32 -04:00
rm -rf /tmp/setup_files
2020-04-17 05:53:48 -04:00
umount -lf /dev/pts
umount -lf /sys
umount -lf /proc
export HISTSIZE=0