From a58041474206fabffdea174425e10bd536db64fa Mon Sep 17 00:00:00 2001 From: Tk-Glitch Date: Thu, 6 Aug 2020 21:58:24 +0200 Subject: [PATCH] linux57-tkg: Simplify various ubuntu build script interactions Untested on buntu. Following https://github.com/Frogging-Family/linux-tkg/pull/26 --- .gitignore | 1 + linux57-tkg/PKGBUILD | 137 +------------------- linux57-tkg/install.sh | 32 +++-- linux57-tkg/linux57-tkg-config/prepare | 173 ++++++++++++++++--------- 4 files changed, 137 insertions(+), 206 deletions(-) diff --git a/.gitignore b/.gitignore index 03004c9..5189f7c 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ *.files */src/ */pkg/ +*/linux-*/ diff --git a/linux57-tkg/PKGBUILD b/linux57-tkg/PKGBUILD index 8ddb342..9216c61 100644 --- a/linux57-tkg/PKGBUILD +++ b/linux57-tkg/PKGBUILD @@ -25,69 +25,17 @@ plain ' `.-:///////:-.`' _where="$PWD" # track basedir as different Arch based distros are moving srcdir around -cp "$_where"/linux57-tkg-patches/* "$_where" # copy patches inside the PKGBUILD's dir to preserve makepkg sourcing and md5sum checking -cp "$_where"/linux57-tkg-config/* "$_where" # copy config files and hooks inside the PKGBUILD's dir to preserve makepkg sourcing and md5sum checking - source "$_where"/customization.cfg # load default configuration from file +source "$_where"/linux*-tkg-config/prepare -# Load external configuration file if present. Available variable values will overwrite customization.cfg ones. -if [ -e "$_EXT_CONFIG_PATH" ]; then - source "$_EXT_CONFIG_PATH" && msg2 "External configuration file $_EXT_CONFIG_PATH will be used to override customization.cfg values." && msg2 "" -fi +_tkg_initscript -if [ -z "$_OPTIPROFILE" ] && [ ! -e "$_where"/cpuschedset ]; then - # Prompt about optimized configurations. Available variable values will overwrite customization.cfg/external config ones. - plain "Do you want to use a predefined optimized profile?" - read -rp "`echo $' > 1.Custom\n 2.Ryzen Desktop (Performance)\n 3.Other Desktop (Performance)\nchoice[1-3?]: '`" _OPTIPROFILE; -fi -if [ "$_OPTIPROFILE" == "2" ]; then - source "$_where"/ryzen-desktop-profile.cfg && msg2 "Ryzen Desktop (Performance) profile will be used." && msg2 "" -elif [ "$_OPTIPROFILE" == "3" ]; then - source "$_where"/generic-desktop-profile.cfg && msg2 "Generic Desktop (Performance) profile will be used." && msg2 "" -fi - -# source cpuschedset early if present -if [ -e "$_where"/cpuschedset ]; then - source "$_where"/cpuschedset -fi - -# CPU SCHED selector -if [ -z "$_cpusched" ] && [ ! -e "$_where"/cpuschedset ]; then - plain "What CPU sched variant do you want to build/install?" - read -rp "`echo $' > 1.PDS\n 2.MuQSS\n 3.Project C / BMQ\n 4.CFS\nchoice[1-4?]: '`" CONDITION; - if [ "$CONDITION" == "2" ]; then - echo "_cpusched=\"MuQSS\"" > "$_where"/cpuschedset - elif [ "$CONDITION" == "3" ]; then - echo "_cpusched=\"bmq\"" > "$_where"/cpuschedset - elif [ "$CONDITION" == "4" ]; then - echo "_cpusched=\"cfs\"" > "$_where"/cpuschedset - else - echo "_cpusched=\"pds\"" > "$_where"/cpuschedset - fi - if [ -n "$_custom_pkgbase" ]; then - echo "_custom_pkgbase=\"${_custom_pkgbase}\"" >> "$_where"/cpuschedset - fi -elif [ "$_cpusched" == "muqss" ] || [ "$_cpusched" == "MuQSS" ]; then - echo "_cpusched=\"MuQSS\"" > "$_where"/cpuschedset -elif [ "$_cpusched" == "pds" ]; then - echo "_cpusched=\"pds\"" > "$_where"/cpuschedset -elif [ "$_cpusched" == "bmq" ]; then - echo "_cpusched=\"bmq\"" > "$_where"/cpuschedset -else - echo "_cpusched=\"cfs\"" > "$_where"/cpuschedset -fi - -source "$_where"/cpuschedset - -_basever=57 if [ -n "$_custom_pkgbase" ]; then pkgbase="${_custom_pkgbase}" else pkgbase=linux"${_basever}"-tkg-"${_cpusched}" fi pkgname=("${pkgbase}" "${pkgbase}-headers") -_basekernel=5.7 -_sub=13 pkgver="${_basekernel}"."${_sub}" pkgrel=25 pkgdesc='Linux-tkg' @@ -164,7 +112,6 @@ prepare() { cd "${srcdir}/linux-${_basekernel}" - source "$_where/linux$_basever-tkg-config/prepare" _tkg_srcprep } @@ -325,83 +272,3 @@ package_${pkgbase}-headers() { hackheaders } EOF - -function exit_cleanup { - # Remove state tracker - rm -f "$_where"/cpuschedset - - # Remove temporarily copied files - rm -rf "$_where"/*.patch - rm -rf "$_where"/*-profile.cfg - rm -f "$_where"/config* - rm -f "$_where"/*.hook - rm -f "$_where"/cleanup - rm -f "$_where"/prepare - - # Community patches removal in case of failure - for _p in ${_community_patches[@]}; do - rm -f "$_where"/"$_p" - done - - if [ "$_NUKR" == "true" ]; then - rm -rf "$_where"/src/* - # Double tap - rm -rf "$srcdir"/linux-* - rm -rf "$srcdir"/*.xz - rm -rf "$srcdir"/*.patch - rm -rf "$srcdir"/*-profile.cfg - rm -f "$srcdir"/config.x86_64 - rm -f "$srcdir"/customization.cfg - else - # Meh - rm -rf "$srcdir"/linux-${_basekernel}/Documentation/filesystems/aufs/* - rm -f "$srcdir"/linux-${_basekernel}/Documentation/ABI/testing/*-aufs - rm -rf "$srcdir"/linux-${_basekernel}/fs/aufs/* - rm -f "$srcdir"/linux-${_basekernel}/include/uapi/linux/aufs* - - rm -f "$srcdir"/linux-${_basekernel}/mm/prfile.c - - rm -f "$srcdir"/linux-${_basekernel}/block/bfq* - - rm -rf "$srcdir"/linux-${_basekernel}/drivers/scsi/vhba/* - - rm -rf "$srcdir"/linux-${_basekernel}/fs/exfat/* - rm -f "$srcdir"/linux-${_basekernel}/include/trace/events/fs.h - - rm -f "$srcdir"/linux-${_basekernel}/Documentation/scheduler/sched-PDS-mq.txt - rm -f "$srcdir"/linux-${_basekernel}/include/linux/skip_list.h - rm -f "$srcdir"/linux-${_basekernel}/kernel/sched/pds.c - rm -f "$srcdir"/linux-${_basekernel}/kernel/sched/pds_sched.h - - rm -f "$srcdir"/linux-${_basekernel}/Documentation/scheduler/sched-BMQ.txt - rm -f "$srcdir"/linux-${_basekernel}/kernel/sched/alt_core.c - rm -f "$srcdir"/linux-${_basekernel}/kernel/sched/sched/alt_debug.c - rm -f "$srcdir"/linux-${_basekernel}/kernel/sched/alt_sched.h - - rm -f "$srcdir"/linux-${_basekernel}/Documentation/scheduler/sched-BFS.txt - rm -f "$srcdir"/linux-${_basekernel}/Documentation/scheduler/sched-MuQSS.txt - rm -rf "$srcdir"/linux-${_basekernel}/arch/blackfin/* - rm -f "$srcdir"/linux-${_basekernel}/arch/powerpc/configs/c2k_defconfig - rm -f "$srcdir"/linux-${_basekernel}/arch/score/configs/spct6600_defconfig - rm -f "$srcdir"/linux-${_basekernel}/arch/tile/configs/tilegx_defconfig - rm -f "$srcdir"/linux-${_basekernel}/arch/tile/configs/tilepro_defconfig - rm -f "$srcdir"/linux-${_basekernel}/drivers/staging/lustre/lnet/lnet/lib-eq.c - rm -f "$srcdir"/linux-${_basekernel}/kernel/sched/MuQSS* - rm -f "$srcdir"/linux-${_basekernel}/kernel/skip_list.c - - rm -f "$srcdir"/linux-${_basekernel}/Documentation/vm/uksm.txt - rm -f "$srcdir"/linux-${_basekernel}/include/linux/sradix-tree.h - rm -f "$srcdir"/linux-${_basekernel}/include/linux/uksm.h - rm -f "$srcdir"/linux-${_basekernel}/lib/sradix-tree.c - rm -f "$srcdir"/linux-${_basekernel}/mm/uksm.c - fi - - remove_deps - - msg2 'exit cleanup done\n' - if [ -n "$_runtime" ]; then - msg2 "compilation time : \n$_runtime" - fi -} - -trap exit_cleanup EXIT diff --git a/linux57-tkg/install.sh b/linux57-tkg/install.sh index f322878..0ddcd6e 100755 --- a/linux57-tkg/install.sh +++ b/linux57-tkg/install.sh @@ -1,4 +1,5 @@ #!/bin/bash + msg2() { echo -e " \033[1;34m->\033[1;0m \033[1;1m$1\033[1;0m" >&2 } @@ -20,7 +21,10 @@ set -e # Variable to know if the user command has been recognised _command_recognised=0 -_script_loc=`pwd` +_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 customization.cfg @@ -40,9 +44,7 @@ fi if [ "$1" == "install" ] || [ "$1" == "config" ]; then - source linux57-tkg-config/prepare - - _define_vars + source linux*-tkg-config/prepare if [ $1 == "install" ] && [ "$_distro" != "Ubuntu" ]; then msg2 "Variable \"_distro\" in \"customization.cfg\" hasn't been set to \"Ubuntu\"" @@ -70,12 +72,12 @@ if [ "$1" == "install" ] || [ "$1" == "config" ]; then if [ -d linux-${_basekernel} ]; then msg2 "Reseting files in linux-$_basekernel to their original state and getting latest updates" - cd $_script_loc/linux-${_basekernel} + cd "$_where"/linux-${_basekernel} git checkout --force linux-$_basekernel.y git clean -f -d -x git pull msg2 "Done" - cd $_script_loc + cd "$_where" else msg2 "Shallow git cloning linux $_basekernel" git clone --branch linux-$_basekernel.y --single-branch --depth=1 https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git linux-${_basekernel} @@ -84,20 +86,24 @@ if [ "$1" == "install" ] || [ "$1" == "config" ]; then # Define current kernel subversion if [ -z $_kernel_subver ]; then - cd $_script_loc/linux-${_basekernel} + cd "$_where"/linux-${_basekernel} _kernelverstr=`git describe` _kernel_subver=${_kernelverstr:5} - cd $_script_loc + cd "$_where" fi # Run init script that is also run in PKGBUILD, it will define some env vars that we will use _tkg_initscript + cd "$_where" + msg2 "Downloading Graysky2's CPU optimisations patch" + wget "$_cpu_opt_patch_link" + # Follow Ubuntu install isntructions in https://wiki.ubuntu.com/KernelTeam/GitKernelBuild # cd in linux folder, copy Ubuntu's current config file, update with new params - cd $_script_loc/linux-${_basekernel} + cd "$_where"/linux-${_basekernel} msg2 "Copying current kernel's config and running make oldconfig..." cp /boot/config-`uname -r` .config @@ -123,7 +129,7 @@ if [ "$1" == "install" ]; then _thread_num=`nproc` else _thread_num=`expr \`nproc\` / 4` - if [ _thread_num == 0 ]; then + if [ "$_thread_num" = "0" ]; then _thread_num=1 fi fi @@ -148,7 +154,7 @@ if [ "$1" == "install" ]; then msg2 "Building successfully finished!" read -p "Do you want to install the new Kernel ? y/[n]: " _install if [ $_install == "y" ] || [ $_install == "Y" ] || [ $_install == "yes" ] || [ $_install == "Yes" ]; then - cd $_script_loc + cd "$_where" _kernelname=$_basekernel.$_kernel_subver-$_kernel_flavor _headers_deb=linux-headers-${_kernelname}*.deb _image_deb=linux-image-${_kernelname}_*.deb @@ -167,7 +173,7 @@ fi if [ "$1" == "uninstall" ]; then _command_recognised=1 - cd $_script_loc + cd "$_where" if [ ! -f installed-kernels ] || [ ! -s installed-kernels ]; then echo "No custom kernel has been installed yet" @@ -201,4 +207,4 @@ if [ "$1" == "uninstall" ]; then i=$((i+1)) done -fi \ No newline at end of file +fi diff --git a/linux57-tkg/linux57-tkg-config/prepare b/linux57-tkg/linux57-tkg-config/prepare index 3a5a2ff..789d135 100644 --- a/linux57-tkg/linux57-tkg-config/prepare +++ b/linux57-tkg/linux57-tkg-config/prepare @@ -1,22 +1,18 @@ #!/bin/bash -_define_vars() { - _basekernel=5.7 - _where="$_script_loc/linux-${_basekernel}" - _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" -} +_basever=57 +_basekernel=5.7 +_sub=13 _tkg_initscript() { - cp $_script_loc/linux57-tkg-patches/* "$_where" # copy patches inside the PKGBUILD's dir to preserve makepkg sourcing and md5sum checking - cp $_script_loc/linux57-tkg-config/* "$_where" # copy config files and hooks inside the PKGBUILD's dir to preserve makepkg sourcing and md5sum checking + cp "$_where"/linux"$_basever"-tkg-patches/* "$_where" # copy patches inside the PKGBUILD's dir to preserve makepkg sourcing and md5sum checking + cp "$_where"/linux"$_basever"-tkg-config/* "$_where" # copy config files and hooks inside the PKGBUILD's dir to preserve makepkg sourcing and md5sum checking - - cd $_script_loc/linux-${_basekernel} - msg2 "Downloading Graysky2's CPU optimisations patch" - wget $_cpu_opt_patch_link - msg2 "Done" - cd $_script_loc + # Load external configuration file if present. Available variable values will overwrite customization.cfg ones. + if [ -e "$_EXT_CONFIG_PATH" ]; then + source "$_EXT_CONFIG_PATH" && msg2 "External configuration file $_EXT_CONFIG_PATH will be used to override customization.cfg values." && msg2 "" + fi if [ -z "$_OPTIPROFILE" ] && [ ! -e "$_where"/cpuschedset ]; then # Prompt about optimized configurations. Available variable values will overwrite customization.cfg/external config ones. @@ -111,10 +107,8 @@ user_patcher() { } _tkg_srcprep() { - - if [ "${_distro}" == "Arch" ]; then - _where=".." + if [ "${_distro}" == "Arch" ]; then msg2 "Setting version..." scripts/setlocalversion --save-scmversion echo "-$pkgrel-tkg-${_cpusched}" > localversion.10-pkgrel @@ -122,95 +116,80 @@ _tkg_srcprep() { # add upstream patch msg2 "Patching from $_basekernel to $pkgver" - patch -p1 -i "$_where"/patch-"${pkgver}" - msg2 "Done" + patch -p1 -i "$srcdir"/patch-"${pkgver}" # ARCH Patches if [ "${_configfile}" == "config_hardened.x86_64" ] && [ "${_cpusched}" == "cfs" ]; then msg2 "Using linux hardened patchset" - patch -Np1 -i "$_where"/0012-linux-hardened.patch - msg2 "Done" + patch -Np1 -i "$srcdir"/0012-linux-hardened.patch else - patch -Np1 -i "$_where"/0001-add-sysctl-to-disallow-unprivileged-CLONE_NEWUSER-by.patch + patch -Np1 -i "$srcdir"/0001-add-sysctl-to-disallow-unprivileged-CLONE_NEWUSER-by.patch fi fi # graysky's cpu opts - https://github.com/graysky2/kernel_gcc_patch msg2 "Applying graysky's cpu opts patch" if [ "${_distro}" == "Arch" ]; then - patch -Np1 -i "$_where"/enable_additional_cpu_optimizations_for_gcc_v10.1%2B_kernel_v5.7%2B.patch + patch -Np1 -i "$srcdir"/enable_additional_cpu_optimizations_for_gcc_v10.1%2B_kernel_v5.7%2B.patch else - patch -Np1 -i "$_where"/enable_additional_cpu_optimizations_for_gcc_v10.1+_kernel_v5.7+.patch + patch -Np1 -i "$srcdir"/enable_additional_cpu_optimizations_for_gcc_v10.1+_kernel_v5.7+.patch fi - msg2 "Done" # TkG msg2 "Applying clear linux patches" - patch -Np1 -i "$_where"/0002-clear-patches.patch - msg2 "Done" + patch -Np1 -i "$srcdir"/0002-clear-patches.patch msg2 "Applying glitched base patch" - patch -Np1 -i "$_where"/0003-glitched-base.patch - msg2 "Done" + patch -Np1 -i "$srcdir"/0003-glitched-base.patch if [ "$_misc_adds" = "true" ]; then msg2 "Applying misc additions patch" - patch -Np1 -i "$_where"/0012-misc-additions.patch + patch -Np1 -i "$srcdir"/0012-misc-additions.patch fi if [ "${_cpusched}" == "MuQSS" ]; then # MuQSS msg2 "Applying MuQSS base patch" - patch -Np1 -i "$_where"/0004-5.7-ck1.patch - msg2 "Done" + patch -Np1 -i "$srcdir"/0004-5.7-ck1.patch if [ "${_aggressive_ondemand}" == "true" ]; then msg2 "Applying MuQSS agressive ondemand governor patch" - patch -Np1 -i "$_where"/0004-glitched-ondemand-muqss.patch - msg2 "Done" + patch -Np1 -i "$srcdir"/0004-glitched-ondemand-muqss.patch fi msg2 "Applying Glitched MuQSS patch" - patch -Np1 -i "$_where"/0004-glitched-muqss.patch - msg2 "Done" + patch -Np1 -i "$srcdir"/0004-glitched-muqss.patch elif [ "${_cpusched}" == "pds" ]; then # PDS-mq msg2 "Applying PDS base patch" - patch -Np1 -i "$_where"/0005-v5.7_undead-pds099o.patch - msg2 "Done" + patch -Np1 -i "$srcdir"/0005-v5.7_undead-pds099o.patch if [ "${_aggressive_ondemand}" == "true" ]; then msg2 "Applying PDS agressive ondemand governor patch" - patch -Np1 -i "$_where"/0005-glitched-ondemand-pds.patch - msg2 "Done" + patch -Np1 -i "$srcdir"/0005-glitched-ondemand-pds.patch fi msg2 "Applying Glitched PDS patch" - patch -Np1 -i "$_where"/0005-glitched-pds.patch - msg2 "Done" + patch -Np1 -i "$srcdir"/0005-glitched-pds.patch elif [ "${_cpusched}" == "bmq" ]; then # Project C / BMQ msg2 "Applying Project C / BMQ base patch" - patch -Np1 -i ../0009-prjc_v5.7-r3.patch - msg2 "Done" + patch -Np1 -i "$srcdir"/0009-prjc_v5.7-r3.patch if [ "${_aggressive_ondemand}" == "true" ]; then msg2 "Applying BMQ agressive ondemand governor patch" - patch -Np1 -i "$_where"/0009-glitched-ondemand-bmq.patch - msg2 "Done" + patch -Np1 -i "$srcdir"/0009-glitched-ondemand-bmq.patch fi msg2 "Applying Glitched BMQ patch" - patch -Np1 -i "$_where"/0009-glitched-bmq.patch - msg2 "Done" + patch -Np1 -i "$srcdir"/0009-glitched-bmq.patch else msg2 "Applying Glitched CFS patch" - patch -Np1 -i "$_where"/0003-glitched-cfs.patch - msg2 "Done" + patch -Np1 -i "$srcdir"/0003-glitched-cfs.patch fi if [ "${_distro}" == "Arch" ]; then @@ -718,8 +697,7 @@ _tkg_srcprep() { fi if [ "$CONDITION7" == "y" ] || [ "$_acs_override" == "true" ]; then msg2 "Patching ACS override" - patch -Np1 -i "$_where"/0006-add-acs-overrides_iommu.patch - msg2 "Done" + patch -Np1 -i "$srcdir"/0006-add-acs-overrides_iommu.patch fi # bcachefs @@ -731,8 +709,7 @@ _tkg_srcprep() { fi if [ "$CONDITION8" == "y" ] || [ "$_bcachefs" == "true" ]; then msg2 "Patching Bcache filesystem support override" - patch -Np1 -i "$_where"/0008-5.7-bcachefs.patch - msg2 "Done" + patch -Np1 -i "$srcdir"/0008-5.7-bcachefs.patch echo "CONFIG_BCACHEFS_FS=m" >> ./.config echo "CONFIG_BCACHEFS_QUOTA=y" >> ./.config @@ -751,8 +728,7 @@ _tkg_srcprep() { fi if [ "$CONDITION9" == "y" ] || [ "$_fsync" == "true" ]; then msg2 "Patching Fsync support" - patch -Np1 -i "$_where"/0007-v5.7-fsync.patch - msg2 "Done" + patch -Np1 -i "$srcdir"/0007-v5.7-fsync.patch fi # ZFS fix @@ -764,8 +740,7 @@ _tkg_srcprep() { fi if [ "$CONDITION11" == "y" ] || [ "$_zfsfix" == "true" ]; then msg2 "Patching missing symbol for AES-NI/AVX support on ZFS" - patch -Np1 -i "$_where"/0011-ZFS-fix.patch - msg2 "Done" + patch -Np1 -i "$srcdir"/0011-ZFS-fix.patch fi # Community patches @@ -775,7 +750,7 @@ _tkg_srcprep() { fi _community_patches=($_community_patches) for _p in ${_community_patches[@]}; do - ln -s "$_where"/../../community-patches/linux57-tkg/$_p "$_where"/ + ln -s "$_where"/../../community-patches/linux"$_basever"-tkg/$_p "$_where"/ done fi @@ -902,3 +877,85 @@ _tkg_srcprep() { msg2 "Prepared %s version %s" "$pkgbase" "$(