From ad99139b1f8ebd422a6b9541080d9ba198342534 Mon Sep 17 00:00:00 2001
From: Andri Joos <andri@joos.io>
Date: Tue, 3 Dec 2024 13:17:15 +0100
Subject: [PATCH] install latest mainline kernel

---
 install.sh           |  4 ++++
 install_functions.sh | 27 ++++++++++++++++++++++++---
 options.sh           |  3 +++
 3 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/install.sh b/install.sh
index d037073..353ace0 100644
--- a/install.sh
+++ b/install.sh
@@ -49,6 +49,7 @@ $protonvpn_key "$protonvpn_label" $protonvpn_enabled \
 $flatseal_key "$flatseal_label" $flatseal_enabled \
 $wireguard_key "$wireguard_label" $wireguard_enabled \
 $remmina_key "$remmina_label" $remmina_enabled \
+$mainline_key "$mainline_label" $mainline_enabled \
 $swap_key "$swap_label" $swap_enabled \
 3>&1 1>&2 2>&3)
 IFS=' ' read -a selected_options <<< $selected_tags
@@ -187,6 +188,9 @@ do
     elif [ $option = $remmina_key ]
     then
         install_remmina
+    elif [ $option = $mainline_key ]
+    then
+        install_mainline_kernel
     elif [ $option = $swap_key ]
     then
         setup_swap
diff --git a/install_functions.sh b/install_functions.sh
index b973bbf..99e1f10 100644
--- a/install_functions.sh
+++ b/install_functions.sh
@@ -35,6 +35,14 @@ update_upgrade() {
     else
         echo "flatpak does not exist; skipping update"
     fi
+
+    if command_exists mainline
+    then
+        sudo mainline install-minor || true
+        echo "kernel was updated to latest minor version, upgrading to a major version must be done manually"
+    else
+        echo "mainline does not exist; skipping update"
+    fi
 }
 
 flatpak_add_repo() {
@@ -214,11 +222,12 @@ install_dl_driver() {
     install_curl
     display_link_keyring="$downloads_path/synaptics-repository-keyring.deb"
     curl https://www.synaptics.com/sites/default/files/Ubuntu/pool/stable/main/all/synaptics-repository-keyring.deb -o $display_link_keyring
-    sudo apt install -y $display_link_keyring
+    $apt_install_cmd $display_link_keyring
     sudo rm $display_link_keyring
-
     sudo apt update
-    sudo apt install -y displaylink-driver
+
+    $apt_install_cmd gcc-14 # newer kernels require gcc 14
+    $apt_install_cmd displaylink-driver
 }
 
 install_obsidian() {
@@ -365,3 +374,15 @@ install_wireguard() {
 install_remmina() {
     install_flatpak_app org.remmina.Remmina
 }
+
+install_mainline_kernel() {
+    sudo add-apt-repository ppa:cappelikan/ppa
+    $apt_update_cmd
+    $apt_install_cmd mainline
+
+    mainline list
+    echo "if displaylink driver is installed, make sure that displaylink evdi supports the kernel: https://github.com/DisplayLink/evdi/releases"
+    read -p "Kernel version (e.g. 6.11.10): " mainline_kernel_version
+
+    sudo mainline install $mainline_kernel_version || true
+}
diff --git a/options.sh b/options.sh
index 52ca3ef..09e22d3 100644
--- a/options.sh
+++ b/options.sh
@@ -46,6 +46,7 @@ protonvpn_enabled=$checkbox_unchecked
 flatseal_enabled=$checkbox_unchecked
 wireguard_enabled=$checkbox_unchecked
 remmina_enabled=$checkbox_unchecked
+mainline_enabled=$checkbox_unchecked
 swap_enabled=$checkbox_unchecked
 
 # labels
@@ -92,6 +93,7 @@ protonvpn_key="proton_vpn"
 flatseal_key="flatseal"
 wireguard_key="wireguard"
 remmina_key="remmina"
+mainline_key="mainline"
 swap_key="swap"
 
 # show text
@@ -138,4 +140,5 @@ protonvpn_label="proton-vpn"
 flatseal_label="flatseal"
 wireguard_label="wireguard"
 remmina_label="remmina"
+mainline_label="mainline kernel"
 swap_label="swap"
-- 
GitLab