diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index a9aa7c3..d5efe37 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -13,10 +13,12 @@ jobs: - name: Configure variables id: variables run: | - BUILD=$(date '+%Y%m%d%H%M%S') - echo "::set-output name=build::${BUILD}" + KERNEL_VERSION=$(curl -Ls https://github.com/t2linux/T2-Ubuntu-Kernel/releases/ | grep deb | grep download | grep "${MBP_VERSION}" | cut -d'/' -f6 | head -n1 | cut -d'v' -f2) + echo "::set-output name=build::${KERNEL_VERSION}" - name: Build + env: + KERNEL_VERSION: ${{ steps.variables.outputs.build }} run: sudo ./build.sh - name: print sha256sum @@ -30,19 +32,21 @@ jobs: - name: Instructions for putting it back together run: | - cat << EOF - Download all the artifacts, and put them in a folder - without other files. Then run:" - unzip "*.z??.zip" - cat livecd-${{ steps.variables.outputs.build }}-mbp.z?? > cd.zip - echo unzip cd.zip - EOF + echo "${{ github.workspace }}Release.txt" + echo 'Download all the artifacts, and put them in a folder' > ${{ github.workspace }}Release.txt + echo 'without other files. Then run:' >> ${{ github.workspace }}Release.txt + echo '`unzip "*.z??.zip"`' >> ${{ github.workspace }}Release.txt + echo '`cat livecd-${{ steps.variables.outputs.build }}-mbp.z?? > cd.zip`' >> ${{ github.workspace }}Release.txt + echo '`unzip cd.zip`' >> ${{ github.workspace }}Release.txt + - name: Test release text + run: cat ${{ github.workspace }}Release.txt - name: Release if: github.ref == 'refs/heads/master' uses: softprops/action-gh-release@v1 with: files: ${{ github.workspace }}/output/* + body_path: ${{ github.workspace }}Release.txt tag_name: v20.04-${{ steps.variables.outputs.build }} draft: true env: diff --git a/01_build_file_system.sh b/01_build_file_system.sh index 335a4a2..2d57ae7 100755 --- a/01_build_file_system.sh +++ b/01_build_file_system.sh @@ -9,6 +9,25 @@ debootstrap \ "${CHROOT_PATH}" \ http://archive.ubuntu.com/ubuntu/ +### Download kernel packages +KERNEL_PACKAGES=() +if [[ -n "${KERNEL_VERSION:-}" ]]; then + MBP_KERNEL_TAG=${KERNEL_VERSION} + echo >&2 "===]> Info: Downloading specified kernel: ${MBP_KERNEL_TAG}"; +else + MBP_VERSION=t2 + MBP_KERNEL_TAG=$(curl -Ls https://github.com/t2linux/T2-Ubuntu-Kernel/releases/ | grep deb | grep download | grep "${MBP_VERSION}" | cut -d'/' -f6 | head -n1 | cut -d'v' -f2) + echo >&2 "===]> Info: Downloading latest ${MBP_VERSION} kernel: ${MBP_KERNEL_TAG}"; +fi + +while IFS='' read -r line; do KERNEL_PACKAGES+=("$line"); done < <(curl -sL https://github.com/t2linux/T2-Ubuntu-Kernel/releases/tag/v"${MBP_KERNEL_TAG}" | grep deb | grep span | cut -d'>' -f2 | cut -d'<' -f1) + +mkdir -p "${ROOT_PATH}/files/kernels" + +for i in "${KERNEL_PACKAGES[@]}"; do + curl -L https://github.com/t2linux/T2-Ubuntu-Kernel/releases/download/v"${MBP_KERNEL_TAG}"/"${i}" -o "${ROOT_PATH}/files/kernels/${i}" +done + echo >&2 "===]> Info: Creating chroot environment... " mount --bind /dev "${CHROOT_PATH}/dev" mount --bind /run "${CHROOT_PATH}/run" @@ -21,15 +40,10 @@ echo >&2 "===]> Info: Cleanup the chroot environment... " #umount "${CHROOT_PATH}/run" umount "${CHROOT_PATH}/dev" - -## Copy audio config files -#echo >&2 "===]> Info: Copy audio config files... " -#mkdir -p "${CHROOT_PATH}"/usr/share/alsa/cards/ -#cp -fv "${ROOT_PATH}"/files/audio/AppleT2.conf "${CHROOT_PATH}"/usr/share/alsa/cards/AppleT2.conf -#cp -fv "${ROOT_PATH}"/files/audio/apple-t2.conf "${CHROOT_PATH}"/usr/share/pulseaudio/alsa-mixer/profile-sets/apple-t2.conf -#cp -fv "${ROOT_PATH}"/files/audio/91-pulseaudio-custom.rules "${CHROOT_PATH}"/usr/lib/udev/rules.d/91-pulseaudio-custom.rules -#printf "\n load-module module-combine-sink channels=6 channel_map=front-left,front-right,rear-left,rear-right,front-center,lfe" >> /etc/pulse/default.pa -#printf "\ndefault-sample-channels = 6\nremixing-produce-lfe = yes\nremixing-consume-lfe = yes" >> /etc/pulse/daemon.conf +### Add update_kernel_mbp script +echo >&2 "===]> Info: Add update_kernel_mbp script... " +curl -L https://raw.githubusercontent.com/marcosfad/mbp-ubuntu/master/update_kernel_mbp.sh -o /usr/bin/update_kernel_mbp +chmod +x /usr/bin/update_kernel_mbp ### Copy grub config without finding macos partition echo >&2 "===]> Info: Patch Grub... " diff --git a/README.md b/README.md index ea7c9cd..551d794 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,14 @@ -# mbp-ubuntu +# mbp-ubunt. -The ISO in from this repo should allow you to install ubuntu without using an external keyboard or mouse on a MacBook Pro. It work in my MacBook with T2. +UBUNTU 20.04 ISO with Apple T2 patches built-in. The ISO in from this repo should allow you to install ubuntu without using an external keyboard or mouse on a MacBook Pro. It work in my MacBook with T2. [![CI](https://github.com/marcosfad/mbp-ubuntu/actions/workflows/CI.yml/badge.svg)](https://github.com/marcosfad/mbp-ubuntu/actions/workflows/CI.yml) **If this repo helped you in any way, consider inviting a coffee to the people in the [credits](https://github.com/marcosfad/mbp-ubuntu#credits) or [me](https://paypal.me/marcosfad).** -UBUNTU 20.04 ISO with Apple T2 patches built-in. - -Apple T2 drivers are integrated with this iso. - This repo is a rework of the great work done by [@mikeeq](https://github.com/mikeeq/mbp-fedora) -I'm using the Kernel from - +I'm using the Kernel from - Using additional drivers: - [Apple T2 (apple-bce) (audio, keyboard, touchpad)](https://github.com/t2linux/apple-bce-drv) @@ -21,42 +17,57 @@ Using additional drivers: Bootloader is configure correctly out of the box. No workaround needed. -## Which kernel to choose - -I've pre installed several different kernel, to allow better support to different hardware. - -If your macbook came with Big Sur preinstalled, you should use a bigsur version of kernel. - -If your macbook came with mojave, you should use a mojave version of the kernel. - -This will allow you to activate wifi in your macbook. See [this page for more information about wifi drivers](https://wiki.t2linux.org/guides/wifi/) - -I've recommend starting with the HWE Kernel. That one comes from Ubuntu own repository and I have had great performance with it. - -## Installation +## How to install (Based on mikeeq/mbp-fedora) 1. Reduce the size of the mac partition in MacOS -2. Download ISO file from releases. (Use the command line to unzip (`unzip /path/to/file.zip`) or "The Unarchiver" app) -3. Copy it to a USB using dd (or gdd if installed over brew): -```bash -diskutil list # found which number has the USB -diskutil umountDisk /dev/diskX -sudo dd bs=4096 if=ubuntu-20.04-5.6.10-mbp.iso of=/dev/diskX -``` -4. Boot in Recovery mode and allow booting unknown OS -5. Restart and immediately press the option key until the Logo come up -6. Select "EFI Boot" (the third option was the one that worked for me) -7. Launch Ubuntu Live -8. Use Ubiquity to install (just click on it) -9. Select the options that work for you and use for the partition the following setup: - * Leave the efi boot as preselected by the installer. Your Mac will keep on working with out problems. - * Add a ext4 partition and mounted as `/boot` (1024MB). - * Add a ext4 partition and monted as `/` (rest). - * Select the `/boot` partition as a target for GRUB installation, otherwise the system won't boot. -10. Run the installer (In my case it had some problem removing some packages at the end, but this is no real problem) -11. Shutdown and remove the USB Drive -12. Start again using the option key. Select the new efi boot. -13. Enjoy. + * HowTo: [Steps to Resize Mac Partition](https://www.anyrecover.com/hard-drive-recovery-data/resize-partition-mac/) +2. Turn off secure boot and allow booting from external media - +3. Download .iso from releases section - + + If it's split into multiple zip parts, i.e.: livecd.zip and livecd.z01 you need to download all zip parts and then + * join split files into one and then extract it via unzip + * + * or extract downloaded zip parts directly using: + * on Windows winrar or other supported tool like 7zip + * on Linux you can use p7zip, dnf install p7zip and then to extract 7za x livecd.zip + * on MacOS you can use + * the unarchiver from AppStore: + * or you can install p7zip via brew brew install p7zip and use 7za x livecd.zip command mentioned above + * to install brew follow this tutorial: +4. Next you can check the SHA256 checksum of extracted .ISO to verify if your extraction process went well + + MacOS: `shasum -a 256 ubuntu-20.04.iso` + Linux `sha256sum ubuntu-20.04.iso` + please compare it with a value in sha256 file available in github releases + +5. Burn the image on USB stick >=8GB via: + * `dd` + * Linux `sudo dd bs=4M if=/home/user/Downloads/ubuntu-20.04.iso of=/dev/sdc conv=fdatasync status=progress` + * MacOS + ```bash + diskutil list # found which number has the USB + sudo diskutil umountDisk /dev/diskX + sudo dd bs=4096 if=ubuntu-20.04-XXX.iso of=/dev/diskX + ``` + * if `dd` is not working for you for some reason you can try to install `gdd` via `brew` and use GNU `dd` command instead `sudo gdd bs=4M if=ubuntu-20.04-XXX.iso of=/dev/diskX conv=fdatasync status=progress` + + * Rufus (GPT)- , if prompted use DD mode + * Please don't use livecd-iso-to-disk as it's overwriting ISO default grub settings and Ubuntu will not boot correctly! + +6. Boot in Recovery mode and allow booting unknown OS +7. Restart and immediately press the option key until the Logo come up +8. Select "EFI Boot" (the third option was the one that worked for me) +9. Launch Ubuntu Live +10. Use Ubiquity to install (just click on it) +11. **[IMPORTANT]** Select the options that work for you and use for the partition the following setup: + * Leave the efi boot as preselected by the installer. Your Mac will keep on working without problems. + * Add a ext4 partition and mounted as `/boot` (1024MB). + * Add a ext4 partition and monted as `/` (rest). + * Select the `/boot` partition as a target for GRUB installation, otherwise the system won't boot. +12. Run the installer (In my case it had some problem removing some packages at the end, but this is no real problem) +13. Shutdown and remove the USB Drive +14. Start again using the option key. Select the new efi boot. +15. Enjoy. See for more details. @@ -64,7 +75,7 @@ See for more detai - See - To install additional languages, install appropriate langpack via apt `sudo apt-get install language-pack-[cod] language-pack-gnome-[cod] language-pack-[cod]-base language-pack-gnome-[cod]-base ` - - see https://askubuntu.com/questions/149876/how-can-i-install-one-language-by-command-line + - see - You can change mappings of ctrl, fn, option keys (PC keyboard mappings) by creating `/etc/modprobe.d/hid_apple.conf` file and recreating grub config. All available modifications could be found here: ``` # /etc/modprobe.d/hid_apple.conf @@ -92,26 +103,22 @@ and then: ### The easy way: -The live cd includes dkms and will automatically run when a new kernel is installed. You can use `dkms status` to see it. - -If you are upgrading from 5.7.19 to a newer kernel version (5.10+), you will need updated versions of these kernel modules. Instructions for installing updated ones are [here](https://wiki.t2linux.org/guides/dkms/). +The live cd includes a script to download the latest T2-Ubuntu-Kernel. Just run `update_kernel_mbp`. ### Another way: Check to see how it is done. +Or read + ## Know issues -- Sound is not working after the install. Follow the instructions detailed by @kevineinarsson: -On MBP 16,1, you might also need to disable realtime scheduling if the above gist doesn't work, because the pulseaudio server might get killed if the realtime budget is exceeded (). Just add `realtime-scheduling = no` to `/etc/pulse/daemon.conf`. - Checksum is failing for 2 files: md5sum.txt and /boot/grub/bios.img -- I'm having troubles shutting down ubuntu. Screen is black but fan keeps on working. I have to force shutdown. ## Not working (Following the mikeeq/mbp-fedora) - Dynamic audio input/output change (on connecting/disconnecting headphones jack) -- TouchID - (@MCMrARM is working on it - https://github.com/Dunedan/mbp-2016-linux/issues/71#issuecomment-528545490) -- Thunderbolt (is disabled, because driver was causing kernel panics (not tested with 5.5 kernel)) +- TouchID - (@MCMrARM is working on it - ) - Microphone (it's recognised with new apple t2 sound driver, but there is a low mic volume amp) ## TODO @@ -163,3 +170,15 @@ On MBP 16,1, you might also need to disable realtime scheduling if the above gis - @aunali1 - thanks for ArchLinux Kernel CI, the continuous support on discord and your continuous efforts. - @ppaulweber - thanks for keyboard and Macbook Air patches - @kevineinarsson - thanks for the audio settings + +## (deprecated) Which kernel to choose + +I've pre installed several different kernel, to allow better support to different hardware. + +If your macbook came with Big Sur preinstalled, you should use a bigsur version of kernel. + +If your macbook came with mojave, you should use a mojave version of the kernel. + +This will allow you to activate wifi in your macbook. See [this page for more information about wifi drivers](https://wiki.t2linux.org/guides/wifi/) + +I've recommend starting with the HWE Kernel. That one comes from Ubuntu own repository and I have had great performance with it. diff --git a/build_in_docker.sh b/build_in_docker.sh index acf1856..b603421 100755 --- a/build_in_docker.sh +++ b/build_in_docker.sh @@ -5,11 +5,10 @@ set -eu -o pipefail DOCKER_IMAGE=ubuntu:20.04 docker pull ${DOCKER_IMAGE} - docker run \ --privileged \ --rm \ -t \ -v "$(pwd)":/repo \ ${DOCKER_IMAGE} \ - /bin/bash -c "cd /repo && ./build.sh" + /bin/bash -c 'cd /repo && ./build.sh' diff --git a/files/chroot_build.sh b/files/chroot_build.sh index 51d875a..3b4020a 100755 --- a/files/chroot_build.sh +++ b/files/chroot_build.sh @@ -65,18 +65,6 @@ apt-get install -y -qq -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::=" grub-efi-amd64-signed \ intel-microcode \ linux-headers-azure \ - linux-headers-5.11.22-t2-hwe-bigsur \ - linux-headers-5.11.22-t2-hwe-mojave \ - linux-headers-5.12.19-t2-a-bigsur \ - linux-headers-5.12.19-t2-a-mojave \ - linux-headers-5.13.15-t2-j-bigsur \ - linux-headers-5.13.15-t2-j-mojave \ - linux-image-5.11.22-t2-hwe-bigsur \ - linux-image-5.11.22-t2-hwe-mojave \ - linux-image-5.12.19-t2-a-bigsur \ - linux-image-5.12.19-t2-a-mojave \ - linux-image-5.13.15-t2-j-bigsur \ - linux-image-5.13.15-t2-j-mojave \ thermald echo >&2 "===]> Info: Add firmwares" @@ -117,109 +105,19 @@ apt-get install -y -qq -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::=" nano \ make \ gcc \ - dkms \ iwd echo >&2 "===]> Info: Change initramfs format (for grub)... " sed -i "s/COMPRESS=lz4/COMPRESS=gzip/g" "/etc/initramfs-tools/initramfs.conf" -echo >&2 "===]> Info: Add drivers... " - -APPLE_BCE_DRIVER_GIT_URL=https://github.com/t2linux/apple-bce-drv.git -APPLE_BCE_DRIVER_BRANCH_NAME=aur -APPLE_BCE_DRIVER_COMMIT_HASH=f93c6566f98b3c95677de8010f7445fa19f75091 -APPLE_BCE_DRIVER_MODULE_NAME=apple-bce -APPLE_BCE_DRIVER_MODULE_VERSION=0.2 - -git clone --single-branch --branch ${APPLE_BCE_DRIVER_BRANCH_NAME} ${APPLE_BCE_DRIVER_GIT_URL} \ - /usr/src/"${APPLE_BCE_DRIVER_MODULE_NAME}-${APPLE_BCE_DRIVER_MODULE_VERSION}" -git -C /usr/src/"${APPLE_BCE_DRIVER_MODULE_NAME}-${APPLE_BCE_DRIVER_MODULE_VERSION}" checkout "${APPLE_BCE_DRIVER_COMMIT_HASH}" - -cat << EOF > /usr/src/${APPLE_BCE_DRIVER_MODULE_NAME}-${APPLE_BCE_DRIVER_MODULE_VERSION}/dkms.conf -PACKAGE_NAME="${APPLE_BCE_DRIVER_MODULE_NAME}" -PACKAGE_VERSION="${APPLE_BCE_DRIVER_MODULE_VERSION}" -MAKE[0]="make KVERSION=\$kernelver" -CLEAN="make clean" -BUILT_MODULE_NAME[0]="${APPLE_BCE_DRIVER_MODULE_NAME}" -DEST_MODULE_LOCATION[0]="/kernel/drivers/misc" -AUTOINSTALL="yes" -EOF - -while IFS= read -r kernel; do - echo "==> Debug: Adding $kernel" - rm -rf "/lib/modules/$kernel/build" - ln -sf "/usr/src/linux-headers-$kernel" "/lib/modules/$kernel/build" - dkms --verbose install -m "${APPLE_BCE_DRIVER_MODULE_NAME}" -v "${APPLE_BCE_DRIVER_MODULE_VERSION}" -k "$kernel" - if [ -f "/var/lib/dkms/${APPLE_BCE_DRIVER_MODULE_NAME}/${APPLE_BCE_DRIVER_MODULE_VERSION}/build/make.log" ]; then - cat "/var/lib/dkms/${APPLE_BCE_DRIVER_MODULE_NAME}/${APPLE_BCE_DRIVER_MODULE_VERSION}/build/make.log" - fi -done < <(dpkg -l | grep linux-image | grep t2 | grep ii | grep t2 | cut -d' ' -f3|cut -d'-' -f3-10) - -printf '\n### apple-bce start ###\napple-bce\n### apple-bce end ###' >>/etc/modules-load.d/apple-bce.conf -printf '\n### apple-bce start ###\nhapple-bce\n### apple-bce end ###' >>/etc/initramfs-tools/modules - -APPLE_IB_DRIVER_GIT_URL=https://github.com/t2linux/apple-ib-drv -APPLE_IB_DRIVER_BRANCH_NAME=mbp15 -APPLE_IB_DRIVER_COMMIT_HASH=fc9aefa5a564e6f2f2bb0326bffb0cef0446dc05 -APPLE_IB_DRIVER_MODULE_NAME=apple-ibridge -APPLE_IB_DRIVER_MODULE_VERSION=0.1 - -git clone --single-branch --branch ${APPLE_IB_DRIVER_BRANCH_NAME} ${APPLE_IB_DRIVER_GIT_URL} \ - /usr/src/"${APPLE_IB_DRIVER_MODULE_NAME}-${APPLE_IB_DRIVER_MODULE_VERSION}" -git -C /usr/src/"${APPLE_IB_DRIVER_MODULE_NAME}-${APPLE_IB_DRIVER_MODULE_VERSION}" checkout "${APPLE_IB_DRIVER_COMMIT_HASH}" - -echo >&2 "===]> Debug: Add apple-ib-drv ... " -cat /usr/src/"${APPLE_IB_DRIVER_MODULE_NAME}-${APPLE_IB_DRIVER_MODULE_VERSION}"/dkms.conf -while IFS= read -r kernel; do - echo "==> Debug: Adding $kernel" - rm -rf "/lib/modules/$kernel/build" - ln -sf "/usr/src/linux-headers-$kernel" "/lib/modules/$kernel/build" - dkms --verbose install -m "${APPLE_IB_DRIVER_MODULE_NAME}" -v "${APPLE_IB_DRIVER_MODULE_VERSION}" -k "$kernel" - if [ -f "/var/lib/dkms/${APPLE_IB_DRIVER_MODULE_NAME}/${APPLE_IB_DRIVER_MODULE_VERSION}/build/make.log" ]; then - cat "/var/lib/dkms/${APPLE_IB_DRIVER_MODULE_NAME}/${APPLE_IB_DRIVER_MODULE_VERSION}/build/make.log" - fi -done < <(dpkg -l | grep linux-image | grep t2 | grep ii | grep t2 | cut -d' ' -f3|cut -d'-' -f3-10) - - printf '\n### applespi start ###\napple_ib_tb\napple_ib_als\n### applespi end ###' >> /etc/modules-load.d/applespi.conf printf '\n# display f* key in touchbar\noptions apple-ib-tb fnmode=2\n' >> /etc/modprobe.d/apple-touchbar.conf -## Add optional dkms for brcm80211-mbp16x -#cd /tmp -#wget https://gist.github.com/hexchain/22932a13a892e240d71cb98fad62a6a0/archive/50ce4513d2865b1081a972bc09e8da639f94a755.zip -#unzip *55.zip -#cd 22* -#cp -r /usr/src/linux-headers-*-generic/drivers/net/wireless/broadcom/brcm80211 . -#cd brcm80211 -#patch -Np6 -i "../8001-corellium-wifi-bigsur.patch" -#patch -Np6 -i "../8002-brcmfmac-4377-mod.patch" -#patch -Np6 -i "../8003-brcmfmac-4377-64bit-regs.patch" -#patch -Np6 -i "../8004-brcmfmac-4377-chip-ids.patch" -#patch -Np1 -i "../out-of-tree.patch" -#mv Makefile Kbuild -#cp ../Makefile . -#sed -e "s,@PACKAGE_NAME@,brcm80211-mbp16x," -e "s,@PACKAGE_VERSION@,2.0," ../dkms.conf.in > dkms.conf -#cp ./brcm80211 /usr/src/brcm80211-mbp16x-2.0 -#cd /tmp -#rm -rf *55.zip 22* - -echo >&2 "===]> Debug dkms status" -dkms status - echo >&2 "===]> Configure amdgpu" cat << EOF > /etc/udev/rules.d/30-amdgpu-pm.rules KERNEL=="card0", SUBSYSTEM=="drm", DRIVERS=="amdgpu", ATTR{device/power_dpm_force_performance_level}="high" EOF -echo >&2 "===]> Info: Update initramfs... " - -## Add custom drivers to be loaded at boot -for kernel in $(dpkg -l | grep linux-image | grep ii | grep t2 | cut -d' ' -f3|cut -d'-' -f3-10); do - echo "==> Adding $kernel" - /usr/sbin/depmod -a "$kernel" - update-initramfs -u -v -k "$kernel" -done - #echo >&2 "===]> Info: install mpbfan ... " #git clone https://github.com/networkException/mbpfan /tmp/mbpfan #cd /tmp/mbpfan diff --git a/files/update_kernel_mbp.sh b/files/update_kernel_mbp.sh new file mode 100755 index 0000000..595a31c --- /dev/null +++ b/files/update_kernel_mbp.sh @@ -0,0 +1,79 @@ +#!/bin/bash + +set -eu -o pipefail + +KERNEL_PATCH_PATH=/tmp/kernel_patch +BINARY_INSTALL_PATH=${BINARY_INSTALL_PATH:-/usr/bin/} +UPDATE_SCRIPT_BRANCH=${UPDATE_SCRIPT_BRANCH:-master} + +#if [ "$EUID" -ne 0 ]; then +# echo >&2 "===]> Please run as root --> sudo -i; update_kernel_mbp" +# exit +#fi + +rm -rf ${KERNEL_PATCH_PATH} +mkdir -p ${KERNEL_PATCH_PATH} +cd ${KERNEL_PATCH_PATH} || exit + +### Downloading update_kernel_mbp script +echo >&2 "===]> Info: Downloading update_kernel_mbp ${UPDATE_SCRIPT_BRANCH} script... "; +rm -rf /usr/local/bin/update_kernel_mbp +if [ -f "${BINARY_INSTALL_PATH}"update_kernel_mbp ]; then + cp -rf "${BINARY_INSTALL_PATH}"update_kernel_mbp ${KERNEL_PATCH_PATH}/ + ORG_SCRIPT_SHA=$(sha256sum ${KERNEL_PATCH_PATH}/update_kernel_mbp | awk '{print $1}') +fi +curl -L https://raw.githubusercontent.com/marcosfad/mbp-ubuntu/"${UPDATE_SCRIPT_BRANCH}"/files/update_kernel_mbp.sh -o "${BINARY_INSTALL_PATH}"update_kernel_mbp +chmod +x "${BINARY_INSTALL_PATH}"update_kernel_mbp +if [ -f "${BINARY_INSTALL_PATH}"update_kernel_mbp ]; then + NEW_SCRIPT_SHA=$(sha256sum "${BINARY_INSTALL_PATH}"update_kernel_mbp | awk '{print $1}') + if [[ "$ORG_SCRIPT_SHA" != "$NEW_SCRIPT_SHA" ]]; then + echo >&2 "===]> Info: update_kernel_mbp script was updated please rerun!" && exit + else + echo >&2 "===]> Info: update_kernel_mbp script is in the latest version proceeding..." + fi +else + echo >&2 "===]> Info: update_kernel_mbp script was installed..." +fi + +### Download kernel packages +KERNEL_PACKAGES=() + +CURRENT_KERNEL_VERSION=$(uname -r) +echo >&2 "===]> Info: Current kernel version: ${CURRENT_KERNEL_VERSION}"; + +if [[ -n "${KERNEL_VERSION:-}" ]]; then + MBP_KERNEL_TAG=${KERNEL_VERSION} + echo >&2 "===]> Info: Downloading specified kernel: ${MBP_KERNEL_TAG}"; +else + MBP_VERSION=t2 + MBP_KERNEL_TAG=$(curl -Ls https://github.com/t2linux/T2-Ubuntu-Kernel/releases/ | grep deb | grep download | grep "${MBP_VERSION}" | cut -d'/' -f6 | head -n1 | cut -d'v' -f2) + echo >&2 "===]> Info: Downloading latest ${MBP_VERSION} kernel: ${MBP_KERNEL_TAG}"; +fi + +while IFS='' read -r line; do KERNEL_PACKAGES+=("$line"); done < <(curl -sL https://github.com/t2linux/T2-Ubuntu-Kernel/releases/tag/v"${MBP_KERNEL_TAG}" | grep deb | grep span | cut -d'>' -f2 | cut -d'<' -f1) + +for i in "${KERNEL_PACKAGES[@]}"; do + curl -LO https://github.com/t2linux/T2-Ubuntu-Kernel/releases/download/v"${MBP_KERNEL_TAG}"/"${i}" +done + +echo >&2 "===]> Info: Installing kernel version: ${MBP_KERNEL_TAG}"; +dpkg -i ./*.deb + +### Suspend fix +echo >&2 "===]> Info: Adding suspend fix... "; +curl -L https://raw.githubusercontent.com/marcosfad/mbp-ubuntu/${MBP_UBUNTU_BRANCH}/files/suspend/rmmod_tb.sh -o /lib/systemd/system-sleep/rmmod_tb.sh +chmod +x /lib/systemd/system-sleep/rmmod_tb.sh + +### Grub +echo >&2 "===]> Info: Rebuilding GRUB config... "; +curl -L https://raw.githubusercontent.com/marcosfad/mbp-ubuntu/${MBP_UBUNTU_BRANCH}/files/grub/30_os-prober -o /etc/grub.d/30_os-prober +chmod 755 /etc/grub.d/30_os-prober +grub2-mkconfig -o /boot/grub2/grub.cfg + +### Cleanup +echo >&2 "===]> Info: Cleaning old kernel pkgs (leaving 3 latest versions)... "; +rm -rf ${KERNEL_PATCH_PATH} +dnf autoremove -y +dnf remove -y "$(dnf repoquery --installonly --latest-limit=-3 -q)" + +echo >&2 "===]> Info: Kernel update to ${MBP_KERNEL_TAG} finished successfully! ";