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..94130a5 100755 --- a/01_build_file_system.sh +++ b/01_build_file_system.sh @@ -9,6 +9,23 @@ 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) + +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" +done + echo >&2 "===]> Info: Creating chroot environment... " mount --bind /dev "${CHROOT_PATH}/dev" mount --bind /run "${CHROOT_PATH}/run" @@ -21,15 +38,9 @@ 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 +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/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! ";