Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save olealgoritme/e08c99d56201f1775e30cff8a98f3241 to your computer and use it in GitHub Desktop.

Select an option

Save olealgoritme/e08c99d56201f1775e30cff8a98f3241 to your computer and use it in GitHub Desktop.

Revisions

  1. @mdPlusPlus mdPlusPlus revised this gist Jan 20, 2019. No changes.
  2. @mdPlusPlus mdPlusPlus revised this gist Jan 20, 2019. 1 changed file with 35 additions and 7 deletions.
    42 changes: 35 additions & 7 deletions compile_newest_stable_kernel_with_acso_patch.sh
    Original file line number Diff line number Diff line change
    @@ -21,9 +21,16 @@ function init() {
    }

    function get_newest_versions() {
    stable_releases="https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/"
    stable_version=$(curl -s "${stable_releases}" | grep -E -o 'linux-([0-9]{1,}\.)+[0-9]{1,}' | sort -Vr | head -n 1 | cut -d '-' -f 2)
    stable_link="${stable_releases}linux-${stable_version}.tar.xz"
    stable_releases_3x_url="https://mirrors.edge.kernel.org/pub/linux/kernel/v3.x/"
    stable_releases_4x_url="https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/"
    stable_releases_5x_url="https://mirrors.edge.kernel.org/pub/linux/kernel/v5.x/"

    stable_releases_3x_html=$(curl -s "${stable_releases_3x_url}")
    stable_releases_4x_html=$(curl -s "${stable_releases_4x_url}")
    stable_releases_5x_html=$(curl -s "${stable_releases_5x_url}")

    stable_releases_combined_html="${stable_releases_3x_html}${stable_releases_4x_html}${stable_releases_5x_html}"
    stable_version=$(echo "${stable_releases_combined_html}" | grep -E -o 'linux-([0-9]{1,}\.)+[0-9]{1,}' | sort -Vru | head -n 1 | cut -d '-' -f 2)

    mainline_link=$(curl -s https://www.kernel.org/ | grep https://git.kernel.org/torvalds/t/linux- | grep -Po '(?<=href=")[^"]*')
    if ! [ -z "${mainline_link}" ]
    @@ -143,7 +150,27 @@ function stable_preparations() {

    kernel_version="${stable_version}"
    kernel_name="linux-${kernel_version}"



    ##Test whether the version strings starts with 3, 4, or 5 and sets the URL accordingly
    if [[ $stable_version == 5* ]]
    then
    stable_link="${stable_releases_5x_url}linux-${stable_version}.tar.xz"
    else
    if [[ $stable_version == 4* ]]
    then
    stable_link="${stable_releases_4x_url}linux-${stable_version}.tar.xz"
    else
    if [[ $stable_version == 3* ]]
    then
    stable_link="${stable_releases_3x_url}linux-${stable_version}.tar.xz"
    else
    echo "${stable_version} is not a vaild version number. Exiting."
    exit
    fi
    fi
    fi

    wget "${stable_link}"
    tar xvf "${kernel_name}.tar.xz"
    cd "${kernel_name}" || exit
    @@ -213,9 +240,9 @@ function independent_code() {
    if [ "${from_repo}" != "true" ]
    then
    ##<Ubuntu specifics>
    if [ $(lsb_release -s -d | cut -d ' ' -f 1) == "Ubuntu" ]
    if [ "$(lsb_release -s -d | cut -d ' ' -f 1)" == "Ubuntu" ]
    then
    ubuntu_codename=$(lsb_release -s -c)
    ubuntu_codename="$(lsb_release -s -c)"
    cd .. || exit
    cp -a /usr/share/kernel-package ubuntu-package
    ##error on bionic (18.04) (and probably up)
    @@ -239,7 +266,7 @@ function independent_code() {
    sudo dpkg -i ../*.deb
    if [ -z "${default}" ] || [ "${default}" == "y" ]
    then
    if [ $(lsb_release -s -d | cut -d ' ' -f 1) == "Ubuntu" ]
    if [ "$(lsb_release -s -d | cut -d ' ' -f 1)" == "Ubuntu" ]
    then
    ##removing previous commented line
    sudo sed -i -e 's/^#GRUB_DEFAULT=.*//g' "${grub_config}"
    @@ -267,3 +294,4 @@ function independent_code() {
    ##actual logic
    init
    stable_or_mainline_or_repo

  3. @mdPlusPlus mdPlusPlus revised this gist Jan 15, 2019. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions compile_newest_stable_kernel_with_acso_patch.sh
    Original file line number Diff line number Diff line change
    @@ -3,8 +3,7 @@
    function install_dependencies() {
    echo "Installing dependencies..."
    sudo apt -qq update
    sudo apt -qq install curl git wget

    sudo apt -qq install -y curl git wget
    sudo apt -qq install -y bison flex kernel-package libssl-dev
    }

  4. @mdPlusPlus mdPlusPlus revised this gist Jan 15, 2019. 1 changed file with 4 additions and 7 deletions.
    11 changes: 4 additions & 7 deletions compile_newest_stable_kernel_with_acso_patch.sh
    Original file line number Diff line number Diff line change
    @@ -5,9 +5,7 @@ function install_dependencies() {
    sudo apt -qq update
    sudo apt -qq install curl git wget

    ## Apparently this does not satisfy all package requirements
    #sudo apt -qq build-dep linux-image-generic
    sudo apt -qq install build-essential kernel-package fakeroot libncurses5-dev libssl-dev ccache
    sudo apt -qq install -y bison flex kernel-package libssl-dev
    }

    function init() {
    @@ -207,7 +205,7 @@ function independent_code() {

    yes '' | make oldconfig

    ##set xhci_hcd to load as a module instead of including it directly into the kernel
    ##set xhci_hcd to load as a module instead of including it directly into the kernel
    ##results in vfio_pci being able to grab usb controllers before xhci_hcd is able to
    sed -i -e 's/^CONFIG_USB_XHCI_HCD=y/CONFIG_USB_XHCI_HCD=m/g' .config

    @@ -229,11 +227,11 @@ function independent_code() {
    cp "ubuntu-${ubuntu_codename}/debian/control-scripts/headers-postinst" ubuntu-package/pkg/headers/
    fi
    cd "${kernel_name}" || exit
    CONCURRENCY_LEVEL=$(getconf _NPROCESSORS_ONLN) fakeroot make-kpkg --initrd --append-to-version="${kernel_localversion}" --overlay-dir=../ubuntu-package kernel_image kernel_headers kernel_source
    CONCURRENCY_LEVEL=$(getconf _NPROCESSORS_ONLN) fakeroot make-kpkg --initrd --append-to-version="${kernel_localversion}" --overlay-dir=../ubuntu-package kernel_image kernel_headers
    fi
    ##</Ubuntu specifics>
    else
    CONCURRENCY_LEVEL=$(getconf _NPROCESSORS_ONLN) fakeroot make-kpkg --initrd --append-to-version="${kernel_localversion}" kernel_image kernel_headers kernel_source
    CONCURRENCY_LEVEL=$(getconf _NPROCESSORS_ONLN) fakeroot make-kpkg --initrd --append-to-version="${kernel_localversion}" kernel_image kernel_headers
    fi


    @@ -270,4 +268,3 @@ function independent_code() {
    ##actual logic
    init
    stable_or_mainline_or_repo

  5. @mdPlusPlus mdPlusPlus revised this gist Dec 16, 2018. 1 changed file with 28 additions and 22 deletions.
    50 changes: 28 additions & 22 deletions compile_newest_stable_kernel_with_acso_patch.sh
    Original file line number Diff line number Diff line change
    @@ -36,9 +36,8 @@ function get_newest_versions() {
    mainline_version="unavailable"
    fi

    repo_string=$(apt search 'linux-source-' | grep 'linux-source' | sort -Vr | head -n 1)
    repo_pkg=$(echo "${repo_string}" | grep -E -o '^[^/]+')
    repo_version=$(echo "${repo_string}" | cut -d ' ' -f 2)
    repo_pkg=$(apt search 'linux-source-' | grep 'linux-source' | cut -d '/' -f 1 | awk -F- 'NF<=3' | sort -Vr | head -n 1)
    repo_version=$(echo "${repo_pkg}" | cut -d '-' -f 3)
    }

    function stable_or_mainline_or_repo() {
    @@ -217,21 +216,24 @@ function independent_code() {
    if [ "${from_repo}" != "true" ]
    then
    ##<Ubuntu specifics>
    ubuntu_codename=$(lsb_release -s -c)
    cd .. || exit
    cp -a /usr/share/kernel-package ubuntu-package
    ##error on bionic - cosmic not tested
    if [ "${ubuntu_codename}" != "bionic" ] && [ "${ubuntu_codename}" != "cosmic" ]
    if [ $(lsb_release -s -d | cut -d ' ' -f 1) == "Ubuntu" ]
    then
    git clone --depth=1 "git://kernel.ubuntu.com/ubuntu/ubuntu-${ubuntu_codename}.git"
    cp "ubuntu-${ubuntu_codename}/debian/control-scripts/{postinst,postrm,preinst,prerm}" ubuntu-package/pkg/image/
    cp "ubuntu-${ubuntu_codename}/debian/control-scripts/headers-postinst" ubuntu-package/pkg/headers/
    ubuntu_codename=$(lsb_release -s -c)
    cd .. || exit
    cp -a /usr/share/kernel-package ubuntu-package
    ##error on bionic (18.04) (and probably up)
    if [ $(lsb_release -s -r) -lt 18 ]
    then
    git clone --depth=1 "git://kernel.ubuntu.com/ubuntu/ubuntu-${ubuntu_codename}.git"
    cp "ubuntu-${ubuntu_codename}/debian/control-scripts/{postinst,postrm,preinst,prerm}" ubuntu-package/pkg/image/
    cp "ubuntu-${ubuntu_codename}/debian/control-scripts/headers-postinst" ubuntu-package/pkg/headers/
    fi
    cd "${kernel_name}" || exit
    CONCURRENCY_LEVEL=$(getconf _NPROCESSORS_ONLN) fakeroot make-kpkg --initrd --append-to-version="${kernel_localversion}" --overlay-dir=../ubuntu-package kernel_image kernel_headers kernel_source
    fi
    cd "${kernel_name}" || exit
    CONCURRENCY_LEVEL=$(getconf _NPROCESSORS_ONLN) fakeroot make-kpkg --initrd --append-to-version="${kernel_localversion}" --overlay-dir=../ubuntu-package kernel_image kernel_headers
    ##</Ubuntu specifics>
    else
    CONCURRENCY_LEVEL=$(getconf _NPROCESSORS_ONLN) fakeroot make-kpkg --initrd --append-to-version="${kernel_localversion}" kernel_image kernel_headers
    CONCURRENCY_LEVEL=$(getconf _NPROCESSORS_ONLN) fakeroot make-kpkg --initrd --append-to-version="${kernel_localversion}" kernel_image kernel_headers kernel_source
    fi


    @@ -240,17 +242,20 @@ function independent_code() {
    sudo dpkg -i ../*.deb
    if [ -z "${default}" ] || [ "${default}" == "y" ]
    then
    ##removing previous commented line
    sudo sed -i -e 's/^#GRUB_DEFAULT=.*//g' "${grub_config}"
    if [ $(lsb_release -s -d | cut -d ' ' -f 1) == "Ubuntu" ]
    then
    ##removing previous commented line
    sudo sed -i -e 's/^#GRUB_DEFAULT=.*//g' "${grub_config}"

    ##commenting current line
    sudo sed -i 's/^GRUB_DEFAULT=/#GRUB_DEFAULT=/' "${grub_config}"
    ##commenting current line
    sudo sed -i 's/^GRUB_DEFAULT=/#GRUB_DEFAULT=/' "${grub_config}"

    ##adding line
    grub_line="GRUB_DEFAULT=\"Advanced options for Ubuntu>Ubuntu, with Linux ${kernel_version}${kernel_localversion}\""
    sudo sed -i -e "s/^#GRUB_DEFAULT=.*/\0\n${grub_line}/" "${grub_config}"
    ##adding line
    grub_line="GRUB_DEFAULT=\"Advanced options for Ubuntu>Ubuntu, with Linux ${kernel_version}${kernel_localversion}\""
    sudo sed -i -e "s/^#GRUB_DEFAULT=.*/\0\n${grub_line}/" "${grub_config}"

    sudo update-grub
    sudo update-grub
    fi
    fi
    fi

    @@ -265,3 +270,4 @@ function independent_code() {
    ##actual logic
    init
    stable_or_mainline_or_repo

  6. @mdPlusPlus mdPlusPlus revised this gist Oct 27, 2018. 1 changed file with 60 additions and 58 deletions.
    118 changes: 60 additions & 58 deletions compile_newest_stable_kernel_with_acso_patch.sh
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,10 @@ function install_dependencies() {
    echo "Installing dependencies..."
    sudo apt -qq update
    sudo apt -qq install curl git wget
    sudo apt -qq build-dep linux-image-generic

    ## Apparently this does not satisfy all package requirements
    #sudo apt -qq build-dep linux-image-generic
    sudo apt -qq install build-essential kernel-package fakeroot libncurses5-dev libssl-dev ccache
    }

    function init() {
    @@ -15,27 +18,27 @@ function init() {

    current_dir=$(pwd)
    working_dir=$(mktemp -d)
    cd ${working_dir}
    cd "${working_dir}" || exit

    install_dependencies
    }

    function get_newest_versions() {
    stable_releases="https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/"
    stable_version=$(curl -s "${stable_releases}" | egrep -o 'linux-([0-9]{1,}\.)+[0-9]{1,}' | sort -Vr | head -n 1 | cut -d '-' -f 2)
    stable_version=$(curl -s "${stable_releases}" | grep -E -o 'linux-([0-9]{1,}\.)+[0-9]{1,}' | sort -Vr | head -n 1 | cut -d '-' -f 2)
    stable_link="${stable_releases}linux-${stable_version}.tar.xz"

    mainline_link=$(curl -s https://www.kernel.org/ | grep https://git.kernel.org/torvalds/t/linux- | grep -Po '(?<=href=")[^"]*')
    if ! [ -z ${mainline_link} ]
    if ! [ -z "${mainline_link}" ]
    then
    mainline_version=$(echo ${mainline_link} | cut -d '-' -f 2,3 | cut -d '.' -f 1,2)
    mainline_version=$(echo "${mainline_link}" | cut -d '-' -f 2,3 | cut -d '.' -f 1,2)
    else
    mainline_version="unavailable"
    fi

    repo_string=$(apt search 'linux-source-' | grep 'linux-source' | sort -Vr | head -n 1)
    repo_pkg=$(echo ${repo_string} | egrep -o '^[^/]+')
    repo_version=$(echo ${repo_string} | cut -d ' ' -f 2)
    repo_pkg=$(echo "${repo_string}" | grep -E -o '^[^/]+')
    repo_version=$(echo "${repo_string}" | cut -d ' ' -f 2)
    }

    function stable_or_mainline_or_repo() {
    @@ -44,35 +47,35 @@ function stable_or_mainline_or_repo() {
    echo "Mainline version is: ${mainline_version}"
    echo "Repository version is: ${repo_version}"
    echo -n "Do you want to get a [s]table, the newest [m]ainline release candidate or the newest kernel from your [r]epositories? [S/m/r] "
    read s_or_m_or_r
    read -r s_or_m_or_r

    echo -n "Do you want to apply the acs override patch? Kernels below 4.10 are not supported. [Y/n] "
    read acso
    read -r acso

    echo -n "Do you want to install the kernel and its headers after compilation? [Y/n] "
    read install
    read -r install

    if [ -z ${install} ] || [ ${install} == "y" ]
    if [ -z "${install}" ] || [ "${install}" == "y" ]
    then
    echo -n "Do you want to make this kernel the new default? [Y/n] "
    read default
    read -r default
    fi

    if [ -z ${s_or_m_or_r} ] || [ ${s_or_m_or_r} == "s" ]
    if [ -z "${s_or_m_or_r}" ] || [ "${s_or_m_or_r}" == "s" ]
    then
    stable_preparations
    else
    if [ ${s_or_m_or_r} == "m" ]
    if [ "${s_or_m_or_r}" == "m" ]
    then
    if [ ${mainline_version} == "unavailable" ]
    if [ "${mainline_version}" == "unavailable" ]
    then
    echo "Mainline version currently unavailable. Exiting."
    exit
    else
    mainline_preparations
    fi
    else
    if [ ${s_or_m_or_r} == "r" ]
    if [ "${s_or_m_or_r}" == "r" ]
    then
    repo_preparations
    else
    @@ -135,55 +138,55 @@ function try_acso_patch() {
    function stable_preparations() {
    echo "The newest available stable kernel version is ${stable_version}. Kernels below 4.10 are not supported."
    echo -n "Which version do you want to download? [${stable_version}] "
    read user_version
    read -r user_version

    if ! [ -z ${user_version} ]
    if ! [ -z "${user_version}" ]
    then
    stable_version=${user_version}
    stable_version="${user_version}"
    fi

    kernel_version=${stable_version}
    kernel_version="${stable_version}"
    kernel_name="linux-${kernel_version}"

    wget "${stable_link}"
    tar xvf ${kernel_name}.tar.xz
    cd ${kernel_name}
    tar xvf "${kernel_name}.tar.xz"
    cd "${kernel_name}" || exit

    independent_code
    }

    function mainline_preparations() {
    kernel_version=${mainline_version}
    kernel_version="${mainline_version}"
    kernel_name="linux-${kernel_version}"

    wget "${mainline_link}"
    tar xvf ${kernel_name}.tar.gz
    cd ${kernel_name}
    tar xvf "${kernel_name}.tar.gz"
    cd "${kernel_name}" || exit

    independent_code
    }

    function repo_preparations() {
    kernel_name=${repo_pkg}
    kernel_name="${repo_pkg}"

    sudo apt install ${repo_pkg}
    tar xvf /usr/src/${kernel_name}.tar.bz2
    cd ${kernel_name}
    sudo apt install "${repo_pkg}"
    tar xvf "/usr/src/${kernel_name}.tar.bz2"
    cd "${kernel_name}" || exit

    makefile_version=$(cat Makefile | grep "^VERSION" | tr -d '[:space:]' | cut -d '=' -f 2)
    makefile_patchlevel=$(cat Makefile | grep "^PATCHLEVEL" | tr -d '[:space:]' | cut -d '=' -f 2)
    makefile_sublevel=$(cat Makefile | grep "^SUBLEVEL" | tr -d '[:space:]' | cut -d '=' -f 2)
    #makefile_extraversion=$(cat Makefile | grep "^EXTRAVERSION" | tr -d '[:space:]' | cut -d '=' -f 2)
    makefile_version=$(grep "^VERSION" Makefile | tr -d '[:space:]' | cut -d '=' -f 2)
    makefile_patchlevel=$(grep "^PATCHLEVEL" Makefile| tr -d '[:space:]' | cut -d '=' -f 2)
    makefile_sublevel=$(grep "^SUBLEVEL" Makefile | tr -d '[:space:]' | cut -d '=' -f 2)
    #makefile_extraversion=$(grep "^EXTRAVERSION" Makefile| tr -d '[:space:]' | cut -d '=' -f 2)

    if ! [ -z ${makefile_version} ]
    if ! [ -z "${makefile_version}" ]
    then
    kernel_version=${makefile_version}
    if ! [ -z ${makefile_patchlevel} ]
    kernel_version="${makefile_version}"
    if ! [ -z "${makefile_patchlevel}" ]
    then
    kernel_version=${makefile_version}.${makefile_patchlevel}
    if ! [ -z ${makefile_sublevel} ]
    kernel_version="${makefile_version}.${makefile_patchlevel}"
    if ! [ -z "${makefile_sublevel}" ]
    then
    kernel_version=${makefile_version}.${makefile_patchlevel}.${makefile_sublevel}
    kernel_version="${makefile_version}.${makefile_patchlevel}.${makefile_sublevel}"
    fi
    fi
    fi
    @@ -196,12 +199,12 @@ function repo_preparations() {
    function independent_code() {
    kernel_localversion="-localversion"

    if [ -z ${acso} ] || [ ${acso} != "n" ]
    if [ -z "${acso}" ] || [ "${acso}" != "n" ]
    then
    try_acso_patch
    fi

    cp ${kernel_config} .config
    cp "${kernel_config}" .config

    yes '' | make oldconfig

    @@ -215,37 +218,37 @@ function independent_code() {
    then
    ##<Ubuntu specifics>
    ubuntu_codename=$(lsb_release -s -c)
    cd ..
    cd .. || exit
    cp -a /usr/share/kernel-package ubuntu-package
    ##error on bionic
    if [ "${ubuntu_codename}" != "bionic" ]
    ##error on bionic - cosmic not tested
    if [ "${ubuntu_codename}" != "bionic" ] && [ "${ubuntu_codename}" != "cosmic" ]
    then
    git clone --depth=1 git://kernel.ubuntu.com/ubuntu/ubuntu-${ubuntu_codename}.git
    cp ubuntu-${ubuntu_codename}/debian/control-scripts/{postinst,postrm,preinst,prerm} ubuntu-package/pkg/image/
    cp ubuntu-${ubuntu_codename}/debian/control-scripts/headers-postinst ubuntu-package/pkg/headers/
    git clone --depth=1 "git://kernel.ubuntu.com/ubuntu/ubuntu-${ubuntu_codename}.git"
    cp "ubuntu-${ubuntu_codename}/debian/control-scripts/{postinst,postrm,preinst,prerm}" ubuntu-package/pkg/image/
    cp "ubuntu-${ubuntu_codename}/debian/control-scripts/headers-postinst" ubuntu-package/pkg/headers/
    fi
    cd ${kernel_name}
    CONCURRENCY_LEVEL=$(getconf _NPROCESSORS_ONLN) fakeroot make-kpkg --initrd --append-to-version=${kernel_localversion} --overlay-dir=../ubuntu-package kernel_image kernel_headers
    cd "${kernel_name}" || exit
    CONCURRENCY_LEVEL=$(getconf _NPROCESSORS_ONLN) fakeroot make-kpkg --initrd --append-to-version="${kernel_localversion}" --overlay-dir=../ubuntu-package kernel_image kernel_headers
    ##</Ubuntu specifics>
    else
    CONCURRENCY_LEVEL=$(getconf _NPROCESSORS_ONLN) fakeroot make-kpkg --initrd --append-to-version=${kernel_localversion} kernel_image kernel_headers
    CONCURRENCY_LEVEL=$(getconf _NPROCESSORS_ONLN) fakeroot make-kpkg --initrd --append-to-version="${kernel_localversion}" kernel_image kernel_headers
    fi


    if [ -z ${install} ] || [ ${install} == "y" ]
    if [ -z "${install}" ] || [ "${install}" == "y" ]
    then
    sudo dpkg -i ../*.deb
    if [ -z ${default} ] || [ ${default} == "y" ]
    if [ -z "${default}" ] || [ "${default}" == "y" ]
    then
    ##removing previous commented line
    sudo sed -i -e 's/^#GRUB_DEFAULT=.*//g' ${grub_config}
    sudo sed -i -e 's/^#GRUB_DEFAULT=.*//g' "${grub_config}"

    ##commenting current line
    sudo sed -i 's/^GRUB_DEFAULT=/#GRUB_DEFAULT=/' ${grub_config}
    sudo sed -i 's/^GRUB_DEFAULT=/#GRUB_DEFAULT=/' "${grub_config}"

    ##adding line
    grub_line="GRUB_DEFAULT=\"Advanced options for Ubuntu>Ubuntu, with Linux ${kernel_version}${kernel_localversion}\""
    sudo sed -i -e "s/^#GRUB_DEFAULT=.*/\0\n${grub_line}/" ${grub_config}
    sudo sed -i -e "s/^#GRUB_DEFAULT=.*/\0\n${grub_line}/" "${grub_config}"

    sudo update-grub
    fi
    @@ -255,11 +258,10 @@ function independent_code() {



    cd ${current_dir}
    rm -rf ${working_dir}
    cd "${current_dir}" || exit
    rm -rf "${working_dir}"
    }

    ##actual logic
    init
    stable_or_mainline_or_repo

  7. @mdPlusPlus mdPlusPlus revised this gist Sep 20, 2018. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions compile_newest_stable_kernel_with_acso_patch.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    #!/bin/bash

    function install_dependencies() {
    echo "Installing dependencies..."
    sudo apt -qq update
    sudo apt -qq install curl git wget
    sudo apt -qq build-dep linux-image-generic
    @@ -203,6 +204,11 @@ function independent_code() {
    cp ${kernel_config} .config

    yes '' | make oldconfig

    ##set xhci_hcd to load as a module instead of including it directly into the kernel
    ##results in vfio_pci being able to grab usb controllers before xhci_hcd is able to
    sed -i -e 's/^CONFIG_USB_XHCI_HCD=y/CONFIG_USB_XHCI_HCD=m/g' .config

    make clean

    if [ "${from_repo}" != "true" ]
  8. @mdPlusPlus mdPlusPlus revised this gist Jun 19, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion compile_newest_stable_kernel_with_acso_patch.sh
    Original file line number Diff line number Diff line change
    @@ -83,7 +83,7 @@ function stable_or_mainline_or_repo() {
    }

    function try_acso_patch() {
    acso_patch_4_18="https://gitlab.com/Queuecumber/linux-acs-override/raw/master/workspaces/4.18/acso.patch"
    acso_patch_4_18="https://gitlab.com/Queuecumber/linux-acs-override/raw/master/workspaces/4.18/acso.patch"
    acso_patch_4_17="https://gitlab.com/Queuecumber/linux-acs-override/raw/master/workspaces/4.17/acso.patch"
    acso_patch_4_14="https://gitlab.com/Queuecumber/linux-acs-override/raw/master/workspaces/4.14/acso.patch"
    acso_patch_4_10="https://gitlab.com/Queuecumber/linux-acs-override/raw/master/workspaces/4.10/acso.patch"
  9. @mdPlusPlus mdPlusPlus revised this gist Jun 19, 2018. 1 changed file with 31 additions and 18 deletions.
    49 changes: 31 additions & 18 deletions compile_newest_stable_kernel_with_acso_patch.sh
    Original file line number Diff line number Diff line change
    @@ -83,39 +83,52 @@ function stable_or_mainline_or_repo() {
    }

    function try_acso_patch() {
    acso_patch_4_18="https://gitlab.com/Queuecumber/linux-acs-override/raw/master/workspaces/4.18/acso.patch"
    acso_patch_4_17="https://gitlab.com/Queuecumber/linux-acs-override/raw/master/workspaces/4.17/acso.patch"
    acso_patch_4_14="https://gitlab.com/Queuecumber/linux-acs-override/raw/master/workspaces/4.14/acso.patch"
    acso_patch_4_10="https://gitlab.com/Queuecumber/linux-acs-override/raw/master/workspaces/4.10/acso.patch"

    echo "Trying to apply acs override patch for 4.17+."
    wget -O ../acso_4_17.patch "${acso_patch_4_17}"
    if $(git apply --check ../acso_4_17.patch)
    echo "Trying to apply acs override patch for 4.18+."
    wget -O ../acso_4_18.patch "${acso_patch_4_18}"
    if $(git apply --check ../acso_4_18.patch)
    then
    echo "Applying acs override patch for 4.17+."
    git apply ../acso_4_17.patch
    echo "Applying acs override patch for 4.18+."
    git apply ../acso_4_18.patch
    else
    echo "Trying to apply acs override patch for 4.14+."
    wget -O ../acso_4_14.patch "${acso_patch_4_14}"
    if $(git apply --check ../acso_4_14.patch)
    echo "Trying to apply acs override patch for 4.17+."
    wget -O ../acso_4_17.patch "${acso_patch_4_17}"
    if $(git apply --check ../acso_4_17.patch)
    then
    echo "Applying acs override patch for 4.14+."
    git apply ../acso_4_14.patch
    echo "Applying acs override patch for 4.17+."
    git apply ../acso_4_17.patch
    else
    echo "Trying to apply acs override patch for 4.10+."
    wget -O ../acso_4_10.patch "${acso_patch_4_10}"
    if $(git apply --check ../acso_4_10.patch)
    echo "Trying to apply acs override patch for 4.14+."
    wget -O ../acso_4_14.patch "${acso_patch_4_14}"
    if $(git apply --check ../acso_4_14.patch)
    then
    echo "Applying acs override patch for 4.10+."
    git apply ../acso_4_10.patch
    echo "Applying acs override patch for 4.14+."
    git apply ../acso_4_14.patch
    else
    echo "[ERROR]: Failed to apply acs override patch. Exiting."
    exit
    echo "Trying to apply acs override patch for 4.10+."
    wget -O ../acso_4_10.patch "${acso_patch_4_10}"
    if $(git apply --check ../acso_4_10.patch)
    then
    echo "Applying acs override patch for 4.10+."
    git apply ../acso_4_10.patch
    else
    echo "[ERROR]: Failed to apply acs override patch. Exiting."
    exit
    fi
    rm -f ../acso_4_10.patch
    fi
    rm -f ../acso_4_14.patch
    fi
    rm -f ../acso_4_17.patch
    fi
    rm -f ../acso_4_18.patch


    kernel_localversion="-acso"
    rm -f ../acso_4_17.patch ../acso_4_14.patch ../acso_4_10.patch
    }

    function stable_preparations() {
  10. @mdPlusPlus mdPlusPlus revised this gist Jun 19, 2018. 1 changed file with 227 additions and 113 deletions.
    340 changes: 227 additions & 113 deletions compile_newest_stable_kernel_with_acso_patch.sh
    Original file line number Diff line number Diff line change
    @@ -1,132 +1,246 @@
    #!/bin/bash
    sudo apt update
    sudo apt install \
    bison \
    build-essential \
    ccache \
    curl \
    fakeroot \
    flex \
    git \
    kernel-package \
    libncurses5-dev \
    libssl-dev \
    wget


    acso_patch_4_17="https://gitlab.com/Queuecumber/linux-acs-override/raw/master/workspaces/4.17/acso.patch"
    acso_patch_4_14="https://gitlab.com/Queuecumber/linux-acs-override/raw/master/workspaces/4.14/acso.patch"
    acso_patch_4_10="https://gitlab.com/Queuecumber/linux-acs-override/raw/master/workspaces/4.10/acso.patch"
    kernel_releases="https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/"
    ##unreliable
    #kernel_releases="https://cdn.kernel.org/pub/linux/kernel/v4.x/"
    kernel_version=$(curl -s "${kernel_releases}" | egrep -o 'linux-([0-9]{1,}\.)+[0-9]{1,}' | sort -Vr | head -n 1)
    kernel_number=$(echo ${kernel_version} | cut -d '-' -f 2)


    if [ -z ${kernel_version} ]
    then
    echo "[ERROR]: Failed to access '${kernel_releases}'. Exiting."
    exit
    fi


    echo "The newest available kernel version is ${kernel_number}. Kernels below 4.10 are not supported."
    echo -n "Which version do you want to download? [${kernel_number}] "
    read user_input

    if [ ${user_input} != ${kernel_number} ]
    then
    kernel_version="linux-${user_input}"
    kernel_number=${user_input}
    fi


    ##x.y --> x.y.0
    kernel_number_expanded=${kernel_number}
    if [ $(echo "${kernel_number}" | fgrep -o . | wc -l) -lt 2 ]
    then
    kernel_number_expanded=${kernel_number}.0
    fi


    kernel_config=$(ls /boot/config-* | grep generic | sort -Vr | head -n 1)
    kernel_localversion="-acso"
    grub_config="/etc/default/grub"
    grub_line="GRUB_DEFAULT=\"Advanced options for Ubuntu>Ubuntu, with Linux ${kernel_number}-acso\""


    current_dir=$(pwd)
    working_dir=$(mktemp -d)
    cd ${working_dir}


    wget "${kernel_releases}${kernel_version}.tar.xz"
    wget -O acso_4_17.patch "${acso_patch_4_17}"
    wget -O acso_4_14.patch "${acso_patch_4_14}"
    wget -O acso_4_10.patch "${acso_patch_4_10}"
    tar xvf ${kernel_version}.tar.xz

    cd ${kernel_version}

    ##Apply acs override patch
    echo "Trying to apply acs override patch for 4.17+."
    if $(git apply --check ../acso_4_17.patch)
    then
    echo "Applying acs override patch for 4.17+."
    git apply ../acso_4_17.patch
    else
    echo "Trying to apply acs override patch for 4.14+."
    if $(git apply --check ../acso_4_14.patch)

    function install_dependencies() {
    sudo apt -qq update
    sudo apt -qq install curl git wget
    sudo apt -qq build-dep linux-image-generic
    }

    function init() {
    echo "Initializing..."

    kernel_config=$(ls /boot/config-* | grep generic | sort -Vr | head -n 1)
    grub_config="/etc/default/grub"

    current_dir=$(pwd)
    working_dir=$(mktemp -d)
    cd ${working_dir}

    install_dependencies
    }

    function get_newest_versions() {
    stable_releases="https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/"
    stable_version=$(curl -s "${stable_releases}" | egrep -o 'linux-([0-9]{1,}\.)+[0-9]{1,}' | sort -Vr | head -n 1 | cut -d '-' -f 2)
    stable_link="${stable_releases}linux-${stable_version}.tar.xz"

    mainline_link=$(curl -s https://www.kernel.org/ | grep https://git.kernel.org/torvalds/t/linux- | grep -Po '(?<=href=")[^"]*')
    if ! [ -z ${mainline_link} ]
    then
    mainline_version=$(echo ${mainline_link} | cut -d '-' -f 2,3 | cut -d '.' -f 1,2)
    else
    mainline_version="unavailable"
    fi

    repo_string=$(apt search 'linux-source-' | grep 'linux-source' | sort -Vr | head -n 1)
    repo_pkg=$(echo ${repo_string} | egrep -o '^[^/]+')
    repo_version=$(echo ${repo_string} | cut -d ' ' -f 2)
    }

    function stable_or_mainline_or_repo() {
    get_newest_versions
    echo "Newest stable version is: ${stable_version}"
    echo "Mainline version is: ${mainline_version}"
    echo "Repository version is: ${repo_version}"
    echo -n "Do you want to get a [s]table, the newest [m]ainline release candidate or the newest kernel from your [r]epositories? [S/m/r] "
    read s_or_m_or_r

    echo -n "Do you want to apply the acs override patch? Kernels below 4.10 are not supported. [Y/n] "
    read acso

    echo -n "Do you want to install the kernel and its headers after compilation? [Y/n] "
    read install

    if [ -z ${install} ] || [ ${install} == "y" ]
    then
    echo "Applying acs override patch for 4.14+."
    git apply ../acso_4_14.patch
    echo -n "Do you want to make this kernel the new default? [Y/n] "
    read default
    fi

    if [ -z ${s_or_m_or_r} ] || [ ${s_or_m_or_r} == "s" ]
    then
    stable_preparations
    else
    echo "Trying to apply acs override patch for 4.10+."
    if $(git apply --check ../acso_4_10.patch)
    if [ ${s_or_m_or_r} == "m" ]
    then
    echo "Applying acs override patch for 4.10+."
    git apply ../acso_4_10.patch
    if [ ${mainline_version} == "unavailable" ]
    then
    echo "Mainline version currently unavailable. Exiting."
    exit
    else
    mainline_preparations
    fi
    else
    echo "[ERROR]: Failed to apply acs override patch. Exiting."
    exit
    if [ ${s_or_m_or_r} == "r" ]
    then
    repo_preparations
    else
    echo "Not a valid option. Exiting."
    exit
    fi
    fi
    fi
    }

    function try_acso_patch() {
    acso_patch_4_17="https://gitlab.com/Queuecumber/linux-acs-override/raw/master/workspaces/4.17/acso.patch"
    acso_patch_4_14="https://gitlab.com/Queuecumber/linux-acs-override/raw/master/workspaces/4.14/acso.patch"
    acso_patch_4_10="https://gitlab.com/Queuecumber/linux-acs-override/raw/master/workspaces/4.10/acso.patch"

    echo "Trying to apply acs override patch for 4.17+."
    wget -O ../acso_4_17.patch "${acso_patch_4_17}"
    if $(git apply --check ../acso_4_17.patch)
    then
    echo "Applying acs override patch for 4.17+."
    git apply ../acso_4_17.patch
    else
    echo "Trying to apply acs override patch for 4.14+."
    wget -O ../acso_4_14.patch "${acso_patch_4_14}"
    if $(git apply --check ../acso_4_14.patch)
    then
    echo "Applying acs override patch for 4.14+."
    git apply ../acso_4_14.patch
    else
    echo "Trying to apply acs override patch for 4.10+."
    wget -O ../acso_4_10.patch "${acso_patch_4_10}"
    if $(git apply --check ../acso_4_10.patch)
    then
    echo "Applying acs override patch for 4.10+."
    git apply ../acso_4_10.patch
    else
    echo "[ERROR]: Failed to apply acs override patch. Exiting."
    exit
    fi
    fi
    fi

    kernel_localversion="-acso"
    rm -f ../acso_4_17.patch ../acso_4_14.patch ../acso_4_10.patch
    }

    function stable_preparations() {
    echo "The newest available stable kernel version is ${stable_version}. Kernels below 4.10 are not supported."
    echo -n "Which version do you want to download? [${stable_version}] "
    read user_version

    if ! [ -z ${user_version} ]
    then
    stable_version=${user_version}
    fi

    kernel_version=${stable_version}
    kernel_name="linux-${kernel_version}"

    wget "${stable_link}"
    tar xvf ${kernel_name}.tar.xz
    cd ${kernel_name}

    independent_code
    }

    function mainline_preparations() {
    kernel_version=${mainline_version}
    kernel_name="linux-${kernel_version}"

    wget "${mainline_link}"
    tar xvf ${kernel_name}.tar.gz
    cd ${kernel_name}

    independent_code
    }

    function repo_preparations() {
    kernel_name=${repo_pkg}

    sudo apt install ${repo_pkg}
    tar xvf /usr/src/${kernel_name}.tar.bz2
    cd ${kernel_name}

    makefile_version=$(cat Makefile | grep "^VERSION" | tr -d '[:space:]' | cut -d '=' -f 2)
    makefile_patchlevel=$(cat Makefile | grep "^PATCHLEVEL" | tr -d '[:space:]' | cut -d '=' -f 2)
    makefile_sublevel=$(cat Makefile | grep "^SUBLEVEL" | tr -d '[:space:]' | cut -d '=' -f 2)
    #makefile_extraversion=$(cat Makefile | grep "^EXTRAVERSION" | tr -d '[:space:]' | cut -d '=' -f 2)

    if ! [ -z ${makefile_version} ]
    then
    kernel_version=${makefile_version}
    if ! [ -z ${makefile_patchlevel} ]
    then
    kernel_version=${makefile_version}.${makefile_patchlevel}
    if ! [ -z ${makefile_sublevel} ]
    then
    kernel_version=${makefile_version}.${makefile_patchlevel}.${makefile_sublevel}
    fi
    fi
    fi
    fi

    from_repo="true"

    independent_code
    }

    function independent_code() {
    kernel_localversion="-localversion"

    if [ -z ${acso} ] || [ ${acso} != "n" ]
    then
    try_acso_patch
    fi

    cp ${kernel_config} .config

    yes '' | make oldconfig
    make clean

    cp ${kernel_config} .config
    if [ "${from_repo}" != "true" ]
    then
    ##<Ubuntu specifics>
    ubuntu_codename=$(lsb_release -s -c)
    cd ..
    cp -a /usr/share/kernel-package ubuntu-package
    ##error on bionic
    if [ "${ubuntu_codename}" != "bionic" ]
    then
    git clone --depth=1 git://kernel.ubuntu.com/ubuntu/ubuntu-${ubuntu_codename}.git
    cp ubuntu-${ubuntu_codename}/debian/control-scripts/{postinst,postrm,preinst,prerm} ubuntu-package/pkg/image/
    cp ubuntu-${ubuntu_codename}/debian/control-scripts/headers-postinst ubuntu-package/pkg/headers/
    fi
    cd ${kernel_name}
    CONCURRENCY_LEVEL=$(getconf _NPROCESSORS_ONLN) fakeroot make-kpkg --initrd --append-to-version=${kernel_localversion} --overlay-dir=../ubuntu-package kernel_image kernel_headers
    ##</Ubuntu specifics>
    else
    CONCURRENCY_LEVEL=$(getconf _NPROCESSORS_ONLN) fakeroot make-kpkg --initrd --append-to-version=${kernel_localversion} kernel_image kernel_headers
    fi

    yes '' | make oldconfig
    make clean

    if [ -z ${install} ] || [ ${install} == "y" ]
    then
    sudo dpkg -i ../*.deb
    if [ -z ${default} ] || [ ${default} == "y" ]
    then
    ##removing previous commented line
    sudo sed -i -e 's/^#GRUB_DEFAULT=.*//g' ${grub_config}

    ##<Ubuntu specifics>
    ubuntu_codename=$(lsb_release -s -c)
    cd ..
    git clone --depth=1 git://kernel.ubuntu.com/ubuntu/ubuntu-${ubuntu_codename}.git
    cp -a /usr/share/kernel-package ubuntu-package
    cp ubuntu-${ubuntu_codename}/debian/control-scripts/{postinst,postrm,preinst,prerm} ubuntu-package/pkg/image/
    cp ubuntu-${ubuntu_codename}/debian/control-scripts/headers-postinst ubuntu-package/pkg/headers/
    cd ${kernel_version}
    CONCURRENCY_LEVEL=$(getconf _NPROCESSORS_ONLN) fakeroot make-kpkg --initrd --append-to-version=${kernel_localversion} --overlay-dir=../ubuntu-package kernel_image kernel_headers
    ##</Ubuntu specifics>
    ##commenting current line
    sudo sed -i 's/^GRUB_DEFAULT=/#GRUB_DEFAULT=/' ${grub_config}

    ##non-Ubuntu
    #make -j $(getconf _NPROCESSORS_ONLN) deb-pkg LOCALVERSION=${kernel_localversion}
    ##adding line
    grub_line="GRUB_DEFAULT=\"Advanced options for Ubuntu>Ubuntu, with Linux ${kernel_version}${kernel_localversion}\""
    sudo sed -i -e "s/^#GRUB_DEFAULT=.*/\0\n${grub_line}/" ${grub_config}

    sudo dpkg -i $(ls ../linux-image-${kernel_number_expanded}${kernel_localversion}_*) $(ls ../linux-headers-${kernel_number_expanded}${kernel_localversion}_*)
    sudo update-grub
    fi
    fi

    ##removing previous commented line
    sudo sed -i -e 's/^#GRUB_DEFAULT=.*//g' ${grub_config}

    ##commenting current line
    sudo sed -i 's/^GRUB_DEFAULT=/#GRUB_DEFAULT=/' ${grub_config}


    ##adding line
    sudo sed -i -e "s/^#GRUB_DEFAULT=.*/\0\n${grub_line}/" ${grub_config}

    sudo update-grub
    cd ${current_dir}
    rm -rf ${working_dir}
    }

    ##actual logic
    init
    stable_or_mainline_or_repo

    cd ${current_dir}
    rm -rf ${working_dir}
  11. @mdPlusPlus mdPlusPlus revised this gist Apr 22, 2018. 1 changed file with 68 additions and 41 deletions.
    109 changes: 68 additions & 41 deletions compile_newest_stable_kernel_with_acso_patch.sh
    Original file line number Diff line number Diff line change
    @@ -14,17 +14,15 @@ sudo apt install \
    wget


    acso_patch="https://gist.github.com/mdPlusPlus/5f276e26a2495d711d22d95a6d96517f/raw/90770d1541aa77e9e216f8b902bf55bf06ce64e5/acso.patch"
    acso_patch_4_17="https://gitlab.com/Queuecumber/linux-acs-override/raw/master/workspaces/4.17/acso.patch"
    acso_patch_4_14="https://gitlab.com/Queuecumber/linux-acs-override/raw/master/workspaces/4.14/acso.patch"
    acso_patch_4_10="https://gitlab.com/Queuecumber/linux-acs-override/raw/master/workspaces/4.10/acso.patch"
    kernel_releases="https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/"
    ##unreliable
    #kernel_releases="https://cdn.kernel.org/pub/linux/kernel/v4.x/"
    kernel_version=$(curl -s "${kernel_releases}" | egrep -o 'linux-([0-9]{1,}\.)+[0-9]{1,}' | sort -Vr | head -n 1)
    kernel_localversion="-acso"
    kernel_number=$(echo ${kernel_version} | cut -d '-' -f 2)

    kernel_config=$(ls /boot/config-* | grep generic | sort -Vr | head -n 1)
    grub_config="/etc/default/grub"


    if [ -z ${kernel_version} ]
    then
    @@ -33,7 +31,7 @@ then
    fi


    echo "The newest available kernel version is ${kernel_version}"
    echo "The newest available kernel version is ${kernel_number}. Kernels below 4.10 are not supported."
    echo -n "Which version do you want to download? [${kernel_number}] "
    read user_input

    @@ -52,54 +50,83 @@ then
    fi


    kernel_config=$(ls /boot/config-* | grep generic | sort -Vr | head -n 1)
    kernel_localversion="-acso"
    grub_config="/etc/default/grub"
    grub_line="GRUB_DEFAULT=\"Advanced options for Ubuntu>Ubuntu, with Linux ${kernel_number}-acso\""


    current_dir=$(pwd)
    working_dir=$(mktemp -d)
    cd ${working_dir}


    wget "${kernel_releases}${kernel_version}.tar.xz"
    wget -O acso.patch "${acso_patch}"
    wget -O acso_4_17.patch "${acso_patch_4_17}"
    wget -O acso_4_14.patch "${acso_patch_4_14}"
    wget -O acso_4_10.patch "${acso_patch_4_10}"
    tar xvf ${kernel_version}.tar.xz

    cd ${kernel_version}

    if $(git apply --check ../acso.patch)
    ##Apply acs override patch
    echo "Trying to apply acs override patch for 4.17+."
    if $(git apply --check ../acso_4_17.patch)
    then
    git apply ../acso.patch
    cp ${kernel_config} .config

    yes '' | make oldconfig
    make clean

    ##<Ubuntu specifics>
    ubuntu_codename=$(lsb_release -s -c)
    cd ..
    git clone --depth=1 git://kernel.ubuntu.com/ubuntu/ubuntu-${ubuntu_codename}.git
    cp -a /usr/share/kernel-package ubuntu-package
    cp ubuntu-${ubuntu_codename}/debian/control-scripts/{postinst,postrm,preinst,prerm} ubuntu-package/pkg/image/
    cp ubuntu-${ubuntu_codename}/debian/control-scripts/headers-postinst ubuntu-package/pkg/headers/
    cd ${kernel_version}
    CONCURRENCY_LEVEL=$(getconf _NPROCESSORS_ONLN) fakeroot make-kpkg --initrd --append-to-version=${kernel_localversion} --overlay-dir=../ubuntu-package kernel_image kernel_headers
    ##</Ubuntu specifics>

    ##non-Ubuntu
    #make -j $(getconf _NPROCESSORS_ONLN) deb-pkg LOCALVERSION=${kernel_localversion}

    sudo dpkg -i $(ls ../linux-image-${kernel_number_expanded}${kernel_localversion}_*) $(ls ../linux-headers-${kernel_number_expanded}${kernel_localversion}_*)

    ##removing previous commented line
    sudo sed -i -e 's/^#GRUB_DEFAULT=.*//g' ${grub_config}

    ##commenting current line
    sudo sed -i 's/^GRUB_DEFAULT=/#GRUB_DEFAULT=/' ${grub_config}

    ##adding line
    grub_line="GRUB_DEFAULT=\"Advanced options for Ubuntu>Ubuntu, with Linux ${kernel_number}-acso\""
    sudo sed -i -e "s/^#GRUB_DEFAULT=.*/\0\n${grub_line}/" ${grub_config}

    sudo update-grub
    echo "Applying acs override patch for 4.17+."
    git apply ../acso_4_17.patch
    else
    echo "Trying to apply acs override patch for 4.14+."
    if $(git apply --check ../acso_4_14.patch)
    then
    echo "Applying acs override patch for 4.14+."
    git apply ../acso_4_14.patch
    else
    echo "Trying to apply acs override patch for 4.10+."
    if $(git apply --check ../acso_4_10.patch)
    then
    echo "Applying acs override patch for 4.10+."
    git apply ../acso_4_10.patch
    else
    echo "[ERROR]: Failed to apply acs override patch. Exiting."
    exit
    fi
    fi
    fi


    cp ${kernel_config} .config

    yes '' | make oldconfig
    make clean

    ##<Ubuntu specifics>
    ubuntu_codename=$(lsb_release -s -c)
    cd ..
    git clone --depth=1 git://kernel.ubuntu.com/ubuntu/ubuntu-${ubuntu_codename}.git
    cp -a /usr/share/kernel-package ubuntu-package
    cp ubuntu-${ubuntu_codename}/debian/control-scripts/{postinst,postrm,preinst,prerm} ubuntu-package/pkg/image/
    cp ubuntu-${ubuntu_codename}/debian/control-scripts/headers-postinst ubuntu-package/pkg/headers/
    cd ${kernel_version}
    CONCURRENCY_LEVEL=$(getconf _NPROCESSORS_ONLN) fakeroot make-kpkg --initrd --append-to-version=${kernel_localversion} --overlay-dir=../ubuntu-package kernel_image kernel_headers
    ##</Ubuntu specifics>

    ##non-Ubuntu
    #make -j $(getconf _NPROCESSORS_ONLN) deb-pkg LOCALVERSION=${kernel_localversion}

    sudo dpkg -i $(ls ../linux-image-${kernel_number_expanded}${kernel_localversion}_*) $(ls ../linux-headers-${kernel_number_expanded}${kernel_localversion}_*)

    ##removing previous commented line
    sudo sed -i -e 's/^#GRUB_DEFAULT=.*//g' ${grub_config}

    ##commenting current line
    sudo sed -i 's/^GRUB_DEFAULT=/#GRUB_DEFAULT=/' ${grub_config}

    ##adding line
    sudo sed -i -e "s/^#GRUB_DEFAULT=.*/\0\n${grub_line}/" ${grub_config}

    sudo update-grub


    cd ${current_dir}
    rm -rf ${working_dir}
  12. @mdPlusPlus mdPlusPlus revised this gist Apr 21, 2018. 1 changed file with 35 additions and 14 deletions.
    49 changes: 35 additions & 14 deletions compile_newest_stable_kernel_with_acso_patch.sh
    Original file line number Diff line number Diff line change
    @@ -15,26 +15,52 @@ sudo apt install \


    acso_patch="https://gist.github.com/mdPlusPlus/5f276e26a2495d711d22d95a6d96517f/raw/90770d1541aa77e9e216f8b902bf55bf06ce64e5/acso.patch"
    kernel_releases="https://cdn.kernel.org/pub/linux/kernel/v4.x/"
    kernel_releases="https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/"
    ##unreliable
    #kernel_releases="https://cdn.kernel.org/pub/linux/kernel/v4.x/"
    kernel_version=$(curl -s "${kernel_releases}" | egrep -o 'linux-([0-9]{1,}\.)+[0-9]{1,}' | sort -Vr | head -n 1)
    kernel_localversion="-acso"
    kernel_number=$(echo ${kernel_version} | cut -d '-' -f 2)
    kernel_number_expanded=${kernel_number}

    kernel_config=$(ls /boot/config-* | grep generic | sort -Vr | head -n 1)
    grub_config="/etc/default/grub"


    if [ -z ${kernel_version} ]
    then
    echo "[ERROR]: Failed to access '${kernel_releases}'. Exiting."
    exit
    fi


    echo "The newest available kernel version is ${kernel_version}"
    echo -n "Which version do you want to download? [${kernel_number}] "
    read user_input

    if [ ${user_input} != ${kernel_number} ]
    then
    kernel_version="linux-${user_input}"
    kernel_number=${user_input}
    fi


    ##x.y --> x.y.0
    kernel_number_expanded=${kernel_number}
    if [ $(echo "${kernel_number}" | fgrep -o . | wc -l) -lt 2 ]
    then
    kernel_number_expanded=${kernel_number}.0
    fi

    kernel_config=$(ls /boot/config-* | grep generic | sort -Vr | head -n 1)
    grub_config="/etc/default/grub"

    current_dir=$(pwd)
    working_dir=$(mktemp -d)
    cd ${working_dir}


    wget "${kernel_releases}${kernel_version}.tar.xz"
    wget -O acso.patch "${acso_patch}"
    tar xvf ${kernel_version}.tar.xz


    cd ${kernel_version}

    if $(git apply --check ../acso.patch)
    @@ -48,14 +74,12 @@ then
    ##<Ubuntu specifics>
    ubuntu_codename=$(lsb_release -s -c)
    cd ..
    git clone git://kernel.ubuntu.com/ubuntu/ubuntu-${ubuntu_codename}.git
    git clone --depth=1 git://kernel.ubuntu.com/ubuntu/ubuntu-${ubuntu_codename}.git
    cp -a /usr/share/kernel-package ubuntu-package
    cp ubuntu-${ubuntu_codename}/debian/control-scripts/{postinst,postrm,preinst,prerm} ubuntu-package/pkg/image/
    cp ubuntu-${ubuntu_codename}/debian/control-scripts/headers-postinst ubuntu-package/pkg/headers/
    cd ${kernel_version}
    CONCURRENCY_LEVEL=`getconf _NPROCESSORS_ONLN` fakeroot make-kpkg --initrd --append-to-version=${kernel_localversion} --overlay-dir=../ubuntu-package kernel_image kernel_headers
    rm -r ../ubuntu-package
    rm -rf ../ubuntu-${ubuntu_codename}
    CONCURRENCY_LEVEL=$(getconf _NPROCESSORS_ONLN) fakeroot make-kpkg --initrd --append-to-version=${kernel_localversion} --overlay-dir=../ubuntu-package kernel_image kernel_headers
    ##</Ubuntu specifics>

    ##non-Ubuntu
    @@ -76,9 +100,6 @@ then
    sudo update-grub
    fi

    cd ..

    rm -r *${kernel_number_expanded}${kernel_localversion}*
    rm acso.patch
    rm -r ${kernel_version}
    rm ${kernel_version}.tar.xz
    cd ${current_dir}
    rm -rf ${working_dir}
  13. @mdPlusPlus mdPlusPlus revised this gist Apr 9, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion compile_newest_stable_kernel_with_acso_patch.sh
    Original file line number Diff line number Diff line change
    @@ -61,7 +61,7 @@ then
    ##non-Ubuntu
    #make -j $(getconf _NPROCESSORS_ONLN) deb-pkg LOCALVERSION=${kernel_localversion}

    sudo dpkg -i $(ls ../linux-image-${kernel_number_expanded}${kernel_localversion}_*") $(ls ../linux-headers-${kernel_number_expanded}${kernel_localversion}_*")
    sudo dpkg -i $(ls ../linux-image-${kernel_number_expanded}${kernel_localversion}_*) $(ls ../linux-headers-${kernel_number_expanded}${kernel_localversion}_*)

    ##removing previous commented line
    sudo sed -i -e 's/^#GRUB_DEFAULT=.*//g' ${grub_config}
  14. @mdPlusPlus mdPlusPlus revised this gist Apr 2, 2018. 1 changed file with 33 additions and 4 deletions.
    37 changes: 33 additions & 4 deletions compile_newest_stable_kernel_with_acso_patch.sh
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,20 @@
    #!/bin/bash
    sudo apt update
    sudo apt install \
    bison \
    build-essential \
    ccache \
    curl \
    fakeroot \
    flex \
    git \
    kernel-package \
    libncurses5-dev \
    libssl-dev \
    wget


    acso_patch="https://gist.github.com/mdPlusPlus/5f276e26a2495d711d22d95a6d96517f/raw/90770d1541aa77e9e216f8b902bf55bf06ce64e5/acso.patch"
    kernel_releases="https://cdn.kernel.org/pub/linux/kernel/v4.x/"
    kernel_version=$(curl -s "${kernel_releases}" | egrep -o 'linux-([0-9]{1,}\.)+[0-9]{1,}' | sort -Vr | head -n 1)
    kernel_localversion="-acso"
    @@ -11,16 +27,14 @@ then
    kernel_number_expanded=${kernel_number}.0
    fi

    acso_patch="https://gist.github.com/mdPlusPlus/5f276e26a2495d711d22d95a6d96517f/raw/90770d1541aa77e9e216f8b902bf55bf06ce64e5/acso.patch"

    kernel_config=$(ls /boot/config-* | grep generic | sort -Vr | head -n 1)

    grub_config="/etc/default/grub"

    wget "${kernel_releases}${kernel_version}.tar.xz"
    wget -O acso.patch "${acso_patch}"
    tar xvf ${kernel_version}.tar.xz


    cd ${kernel_version}

    if $(git apply --check ../acso.patch)
    @@ -30,7 +44,22 @@ then

    yes '' | make oldconfig
    make clean
    make -j $(getconf _NPROCESSORS_ONLN) deb-pkg LOCALVERSION=${kernel_localversion}

    ##<Ubuntu specifics>
    ubuntu_codename=$(lsb_release -s -c)
    cd ..
    git clone git://kernel.ubuntu.com/ubuntu/ubuntu-${ubuntu_codename}.git
    cp -a /usr/share/kernel-package ubuntu-package
    cp ubuntu-${ubuntu_codename}/debian/control-scripts/{postinst,postrm,preinst,prerm} ubuntu-package/pkg/image/
    cp ubuntu-${ubuntu_codename}/debian/control-scripts/headers-postinst ubuntu-package/pkg/headers/
    cd ${kernel_version}
    CONCURRENCY_LEVEL=`getconf _NPROCESSORS_ONLN` fakeroot make-kpkg --initrd --append-to-version=${kernel_localversion} --overlay-dir=../ubuntu-package kernel_image kernel_headers
    rm -r ../ubuntu-package
    rm -rf ../ubuntu-${ubuntu_codename}
    ##</Ubuntu specifics>

    ##non-Ubuntu
    #make -j $(getconf _NPROCESSORS_ONLN) deb-pkg LOCALVERSION=${kernel_localversion}

    sudo dpkg -i $(ls ../linux-image-${kernel_number_expanded}${kernel_localversion}_*") $(ls ../linux-headers-${kernel_number_expanded}${kernel_localversion}_*")
  15. @mdPlusPlus mdPlusPlus revised this gist Apr 2, 2018. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions compile_newest_stable_kernel_with_acso_patch.sh
    Original file line number Diff line number Diff line change
    @@ -11,8 +11,6 @@ then
    kernel_number_expanded=${kernel_number}.0
    fi

    echo ${kernel_number_expanded}

    acso_patch="https://gist.github.com/mdPlusPlus/5f276e26a2495d711d22d95a6d96517f/raw/90770d1541aa77e9e216f8b902bf55bf06ce64e5/acso.patch"

    kernel_config=$(ls /boot/config-* | grep generic | sort -Vr | head -n 1)
  16. @mdPlusPlus mdPlusPlus revised this gist Apr 2, 2018. 1 changed file with 11 additions and 2 deletions.
    13 changes: 11 additions & 2 deletions compile_newest_stable_kernel_with_acso_patch.sh
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,15 @@ kernel_releases="https://cdn.kernel.org/pub/linux/kernel/v4.x/"
    kernel_version=$(curl -s "${kernel_releases}" | egrep -o 'linux-([0-9]{1,}\.)+[0-9]{1,}' | sort -Vr | head -n 1)
    kernel_localversion="-acso"
    kernel_number=$(echo ${kernel_version} | cut -d '-' -f 2)
    kernel_number_expanded=${kernel_number}

    ##x.y --> x.y.0
    if [ $(echo "${kernel_number}" | fgrep -o . | wc -l) -lt 2 ]
    then
    kernel_number_expanded=${kernel_number}.0
    fi

    echo ${kernel_number_expanded}

    acso_patch="https://gist.github.com/mdPlusPlus/5f276e26a2495d711d22d95a6d96517f/raw/90770d1541aa77e9e216f8b902bf55bf06ce64e5/acso.patch"

    @@ -25,7 +34,7 @@ then
    make clean
    make -j $(getconf _NPROCESSORS_ONLN) deb-pkg LOCALVERSION=${kernel_localversion}

    sudo dpkg -i $(ls ../linux-image-${kernel_number}${kernel_localversion}_*) $(ls ../linux-headers-${kernel_number}${kernel_localversion}_*)
    sudo dpkg -i $(ls ../linux-image-${kernel_number_expanded}${kernel_localversion}_*") $(ls ../linux-headers-${kernel_number_expanded}${kernel_localversion}_*")
    ##removing previous commented line
    sudo sed -i -e 's/^#GRUB_DEFAULT=.*//g' ${grub_config}
    @@ -42,7 +51,7 @@ fi
    cd ..
    rm -r *${kernel_number}${kernel_localversion}*
    rm -r *${kernel_number_expanded}${kernel_localversion}*
    rm acso.patch
    rm -r ${kernel_version}
    rm ${kernel_version}.tar.xz
  17. @mdPlusPlus mdPlusPlus revised this gist Apr 2, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion compile_newest_stable_kernel_with_acso_patch.sh
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,7 @@ cd ${kernel_version}
    if $(git apply --check ../acso.patch)
    then
    git apply ../acso.patch
    cp $kernel_config .config
    cp ${kernel_config} .config

    yes '' | make oldconfig
    make clean
  18. @mdPlusPlus mdPlusPlus revised this gist Apr 2, 2018. 1 changed file with 18 additions and 3 deletions.
    21 changes: 18 additions & 3 deletions compile_newest_stable_kernel_with_acso_patch.sh
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,15 @@
    #!/bin/bash
    kernel_releases="https://cdn.kernel.org/pub/linux/kernel/v4.x/"
    kernel_version=$(curl -s4 "${kernel_releases}" | grep -oP 'linux-[0-9]+\.[0-9]+\.[0-9]+' | sort -Vr | head -n 1)
    kernel_version=$(curl -s "${kernel_releases}" | egrep -o 'linux-([0-9]{1,}\.)+[0-9]{1,}' | sort -Vr | head -n 1)
    kernel_localversion="-acso"
    kernel_number=$(echo ${kernel_version} | cut -d '-' -f 2)

    acso_patch="https://gist.github.com/mdPlusPlus/5f276e26a2495d711d22d95a6d96517f/raw/90770d1541aa77e9e216f8b902bf55bf06ce64e5/acso.patch"

    kernel_config=$(ls /boot/config-* | grep generic | sort -Vr | head -n 1)

    grub_config="/etc/default/grub"

    wget "${kernel_releases}${kernel_version}.tar.xz"
    wget -O acso.patch "${acso_patch}"
    tar xvf ${kernel_version}.tar.xz
    @@ -18,15 +20,28 @@ if $(git apply --check ../acso.patch)
    then
    git apply ../acso.patch
    cp $kernel_config .config

    yes '' | make oldconfig
    make clean
    make -j $(getconf _NPROCESSORS_ONLN) deb-pkg LOCALVERSION=${kernel_localversion}

    sudo dpkg -i $(ls ../linux-image-${kernel_number}${kernel_localversion}_*) $(ls ../linux-headers-${kernel_number}${kernel_localversion}_*)

    ##removing previous commented line
    sudo sed -i -e 's/^#GRUB_DEFAULT=.*//g' ${grub_config}

    ##commenting current line
    sudo sed -i 's/^GRUB_DEFAULT=/#GRUB_DEFAULT=/' ${grub_config}

    ##adding line
    grub_line="GRUB_DEFAULT=\"Advanced options for Ubuntu>Ubuntu, with Linux ${kernel_number}-acso\""
    sudo sed -i -e "s/^#GRUB_DEFAULT=.*/\0\n${grub_line}/" ${grub_config}

    sudo update-grub
    fi

    cd ..

    sudo dpkg -i $(ls linux-image-${kernel_number}${kernel_localversion}_*) $(ls linux-headers-${kernel_number}${kernel_localversion}_*)

    rm -r *${kernel_number}${kernel_localversion}*
    rm acso.patch
    rm -r ${kernel_version}
  19. @mdPlusPlus mdPlusPlus revised this gist Mar 29, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion compile_newest_stable_kernel_with_acso_patch.sh
    Original file line number Diff line number Diff line change
    @@ -20,7 +20,7 @@ then
    cp $kernel_config .config
    yes '' | make oldconfig
    make clean
    make -j $(getconf _NPROCESSORS_ONLN) deb-pkg LOCALVERSION={$kernel_localversion}
    make -j $(getconf _NPROCESSORS_ONLN) deb-pkg LOCALVERSION=${kernel_localversion}
    fi

    cd ..
  20. @mdPlusPlus mdPlusPlus revised this gist Mar 29, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion compile_newest_stable_kernel_with_acso_patch.sh
    Original file line number Diff line number Diff line change
    @@ -20,7 +20,7 @@ then
    cp $kernel_config .config
    yes '' | make oldconfig
    make clean
    make -j $(getconf _NPROCESSORS_ONLN) deb-pkg LOCALVERSION=$kernel_localversion
    make -j $(getconf _NPROCESSORS_ONLN) deb-pkg LOCALVERSION={$kernel_localversion}
    fi

    cd ..
  21. @mdPlusPlus mdPlusPlus revised this gist Mar 29, 2018. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion compile_newest_stable_kernel_with_acso_patch.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,8 @@
    #!/bin/bash
    kernel_releases="https://cdn.kernel.org/pub/linux/kernel/v4.x/"
    kernel_version=$(curl -s4 "${kernel_releases}" | grep -oP 'linux-[0-9]+\.[0-9]+\.[0-9]+' | sort -Vr | head -n 1)
    kernel_localversion="-acso"
    kernel_number=$(echo ${kernel_version} | cut -d '-' -f 2)

    acso_patch="https://gist.github.com/mdPlusPlus/5f276e26a2495d711d22d95a6d96517f/raw/90770d1541aa77e9e216f8b902bf55bf06ce64e5/acso.patch"

    @@ -18,11 +20,14 @@ then
    cp $kernel_config .config
    yes '' | make oldconfig
    make clean
    make -j `getconf _NPROCESSORS_ONLN` deb-pkg LOCALVERSION=-acso
    make -j $(getconf _NPROCESSORS_ONLN) deb-pkg LOCALVERSION=$kernel_localversion
    fi

    cd ..

    sudo dpkg -i $(ls linux-image-${kernel_number}${kernel_localversion}_*) $(ls linux-headers-${kernel_number}${kernel_localversion}_*)

    rm -r *${kernel_number}${kernel_localversion}*
    rm acso.patch
    rm -r ${kernel_version}
    rm ${kernel_version}.tar.xz
  22. @mdPlusPlus mdPlusPlus created this gist Mar 29, 2018.
    28 changes: 28 additions & 0 deletions compile_newest_stable_kernel_with_acso_patch.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    #!/bin/bash
    kernel_releases="https://cdn.kernel.org/pub/linux/kernel/v4.x/"
    kernel_version=$(curl -s4 "${kernel_releases}" | grep -oP 'linux-[0-9]+\.[0-9]+\.[0-9]+' | sort -Vr | head -n 1)

    acso_patch="https://gist.github.com/mdPlusPlus/5f276e26a2495d711d22d95a6d96517f/raw/90770d1541aa77e9e216f8b902bf55bf06ce64e5/acso.patch"

    kernel_config=$(ls /boot/config-* | grep generic | sort -Vr | head -n 1)

    wget "${kernel_releases}${kernel_version}.tar.xz"
    wget -O acso.patch "${acso_patch}"
    tar xvf ${kernel_version}.tar.xz

    cd ${kernel_version}

    if $(git apply --check ../acso.patch)
    then
    git apply ../acso.patch
    cp $kernel_config .config
    yes '' | make oldconfig
    make clean
    make -j `getconf _NPROCESSORS_ONLN` deb-pkg LOCALVERSION=-acso
    fi

    cd ..

    rm acso.patch
    rm -r ${kernel_version}
    rm ${kernel_version}.tar.xz