diff --git a/linux57-tkg/PKGBUILD b/linux57-tkg/PKGBUILD index fd4aeb1..b443e42 100644 --- a/linux57-tkg/PKGBUILD +++ b/linux57-tkg/PKGBUILD @@ -30,6 +30,8 @@ source "$_where"/linux*-tkg-config/prepare _tkg_initscript +_distro="Arch" + if [ -n "$_custom_pkgbase" ]; then pkgbase="${_custom_pkgbase}" else diff --git a/linux57-tkg/README.md b/linux57-tkg/README.md index 2c194ae..322b4fe 100644 --- a/linux57-tkg/README.md +++ b/linux57-tkg/README.md @@ -39,27 +39,27 @@ You can enable support for it at the beginning of the PKGBUILD file. Make sure t ``` git clone https://github.com/Frogging-Family/linux-tkg.git cd linux-tkg/linux57-tkg -# Edit customization.cfg file +# Optional: edit customization.cfg file makepkg -si ``` -### Ubuntu & derivatives +### Fedora, Ubuntu and derivatives ``` git clone https://github.com/Frogging-Family/linux-tkg.git cd linux-tkg/linux57-tkg -# Edit customization.cfg file to at least set _distro to "Ubuntu" +# Optional: edit customization.cfg file ./install.sh install ``` -To uninstall custom kernels installed through the script: +Uninstalling custom kernels installed through the script has to be done +manually, the script can can help out with some useful information: ``` cd path/to/linux-tkg/linux57-tkg -./install.sh uninstall +./install.sh uninstall-help ``` ### Other linux distributions -Other distros are not supported, Debian may work with the `install.sh` script. Otherwise, -that same `install.sh` script can clone, patch and edit a `.config` file from your current distro's -that is expected at ``/boot/config-`uname -r`.config``. Otherwise it won't work as-is. +If your distro is not DEB or RPM based, `install.sh` script can clone the kernel tree, patch and edit a `.config` file from your current distro's +that is expected at ``/boot/config-`uname -r`.config`` (otherwise it won't work as-is) The command to do for that is: ``` diff --git a/linux57-tkg/customization.cfg b/linux57-tkg/customization.cfg index c0cffcc..0aef7b5 100644 --- a/linux57-tkg/customization.cfg +++ b/linux57-tkg/customization.cfg @@ -1,7 +1,9 @@ # linux57-TkG config file -# Linux distribution you are using, options are "Arch" (default), "Ubuntu" -_distro="Arch" +# Linux distribution you are using, options are "Arch", "Ubuntu", "Debian", "Fedora" or "Suse". +# It is automatically set to "Arch" when using PKGBUILD. +# If left empty, the script will prompt +_distro="" #### MISC OPTIONS #### @@ -155,7 +157,7 @@ _custom_commandline="intel_pstate=passive" # !!! It will also change pkgname - If you don't explicitely need this, don't use it !!! _custom_pkgbase="" -# [non-Arch specific] Kernel localversion. Putting it to "Mario" will make for example the kernel version be 5.7.0-Mario (given by uname -r) +# [non-Arch specific] Kernel localversion. Putting it to "Mario" will make for example the kernel version be 5.7.0-tkg-Mario (given by uname -r) # If left empty, it will use -tkg-"${_cpusched}" where "${_cpusched}" will be replaced by the user chosen scheduler _kernel_localversion="" diff --git a/linux57-tkg/install.sh b/linux57-tkg/install.sh index 2e21a68..0fa193a 100755 --- a/linux57-tkg/install.sh +++ b/linux57-tkg/install.sh @@ -16,21 +16,24 @@ plain() { echo "$1" >&2 } -# alias plain=echo +# Stop the script at any ecountered error set -e _where=`pwd` srcdir="$_where" -_cpu_opt_patch_link="https://raw.githubusercontent.com/graysky2/kernel_gcc_patch/master/enable_additional_cpu_optimizations_for_gcc_v10.1%2B_kernel_v5.7%2B.patch" +source linux*-tkg-config/prepare + +_cpu_opt_patch_link="https://raw.githubusercontent.com/graysky2/kernel_gcc_patch/master/enable_additional_cpu_optimizations_for_gcc_v10.1%2B_kernel_v${_basekernel}%2B.patch" source customization.cfg -if [ "$1" != "install" ] && [ "$1" != "config" ] && [ "$1" != "uninstall" ]; then - echo "Command not recognised, options are: - - config : shallow clones the linux 5.7.x git tree into the folder linux-5.7, then applies on it the extra patches and prepares the .config file by copying the one from the current linux system in /boot/config-`uname -r` and updates it. - - install : [Debian-like only (Debian, Ubuntu, Pop_os!...)], does the config step, proceeds to compile, then prompts to install - - uninstall : [Debian-like only (Debian, Ubuntu, Pop_os!...)], lists the installed custom kernels through this script, then prompts for which one to uninstall." +if [ "$1" != "install" ] && [ "$1" != "config" ] && [ "$1" != "uninstall-help" ]; then + msg2 "Argument not recognised, options are: + - config : shallow clones the linux ${_basekernel}.x git tree into the folder linux-${_basekernel}, then applies on it the extra patches and prepares the .config file + by copying the one from the current linux system in /boot/config-`uname -r` and updates it. + - install : [RPM and DEB based distros only], does the config step, proceeds to compile, then prompts to install + - uninstall-help : [RPM and DEB based distros only], lists the installed kernels in this system, then gives a hint on how to uninstall them manually." exit 0 fi @@ -44,22 +47,52 @@ _misc_adds="false" # We currently don't want this enabled on non-Arch if [ "$1" = "install" ] || [ "$1" = "config" ]; then - source linux*-tkg-config/prepare + if [ -z $_distro ] && [ "$1" = "install" ]; then + while true; do + echo "Which linux distribution are you running ?" + echo "if it's not on the list, chose the closest one to it: Fedora/Suse for RPM, Ubuntu/Debian for DEB" + echo " 1) Debian" + echo " 2) Fedora" + echo " 3) Suse" + echo " 4) Ubuntu" + read -p "[1-4]: " _distro_index - if [ $1 = "install" ] && [ "$_distro" != "Ubuntu" ]; then - msg2 "Variable \"_distro\" in \"customization.cfg\" hasn't been set to \"Ubuntu\"" - msg2 "This script can only install custom kernels for Ubuntu and Debian derivatives. Exiting..." + if [ "$_distro_index" = "1" ]; then + _distro="Debian" + break + elif [ "$_distro_index" = "2" ]; then + _distro="Fedora" + break + elif [ "$_distro_index" = "3" ]; then + _distro="Suse" + break + elif [ "$_distro_index" = "4" ]; then + _distro="Ubuntu" + break + else + echo "Wrong index." + fi + done + fi + + if [[ $1 = "install" && "$_distro" != "Ubuntu" && "$_distro" != "Debian" && "$_distro" != "Fedora" && "$_distro" != "Suse" ]]; then + msg2 "Variable \"_distro\" in \"customization.cfg\" hasn't been set to \"Ubuntu\", \"Debian\", \"Fedora\" or \"Suse\"" + msg2 "This script can only install custom kernels for RPM and DEB based distros, though only those keywords are permitted. Exiting..." exit 0 fi - if [ "$_distro" = "Ubuntu" ]; then + if [ "$_distro" = "Ubuntu" ] || [ "$_distro" = "Debian" ]; then msg2 "Installing dependencies" - sudo apt install git build-essential kernel-package fakeroot libncurses5-dev libssl-dev ccache bison flex - else - msg2 "Dependencies are unknown for the target linux distribution." + sudo apt install git build-essential kernel-package fakeroot libncurses5-dev libssl-dev ccache bison flex qtbase5-dev -y + elif [ "$_distro" = "Fedora" ]; then + msg2 "Installing dependencies" + sudo dnf install fedpkg fedora-packager rpmdevtools ncurses-devel pesign grubby qt5-devel libXi-devel gcc-c++ git ccache flex bison elfutils-libelf-devel openssl-devel dwarves rpm-build -y + elif [ "$_distro" = "Suse" ]; then + msg2 "Installing dependencies" + sudo zypper install -y rpmdevtools ncurses-devel pesign libXi-devel gcc-c++ git ccache flex bison elfutils libelf-devel openssl-devel dwarves make patch bc rpm-build libqt5-qtbase-common-devel libqt5-qtbase-devel lz4 fi - # Force prepare script to avoid Arch specific commands if the user didn't change _distro from "Arch" + # Force prepare script to avoid Arch specific commands if the user is using `config` if [ "$1" = "config" ]; then _distro="" fi @@ -105,6 +138,9 @@ if [ "$1" = "install" ] || [ "$1" = "config" ]; then msg2 "Copying current kernel's config and running make oldconfig..." cp /boot/config-`uname -r` .config + if [ "$_distro" = "Debian" ]; then #Help Debian cert problem. + sed -i -e 's#CONFIG_SYSTEM_TRUSTED_KEYS="debian/certs/test-signing-certs.pem"#CONFIG_SYSTEM_TRUSTED_KEYS=""#g' .config + fi yes '' | make oldconfig msg2 "Done" @@ -132,74 +168,115 @@ if [ "$1" = "install" ]; then # ccache if [ "$_noccache" != "true" ]; then - if [ "$_distro" = "Ubuntu" ] && dpkg -l ccache > /dev/null; then + + if [ "$_distro" = "Ubuntu" ] || [ "$_distro" = "Debian" ]; then export PATH="/usr/lib/ccache/bin/:$PATH" - export CCACHE_SLOPPINESS="file_macro,locale,time_macros" - export CCACHE_NOHASHDIR="true" - msg2 'ccache was found and will be used' + elif [ "$_distro" = "Fedora" ] || [ "$_distro" = "Suse" ]; then + export PATH="/usr/lib64/ccache/:$PATH" fi + + export CCACHE_SLOPPINESS="file_macro,locale,time_macros" + export CCACHE_NOHASHDIR="true" + msg2 'ccache was found and will be used' + fi - _kernel_flavor="${_kernel_localversion}" if [ -z $_kernel_localversion ]; then _kernel_flavor="tkg-${_cpusched}" + else + _kernel_flavor="tkg-${_kernel_localversion}" fi - if [ "$_distro" = "Ubuntu" ]; then + if [ "$_distro" = "Ubuntu" ] || [ "$_distro" = "Debian" ]; then + if make -j ${_thread_num} deb-pkg LOCALVERSION=-${_kernel_flavor}; then msg2 "Building successfully finished!" + + cd "$_where" + + # Create DEBS folder if it doesn't exist + mkdir -p DEBS + + # Move rpm files to RPMS folder inside the linux-tkg folder + mv "$_where"/*.deb "$_where"/DEBS/ + read -p "Do you want to install the new Kernel ? y/[n]: " _install - if [[ $_install =~ [yY] ]] || [[ $_install =~ [yY] ]] || [ $_install = "yes" ] || [ $_install = "Yes" ]; then + if [[ $_install =~ [yY] ]] || [ $_install = "yes" ] || [ $_install = "Yes" ]; then cd "$_where" _kernelname=$_basekernel.$_kernel_subver-$_kernel_flavor - _headers_deb=linux-headers-${_kernelname}*.deb - _image_deb=linux-image-${_kernelname}_*.deb + _headers_deb="linux-headers-${_kernelname}*.deb" + _image_deb="linux-image-${_kernelname}_*.deb" + _kernel_devel_deb="linux-libc-dev_${_kernelname}*.rpm" - sudo dpkg -i $_headers_deb $_image_deb + cd DEBS + sudo dpkg -i $_headers_deb $_image_deb $_kernel_devel_deb + fi + fi - # Add to the list of installed kernels, used for uninstall - if ! { [ -f installed-kernels ] && grep -Fxq "$_kernelname" installed-kernels; }; then - echo $_kernelname >> installed-kernels - fi + elif [[ "$_distro" = "Fedora" || "$_distro" = "Suse" ]]; then + + # Replace dashes with underscores, it seems that it's being done by binrpm-pkg + # Se we can actually refer properly to the rpm files. + _kernel_flavor=${_kernel_flavor//-/_} + + if make -j ${_thread_num} rpm-pkg EXTRAVERSION="_${_kernel_flavor}"; then + msg2 "Building successfully finished!" + + cd "$_where" + + # Create RPMS folder if it doesn't exist + mkdir -p RPMS + + # Move rpm files to RPMS folder inside the linux-tkg folder + mv ~/rpmbuild/RPMS/x86_64/* "$_where"/RPMS/ + + #Clean up the original folder, unneeded and takes a lot of space + rm -rf ~/rpmbuild/ + + read -p "Do you want to install the new Kernel ? y/[n]: " _install + if [ "$_install" = "y" ] || [ "$_install" = "Y" ] || [ "$_install" = "yes" ] || [ "$_install" = "Yes" ]; then + + _kernelname=$_basekernel.${_kernel_subver}_$_kernel_flavor + _headers_rpm="kernel-headers-${_kernelname}*.rpm" + _kernel_rpm="kernel-${_kernelname}*.rpm" + _kernel_devel_rpm="kernel-devel-${_kernelname}*.rpm" + + cd RPMS + if [ "$_distro" = "Fedora" ]; then + sudo dnf install $_headers_rpm $_kernel_rpm $_kernel_devel_rpm + elif [ "$_distro" = "Suse" ]; then + msg2 "Some files from 'linux-glibc-devel' will be replaced by files from the custom kernel-hearders package" + msg2 "To revert back to the original kernel headers do 'sudo zypper install -f linux-glibc-devel'" + sudo zypper install --replacefiles --allow-unsigned-rpm $_headers_rpm $_kernel_rpm $_kernel_devel_rpm + fi + + msg2 "Install successful" fi fi fi fi -if [ "$1" = "uninstall" ]; then +if [ "$1" = "uninstall-help" ]; then cd "$_where" + msg2 "List of installed custom tkg kernels: " - if [ ! -f installed-kernels ] || [ ! -s installed-kernels ]; then - echo "No custom kernel has been installed yet" - exit 0 + if [ "$_distro" = "Ubuntu" ]; then + dpkg -l "*tkg*" | grep "linux.*tkg" + dpkg -l "*linux-libc-dev*" | grep "linux.*tkg" + msg2 "To uninstall a version, you should remove the linux-image, linux-headers and linux-libc-dev associated to it (if installed), with: " + msg2 " sudo apt remove linux-image-VERSION linux-headers-VERSION linux-libc-dev-VERSION" + msg2 " where VERSION is displayed in the lists above, uninstall only versions that have \"tkg\" in its name" + elif [ "$_distro" = "Fedora" ]; then + dnf list --installed kernel* + msg2 "To uninstall a version, you should remove the kernel, kernel-headers and kernel-devel associated to it (if installed), with: " + msg2 " sudo dnf remove --noautoremove kernel-VERSION kernel-devel-VERSION kernel-headers-VERSION" + msg2 " where VERSION is displayed in the second column" + elif [ "$_distro" = "Suse" ]; then + zypper packages --installed-only | grep "kernel.*tkg" + msg2 "To uninstall a version, you should remove the kernel, kernel-headers and kernel-devel associated to it (if installed), with: " + msg2 " sudo zypper remove --no-clean-deps kernel-VERSION kernel-devel-VERSION kernel-headers-VERSION" + msg2 " where VERSION is displayed in the second to last column" fi - i=1 - declare -a _custom_kernels - msg2 "Installed custom kernel versions: " - while read p; do - echo " $i) $p" - _custom_kernels+=($p) - i=$((i+1)) - done < installed-kernels - - i=$((i-1)) - _delete_index=0 - read -p "Which one would you like to delete ? [1-$i]: " _delete_index - - if [ $_delete_index -ge 1 ] && [ $_delete_index -le $i ]; then - _delete_index=$((_delete_index-1)) - sudo dpkg -r linux-headers-${_custom_kernels[$_delete_index]} linux-image-${_custom_kernels[$_delete_index]} - fi - - rm -f installed-kernels - i=0 - for kernel in "${_custom_kernels[@]}"; do - if [ $_delete_index != $i ]; then - echo "$kernel" >> installed-kernels - fi - i=$((i+1)) - done - fi diff --git a/linux58-tkg/PKGBUILD b/linux58-tkg/PKGBUILD index a0e9405..f3daa2d 100644 --- a/linux58-tkg/PKGBUILD +++ b/linux58-tkg/PKGBUILD @@ -36,6 +36,8 @@ fi _tkg_initscript +_distro="Arch" + if [ -n "$_custom_pkgbase" ]; then pkgbase="${_custom_pkgbase}" else diff --git a/linux58-tkg/README.md b/linux58-tkg/README.md index 4f0b0e4..9ac8c21 100644 --- a/linux58-tkg/README.md +++ b/linux58-tkg/README.md @@ -31,31 +31,23 @@ You can enable support for it at the beginning of the PKGBUILD file. Make sure t ## Install procedure -### Arch & derivatives +### Fedora, Ubuntu and derivatives ``` git clone https://github.com/Frogging-Family/linux-tkg.git cd linux-tkg/linux58-tkg -# Edit customization.cfg file -makepkg -si -``` - -### Ubuntu & derivatives -``` -git clone https://github.com/Frogging-Family/linux-tkg.git -cd linux-tkg/linux58-tkg -# Edit customization.cfg file to at least set _distro to "Ubuntu" +# Optional: edit customization.cfg file ./install.sh install ``` -To uninstall custom kernels installed through the script: +Uninstalling custom kernels installed through the script has to be done +manually, the script can can help out with some useful information: ``` cd path/to/linux-tkg/linux58-tkg -./install.sh uninstall +./install.sh uninstall-help ``` ### Other linux distributions -Other distros are not supported, Debian may work with the `install.sh` script. Otherwise, -that same `install.sh` script can clone, patch and edit a `.config` file from your current distro's -that is expected at ``/boot/config-`uname -r`.config``. Otherwise it won't work as-is. +If your distro is not DEB or RPM based, `install.sh` script can clone the kernel tree, patch and edit a `.config` file from your current distro's +that is expected at ``/boot/config-`uname -r`.config`` (otherwise it won't work as-is) The command to do for that is: ``` diff --git a/linux58-tkg/customization.cfg b/linux58-tkg/customization.cfg index ac629bd..ef47268 100644 --- a/linux58-tkg/customization.cfg +++ b/linux58-tkg/customization.cfg @@ -1,7 +1,9 @@ # linux58-TkG config file -# Linux distribution you are using, options are "Arch" (default), "Debian" or "Ubuntu" -_distro="Arch" +# Linux distribution you are using, options are "Arch", "Ubuntu", "Debian", "Fedora" or "Suse". +# It is automatically set to "Arch" when using PKGBUILD. +# If left empty, the script will prompt +_distro="" #### MISC OPTIONS #### @@ -152,7 +154,7 @@ _custom_commandline="intel_pstate=passive" # !!! It will also change pkgname - If you don't explicitely need this, don't use it !!! _custom_pkgbase="" -# [non-Arch specific] Kernel localversion. Putting it to "Mario" will make for example the kernel version be 5.7.0-Mario (given by uname -r) +# [non-Arch specific] Kernel localversion. Putting it to "Mario" will make for example the kernel version be 5.7.0-tkg-Mario (given by uname -r) # If left empty, it will use -tkg-"${_cpusched}" where "${_cpusched}" will be replaced by the user chosen scheduler _kernel_localversion="" diff --git a/linux58-tkg/install.sh b/linux58-tkg/install.sh index babe795..0fa193a 100755 --- a/linux58-tkg/install.sh +++ b/linux58-tkg/install.sh @@ -16,21 +16,24 @@ plain() { echo "$1" >&2 } -# alias plain=echo +# Stop the script at any ecountered error set -e _where=`pwd` srcdir="$_where" -_cpu_opt_patch_link="https://raw.githubusercontent.com/graysky2/kernel_gcc_patch/master/enable_additional_cpu_optimizations_for_gcc_v10.1%2B_kernel_v5.8%2B.patch" +source linux*-tkg-config/prepare + +_cpu_opt_patch_link="https://raw.githubusercontent.com/graysky2/kernel_gcc_patch/master/enable_additional_cpu_optimizations_for_gcc_v10.1%2B_kernel_v${_basekernel}%2B.patch" source customization.cfg -if [ "$1" != "install" ] && [ "$1" != "config" ] && [ "$1" != "uninstall" ]; then - echo "Command not recognised, options are: - - config : shallow clones the linux 5.8.x git tree into the folder linux-5.8, then applies on it the extra patches and prepares the .config file by copying the one from the current linux system in /boot/config-`uname -r` and updates it. - - install : [Debian-like only (Debian, Ubuntu, Pop_os!...)], does the config step, proceeds to compile, then prompts to install - - uninstall : [Debian-like only (Debian, Ubuntu, Pop_os!...)], lists the installed custom kernels through this script, then prompts for which one to uninstall." +if [ "$1" != "install" ] && [ "$1" != "config" ] && [ "$1" != "uninstall-help" ]; then + msg2 "Argument not recognised, options are: + - config : shallow clones the linux ${_basekernel}.x git tree into the folder linux-${_basekernel}, then applies on it the extra patches and prepares the .config file + by copying the one from the current linux system in /boot/config-`uname -r` and updates it. + - install : [RPM and DEB based distros only], does the config step, proceeds to compile, then prompts to install + - uninstall-help : [RPM and DEB based distros only], lists the installed kernels in this system, then gives a hint on how to uninstall them manually." exit 0 fi @@ -44,22 +47,52 @@ _misc_adds="false" # We currently don't want this enabled on non-Arch if [ "$1" = "install" ] || [ "$1" = "config" ]; then - source linux*-tkg-config/prepare + if [ -z $_distro ] && [ "$1" = "install" ]; then + while true; do + echo "Which linux distribution are you running ?" + echo "if it's not on the list, chose the closest one to it: Fedora/Suse for RPM, Ubuntu/Debian for DEB" + echo " 1) Debian" + echo " 2) Fedora" + echo " 3) Suse" + echo " 4) Ubuntu" + read -p "[1-4]: " _distro_index - if [ $1 = "install" ] && [[ "$_distro" != "Ubuntu" && "$_distro" != "Debian" ]]; then - msg2 "Variable \"_distro\" in \"customization.cfg\" hasn't been set to \"Debian\" or \"Ubuntu\"" - msg2 "This script can only install custom kernels for Ubuntu and Debian derivatives. Exiting..." + if [ "$_distro_index" = "1" ]; then + _distro="Debian" + break + elif [ "$_distro_index" = "2" ]; then + _distro="Fedora" + break + elif [ "$_distro_index" = "3" ]; then + _distro="Suse" + break + elif [ "$_distro_index" = "4" ]; then + _distro="Ubuntu" + break + else + echo "Wrong index." + fi + done + fi + + if [[ $1 = "install" && "$_distro" != "Ubuntu" && "$_distro" != "Debian" && "$_distro" != "Fedora" && "$_distro" != "Suse" ]]; then + msg2 "Variable \"_distro\" in \"customization.cfg\" hasn't been set to \"Ubuntu\", \"Debian\", \"Fedora\" or \"Suse\"" + msg2 "This script can only install custom kernels for RPM and DEB based distros, though only those keywords are permitted. Exiting..." exit 0 fi - if [ "$_distro" = "Debian" ] || [ "$_distro" = "Ubuntu" ]; then + if [ "$_distro" = "Ubuntu" ] || [ "$_distro" = "Debian" ]; then msg2 "Installing dependencies" - sudo apt install git build-essential kernel-package fakeroot libncurses5-dev libssl-dev ccache bison flex - else - msg2 "Dependencies are unknown for the target linux distribution." + sudo apt install git build-essential kernel-package fakeroot libncurses5-dev libssl-dev ccache bison flex qtbase5-dev -y + elif [ "$_distro" = "Fedora" ]; then + msg2 "Installing dependencies" + sudo dnf install fedpkg fedora-packager rpmdevtools ncurses-devel pesign grubby qt5-devel libXi-devel gcc-c++ git ccache flex bison elfutils-libelf-devel openssl-devel dwarves rpm-build -y + elif [ "$_distro" = "Suse" ]; then + msg2 "Installing dependencies" + sudo zypper install -y rpmdevtools ncurses-devel pesign libXi-devel gcc-c++ git ccache flex bison elfutils libelf-devel openssl-devel dwarves make patch bc rpm-build libqt5-qtbase-common-devel libqt5-qtbase-devel lz4 fi - # Force prepare script to avoid Arch specific commands if the user didn't change _distro from "Arch" + # Force prepare script to avoid Arch specific commands if the user is using `config` if [ "$1" = "config" ]; then _distro="" fi @@ -135,74 +168,115 @@ if [ "$1" = "install" ]; then # ccache if [ "$_noccache" != "true" ]; then - if [[ "$_distro" = "Ubuntu" || "$_distro" = "Debian" ]] && dpkg -l ccache > /dev/null; then + + if [ "$_distro" = "Ubuntu" ] || [ "$_distro" = "Debian" ]; then export PATH="/usr/lib/ccache/bin/:$PATH" - export CCACHE_SLOPPINESS="file_macro,locale,time_macros" - export CCACHE_NOHASHDIR="true" - msg2 'ccache was found and will be used' + elif [ "$_distro" = "Fedora" ] || [ "$_distro" = "Suse" ]; then + export PATH="/usr/lib64/ccache/:$PATH" fi + + export CCACHE_SLOPPINESS="file_macro,locale,time_macros" + export CCACHE_NOHASHDIR="true" + msg2 'ccache was found and will be used' + fi - _kernel_flavor="${_kernel_localversion}" if [ -z $_kernel_localversion ]; then _kernel_flavor="tkg-${_cpusched}" + else + _kernel_flavor="tkg-${_kernel_localversion}" fi - if [ "$_distro" = "Ubuntu" ] || [ "$_distro" = "Debian" ]; then + if [ "$_distro" = "Ubuntu" ] || [ "$_distro" = "Debian" ]; then + if make -j ${_thread_num} deb-pkg LOCALVERSION=-${_kernel_flavor}; then msg2 "Building successfully finished!" + + cd "$_where" + + # Create DEBS folder if it doesn't exist + mkdir -p DEBS + + # Move rpm files to RPMS folder inside the linux-tkg folder + mv "$_where"/*.deb "$_where"/DEBS/ + read -p "Do you want to install the new Kernel ? y/[n]: " _install - if [[ $_install =~ [yY] ]] || [[ $_install =~ [yY] ]] || [ $_install = "yes" ] || [ $_install = "Yes" ]; then + if [[ $_install =~ [yY] ]] || [ $_install = "yes" ] || [ $_install = "Yes" ]; then cd "$_where" _kernelname=$_basekernel.$_kernel_subver-$_kernel_flavor - _headers_deb=linux-headers-${_kernelname}*.deb - _image_deb=linux-image-${_kernelname}_*.deb + _headers_deb="linux-headers-${_kernelname}*.deb" + _image_deb="linux-image-${_kernelname}_*.deb" + _kernel_devel_deb="linux-libc-dev_${_kernelname}*.rpm" - sudo dpkg -i $_headers_deb $_image_deb + cd DEBS + sudo dpkg -i $_headers_deb $_image_deb $_kernel_devel_deb + fi + fi - # Add to the list of installed kernels, used for uninstall - if ! { [ -f installed-kernels ] && grep -Fxq "$_kernelname" installed-kernels; }; then - echo $_kernelname >> installed-kernels - fi + elif [[ "$_distro" = "Fedora" || "$_distro" = "Suse" ]]; then + + # Replace dashes with underscores, it seems that it's being done by binrpm-pkg + # Se we can actually refer properly to the rpm files. + _kernel_flavor=${_kernel_flavor//-/_} + + if make -j ${_thread_num} rpm-pkg EXTRAVERSION="_${_kernel_flavor}"; then + msg2 "Building successfully finished!" + + cd "$_where" + + # Create RPMS folder if it doesn't exist + mkdir -p RPMS + + # Move rpm files to RPMS folder inside the linux-tkg folder + mv ~/rpmbuild/RPMS/x86_64/* "$_where"/RPMS/ + + #Clean up the original folder, unneeded and takes a lot of space + rm -rf ~/rpmbuild/ + + read -p "Do you want to install the new Kernel ? y/[n]: " _install + if [ "$_install" = "y" ] || [ "$_install" = "Y" ] || [ "$_install" = "yes" ] || [ "$_install" = "Yes" ]; then + + _kernelname=$_basekernel.${_kernel_subver}_$_kernel_flavor + _headers_rpm="kernel-headers-${_kernelname}*.rpm" + _kernel_rpm="kernel-${_kernelname}*.rpm" + _kernel_devel_rpm="kernel-devel-${_kernelname}*.rpm" + + cd RPMS + if [ "$_distro" = "Fedora" ]; then + sudo dnf install $_headers_rpm $_kernel_rpm $_kernel_devel_rpm + elif [ "$_distro" = "Suse" ]; then + msg2 "Some files from 'linux-glibc-devel' will be replaced by files from the custom kernel-hearders package" + msg2 "To revert back to the original kernel headers do 'sudo zypper install -f linux-glibc-devel'" + sudo zypper install --replacefiles --allow-unsigned-rpm $_headers_rpm $_kernel_rpm $_kernel_devel_rpm + fi + + msg2 "Install successful" fi fi fi fi -if [ "$1" = "uninstall" ]; then +if [ "$1" = "uninstall-help" ]; then cd "$_where" + msg2 "List of installed custom tkg kernels: " - if [ ! -f installed-kernels ] || [ ! -s installed-kernels ]; then - echo "No custom kernel has been installed yet" - exit 0 + if [ "$_distro" = "Ubuntu" ]; then + dpkg -l "*tkg*" | grep "linux.*tkg" + dpkg -l "*linux-libc-dev*" | grep "linux.*tkg" + msg2 "To uninstall a version, you should remove the linux-image, linux-headers and linux-libc-dev associated to it (if installed), with: " + msg2 " sudo apt remove linux-image-VERSION linux-headers-VERSION linux-libc-dev-VERSION" + msg2 " where VERSION is displayed in the lists above, uninstall only versions that have \"tkg\" in its name" + elif [ "$_distro" = "Fedora" ]; then + dnf list --installed kernel* + msg2 "To uninstall a version, you should remove the kernel, kernel-headers and kernel-devel associated to it (if installed), with: " + msg2 " sudo dnf remove --noautoremove kernel-VERSION kernel-devel-VERSION kernel-headers-VERSION" + msg2 " where VERSION is displayed in the second column" + elif [ "$_distro" = "Suse" ]; then + zypper packages --installed-only | grep "kernel.*tkg" + msg2 "To uninstall a version, you should remove the kernel, kernel-headers and kernel-devel associated to it (if installed), with: " + msg2 " sudo zypper remove --no-clean-deps kernel-VERSION kernel-devel-VERSION kernel-headers-VERSION" + msg2 " where VERSION is displayed in the second to last column" fi - i=1 - declare -a _custom_kernels - msg2 "Installed custom kernel versions: " - while read p; do - echo " $i) $p" - _custom_kernels+=($p) - i=$((i+1)) - done < installed-kernels - - i=$((i-1)) - _delete_index=0 - read -p "Which one would you like to delete ? [1-$i]: " _delete_index - - if [ $_delete_index -ge 1 ] && [ $_delete_index -le $i ]; then - _delete_index=$((_delete_index-1)) - sudo dpkg -r linux-headers-${_custom_kernels[$_delete_index]} linux-image-${_custom_kernels[$_delete_index]} - fi - - rm -f installed-kernels - i=0 - for kernel in "${_custom_kernels[@]}"; do - if [ $_delete_index != $i ]; then - echo "$kernel" >> installed-kernels - fi - i=$((i+1)) - done - fi diff --git a/linux59-rc-tkg/PKGBUILD b/linux59-rc-tkg/PKGBUILD index 4bc2a78..85824f5 100644 --- a/linux59-rc-tkg/PKGBUILD +++ b/linux59-rc-tkg/PKGBUILD @@ -36,6 +36,8 @@ fi _tkg_initscript +_distro="Arch" + if [ -n "$_custom_pkgbase" ]; then pkgbase="${_custom_pkgbase}" else diff --git a/linux59-rc-tkg/README.md b/linux59-rc-tkg/README.md index 231bd5f..e101182 100644 --- a/linux59-rc-tkg/README.md +++ b/linux59-rc-tkg/README.md @@ -27,33 +27,28 @@ You can enable support for it at the beginning of the PKGBUILD file. Make sure t ## Install procedure -### Arch & derivatives -``` -git clone https://github.com/Frogging-Family/linux-tkg.git -cd linux-tkg/linux59-rc-tkg -# Edit customization.cfg file -makepkg -si -``` +## Install procedure -### Ubuntu & derivatives +### Fedora, Ubuntu and derivatives ``` git clone https://github.com/Frogging-Family/linux-tkg.git cd linux-tkg/linux59-rc-tkg -# Edit customization.cfg file to at least set _distro to "Ubuntu" +# Optional: edit customization.cfg file ./install.sh install ``` -To uninstall custom kernels installed through the script: +Uninstalling custom kernels installed through the script has to be done +manually, the script can can help out with some useful information: ``` cd path/to/linux-tkg/linux59-rc-tkg -./install.sh uninstall +./install.sh uninstall-help ``` ### Other linux distributions -Other distros are not supported, Debian may work with the `install.sh` script. Otherwise, -that same `install.sh` script can clone, patch and edit a `.config` file from your current distro's -that is expected at ``/boot/config-`uname -r`.config``. Otherwise it won't work as-is. +If your distro is not DEB or RPM based, `install.sh` script can clone the kernel tree, patch and edit a `.config` file from your current distro's +that is expected at ``/boot/config-`uname -r`.config`` (otherwise it won't work as-is) The command to do for that is: ``` ./install.sh config ``` + diff --git a/linux59-rc-tkg/customization.cfg b/linux59-rc-tkg/customization.cfg index 4bf09ef..4a2530e 100644 --- a/linux59-rc-tkg/customization.cfg +++ b/linux59-rc-tkg/customization.cfg @@ -1,7 +1,9 @@ # linux59-TkG config file -# Linux distribution you are using, options are "Arch" (default), "Ubuntu" -_distro="Arch" +# Linux distribution you are using, options are "Arch", "Ubuntu", "Debian", "Fedora" or "Suse". +# It is automatically set to "Arch" when using PKGBUILD. +# If left empty, the script will prompt +_distro="" #### MISC OPTIONS #### diff --git a/linux59-rc-tkg/install.sh b/linux59-rc-tkg/install.sh index e76b034..6debfda 100755 --- a/linux59-rc-tkg/install.sh +++ b/linux59-rc-tkg/install.sh @@ -16,21 +16,24 @@ plain() { echo "$1" >&2 } -# alias plain=echo +# Stop the script at any ecountered error set -e _where=`pwd` srcdir="$_where" +source linux*-tkg-config/prepare + _cpu_opt_patch_link="https://raw.githubusercontent.com/graysky2/kernel_gcc_patch/master/enable_additional_cpu_optimizations_for_gcc_v10.1%2B_kernel_v5.8%2B.patch" source customization.cfg -if [ "$1" != "install" ] && [ "$1" != "config" ] && [ "$1" != "uninstall" ]; then - echo "Command not recognised, options are: - - config : shallow clones the linux 5.9.x git tree into the folder linux-5.9, then applies on it the extra patches and prepares the .config file by copying the one from the current linux system in /boot/config-`uname -r` and updates it. - - install : [Debian-like only (Debian, Ubuntu, Pop_os!...)], does the config step, proceeds to compile, then prompts to install - - uninstall : [Debian-like only (Debian, Ubuntu, Pop_os!...)], lists the installed custom kernels through this script, then prompts for which one to uninstall." +if [ "$1" != "install" ] && [ "$1" != "config" ] && [ "$1" != "uninstall-help" ]; then + msg2 "Argument not recognised, options are: + - config : shallow clones the linux ${_basekernel}.x git tree into the folder linux-${_basekernel}, then applies on it the extra patches and prepares the .config file + by copying the one from the current linux system in /boot/config-`uname -r` and updates it. + - install : [RPM and DEB based distros only], does the config step, proceeds to compile, then prompts to install + - uninstall-help : [RPM and DEB based distros only], lists the installed kernels in this system, then gives a hint on how to uninstall them manually." exit 0 fi @@ -44,22 +47,52 @@ _misc_adds="false" # We currently don't want this enabled on non-Arch if [ "$1" = "install" ] || [ "$1" = "config" ]; then - source linux*-tkg-config/prepare + if [ -z $_distro ] && [ "$1" = "install" ]; then + while true; do + echo "Which linux distribution are you running ?" + echo "if it's not on the list, chose the closest one to it: Fedora/Suse for RPM, Ubuntu/Debian for DEB" + echo " 1) Debian" + echo " 2) Fedora" + echo " 3) Suse" + echo " 4) Ubuntu" + read -p "[1-4]: " _distro_index - if [ $1 = "install" ] && [ "$_distro" != "Ubuntu" ]; then - msg2 "Variable \"_distro\" in \"customization.cfg\" hasn't been set to \"Ubuntu\"" - msg2 "This script can only install custom kernels for Ubuntu and Debian derivatives. Exiting..." + if [ "$_distro_index" = "1" ]; then + _distro="Debian" + break + elif [ "$_distro_index" = "2" ]; then + _distro="Fedora" + break + elif [ "$_distro_index" = "3" ]; then + _distro="Suse" + break + elif [ "$_distro_index" = "4" ]; then + _distro="Ubuntu" + break + else + echo "Wrong index." + fi + done + fi + + if [[ $1 = "install" && "$_distro" != "Ubuntu" && "$_distro" != "Debian" && "$_distro" != "Fedora" && "$_distro" != "Suse" ]]; then + msg2 "Variable \"_distro\" in \"customization.cfg\" hasn't been set to \"Ubuntu\", \"Debian\", \"Fedora\" or \"Suse\"" + msg2 "This script can only install custom kernels for RPM and DEB based distros, though only those keywords are permitted. Exiting..." exit 0 fi - if [ "$_distro" = "Ubuntu" ]; then + if [ "$_distro" = "Ubuntu" ] || [ "$_distro" = "Debian" ]; then msg2 "Installing dependencies" - sudo apt install git build-essential kernel-package fakeroot libncurses5-dev libssl-dev ccache bison flex - else - msg2 "Dependencies are unknown for the target linux distribution." + sudo apt install git build-essential kernel-package fakeroot libncurses5-dev libssl-dev ccache bison flex qtbase5-dev -y + elif [ "$_distro" = "Fedora" ]; then + msg2 "Installing dependencies" + sudo dnf install fedpkg fedora-packager rpmdevtools ncurses-devel pesign grubby qt5-devel libXi-devel gcc-c++ git ccache flex bison elfutils-libelf-devel openssl-devel dwarves rpm-build -y + elif [ "$_distro" = "Suse" ]; then + msg2 "Installing dependencies" + sudo zypper install -y rpmdevtools ncurses-devel pesign libXi-devel gcc-c++ git ccache flex bison elfutils libelf-devel openssl-devel dwarves make patch bc rpm-build libqt5-qtbase-common-devel libqt5-qtbase-devel lz4 fi - # Force prepare script to avoid Arch specific commands if the user didn't change _distro from "Arch" + # Force prepare script to avoid Arch specific commands if the user is using `config` if [ "$1" = "config" ]; then _distro="" fi @@ -105,6 +138,9 @@ if [ "$1" = "install" ] || [ "$1" = "config" ]; then msg2 "Copying current kernel's config and running make oldconfig..." cp /boot/config-`uname -r` .config + if [ "$_distro" = "Debian" ]; then #Help Debian cert problem. + sed -i -e 's#CONFIG_SYSTEM_TRUSTED_KEYS="debian/certs/test-signing-certs.pem"#CONFIG_SYSTEM_TRUSTED_KEYS=""#g' .config + fi yes '' | make oldconfig msg2 "Done" @@ -132,74 +168,115 @@ if [ "$1" = "install" ]; then # ccache if [ "$_noccache" != "true" ]; then - if [ "$_distro" = "Ubuntu" ] && dpkg -l ccache > /dev/null; then + + if [ "$_distro" = "Ubuntu" ] || [ "$_distro" = "Debian" ]; then export PATH="/usr/lib/ccache/bin/:$PATH" - export CCACHE_SLOPPINESS="file_macro,locale,time_macros" - export CCACHE_NOHASHDIR="true" - msg2 'ccache was found and will be used' + elif [ "$_distro" = "Fedora" ] || [ "$_distro" = "Suse" ]; then + export PATH="/usr/lib64/ccache/:$PATH" fi + + export CCACHE_SLOPPINESS="file_macro,locale,time_macros" + export CCACHE_NOHASHDIR="true" + msg2 'ccache was found and will be used' + fi - _kernel_flavor="${_kernel_localversion}" if [ -z $_kernel_localversion ]; then _kernel_flavor="tkg-${_cpusched}" + else + _kernel_flavor="tkg-${_kernel_localversion}" fi - if [ "$_distro" = "Ubuntu" ]; then + if [ "$_distro" = "Ubuntu" ] || [ "$_distro" = "Debian" ]; then + if make -j ${_thread_num} deb-pkg LOCALVERSION=-${_kernel_flavor}; then msg2 "Building successfully finished!" + + cd "$_where" + + # Create DEBS folder if it doesn't exist + mkdir -p DEBS + + # Move rpm files to RPMS folder inside the linux-tkg folder + mv "$_where"/*.deb "$_where"/DEBS/ + read -p "Do you want to install the new Kernel ? y/[n]: " _install - if [[ $_install =~ [yY] ]] || [[ $_install =~ [yY] ]] || [ $_install = "yes" ] || [ $_install = "Yes" ]; then + if [[ $_install =~ [yY] ]] || [ $_install = "yes" ] || [ $_install = "Yes" ]; then cd "$_where" _kernelname=$_basekernel.$_kernel_subver-$_kernel_flavor - _headers_deb=linux-headers-${_kernelname}*.deb - _image_deb=linux-image-${_kernelname}_*.deb + _headers_deb="linux-headers-${_kernelname}*.deb" + _image_deb="linux-image-${_kernelname}_*.deb" + _kernel_devel_deb="linux-libc-dev_${_kernelname}*.rpm" - sudo dpkg -i $_headers_deb $_image_deb + cd DEBS + sudo dpkg -i $_headers_deb $_image_deb $_kernel_devel_deb + fi + fi - # Add to the list of installed kernels, used for uninstall - if ! { [ -f installed-kernels ] && grep -Fxq "$_kernelname" installed-kernels; }; then - echo $_kernelname >> installed-kernels - fi + elif [[ "$_distro" = "Fedora" || "$_distro" = "Suse" ]]; then + + # Replace dashes with underscores, it seems that it's being done by binrpm-pkg + # Se we can actually refer properly to the rpm files. + _kernel_flavor=${_kernel_flavor//-/_} + + if make -j ${_thread_num} rpm-pkg EXTRAVERSION="_${_kernel_flavor}"; then + msg2 "Building successfully finished!" + + cd "$_where" + + # Create RPMS folder if it doesn't exist + mkdir -p RPMS + + # Move rpm files to RPMS folder inside the linux-tkg folder + mv ~/rpmbuild/RPMS/x86_64/* "$_where"/RPMS/ + + #Clean up the original folder, unneeded and takes a lot of space + rm -rf ~/rpmbuild/ + + read -p "Do you want to install the new Kernel ? y/[n]: " _install + if [ "$_install" = "y" ] || [ "$_install" = "Y" ] || [ "$_install" = "yes" ] || [ "$_install" = "Yes" ]; then + + _kernelname=$_basekernel.${_kernel_subver}_$_kernel_flavor + _headers_rpm="kernel-headers-${_kernelname}*.rpm" + _kernel_rpm="kernel-${_kernelname}*.rpm" + _kernel_devel_rpm="kernel-devel-${_kernelname}*.rpm" + + cd RPMS + if [ "$_distro" = "Fedora" ]; then + sudo dnf install $_headers_rpm $_kernel_rpm $_kernel_devel_rpm + elif [ "$_distro" = "Suse" ]; then + msg2 "Some files from 'linux-glibc-devel' will be replaced by files from the custom kernel-hearders package" + msg2 "To revert back to the original kernel headers do 'sudo zypper install -f linux-glibc-devel'" + sudo zypper install --replacefiles --allow-unsigned-rpm $_headers_rpm $_kernel_rpm $_kernel_devel_rpm + fi + + msg2 "Install successful" fi fi fi fi -if [ "$1" = "uninstall" ]; then +if [ "$1" = "uninstall-help" ]; then cd "$_where" + msg2 "List of installed custom tkg kernels: " - if [ ! -f installed-kernels ] || [ ! -s installed-kernels ]; then - echo "No custom kernel has been installed yet" - exit 0 + if [ "$_distro" = "Ubuntu" ]; then + dpkg -l "*tkg*" | grep "linux.*tkg" + dpkg -l "*linux-libc-dev*" | grep "linux.*tkg" + msg2 "To uninstall a version, you should remove the linux-image, linux-headers and linux-libc-dev associated to it (if installed), with: " + msg2 " sudo apt remove linux-image-VERSION linux-headers-VERSION linux-libc-dev-VERSION" + msg2 " where VERSION is displayed in the lists above, uninstall only versions that have \"tkg\" in its name" + elif [ "$_distro" = "Fedora" ]; then + dnf list --installed kernel* + msg2 "To uninstall a version, you should remove the kernel, kernel-headers and kernel-devel associated to it (if installed), with: " + msg2 " sudo dnf remove --noautoremove kernel-VERSION kernel-devel-VERSION kernel-headers-VERSION" + msg2 " where VERSION is displayed in the second column" + elif [ "$_distro" = "Suse" ]; then + zypper packages --installed-only | grep "kernel.*tkg" + msg2 "To uninstall a version, you should remove the kernel, kernel-headers and kernel-devel associated to it (if installed), with: " + msg2 " sudo zypper remove --no-clean-deps kernel-VERSION kernel-devel-VERSION kernel-headers-VERSION" + msg2 " where VERSION is displayed in the second to last column" fi - i=1 - declare -a _custom_kernels - msg2 "Installed custom kernel versions: " - while read p; do - echo " $i) $p" - _custom_kernels+=($p) - i=$((i+1)) - done < installed-kernels - - i=$((i-1)) - _delete_index=0 - read -p "Which one would you like to delete ? [1-$i]: " _delete_index - - if [ $_delete_index -ge 1 ] && [ $_delete_index -le $i ]; then - _delete_index=$((_delete_index-1)) - sudo dpkg -r linux-headers-${_custom_kernels[$_delete_index]} linux-image-${_custom_kernels[$_delete_index]} - fi - - rm -f installed-kernels - i=0 - for kernel in "${_custom_kernels[@]}"; do - if [ $_delete_index != $i ]; then - echo "$kernel" >> installed-kernels - fi - i=$((i+1)) - done - fi