Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 1ee4c91
Author: Uri Herrera <[email protected]>
Date:   Sat Nov 2 14:08:46 2024 -0600

    show update-grub output

commit 1df57e8
Author: Uri Herrera <[email protected]>
Date:   Sat Nov 2 06:17:15 2024 -0600

    enchance  nuts-ccu

    to handle case-sensitive cases, partial matching for sub-params, add logic to remove duplicates

commit d88b2ce
Author: Uri Herrera <[email protected]>
Date:   Sat Nov 2 06:08:17 2024 -0600

    add new kernel params to existing grub config

commit 54f0eb8
Author: Uri Herrera <[email protected]>
Date:   Thu Oct 31 20:25:00 2024 -0600

    ...

commit 7f1a421
Author: Uri Herrera <[email protected]>
Date:   Thu Oct 31 19:56:45 2024 -0600

    rm sudo

    godfkndmt

commit 0ab1d1e
Author: Uri Herrera <[email protected]>
Date:   Thu Oct 31 19:29:38 2024 -0600

    run xone and xpadneon scripts

    to update the drivers

commit 5d2fe13
Author: Uri Herrera <[email protected]>
Date:   Thu Oct 31 19:14:02 2024 -0600

    rm older kernel when updating

commit c1da2c5
Author: Uri Herrera <[email protected]>
Date:   Thu Oct 31 18:52:52 2024 -0600

    mount /var/lib for update-grub

commit eacc51f
Author: Uri Herrera <[email protected]>
Date:   Thu Oct 31 18:38:28 2024 -0600

    chk ota

    ffs

commit db963da
Author: Uri Herrera <[email protected]>
Date:   Thu Oct 31 18:09:26 2024 -0600

    chk ota

commit 58e12a9
Author: Uri Herrera <[email protected]>
Date:   Thu Oct 31 17:48:50 2024 -0600

    chk ota

commit 451d41f
Author: Uri Herrera <[email protected]>
Date:   Mon Oct 21 16:11:41 2024 -0600

    ...

commit d9f91a0
Author: Uri Herrera <[email protected]>
Date:   Mon Oct 21 16:11:17 2024 -0600

    ensure xone and xpadneo are built

    when a new kernel is added
  • Loading branch information
UriHerrera committed Nov 2, 2024
1 parent a80c129 commit 6c23bed
Showing 1 changed file with 146 additions and 1 deletion.
147 changes: 146 additions & 1 deletion tmp/nuts-ccu
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,153 @@ update-initramfs -c -k all


# -- Update GRUB.
# -- Whenever we add new parameters, ensure that these are added to existing installations.

GRUB_FILE="/etc/default/grub"
BACKUP_FILE="/etc/default/grub.bak"

REQUIRED_PARAMS=(
"amdgpu.cik_support=1"
"amdgpu.ppfeaturemask=0xffffffff"
"amdgpu.si_support=1"
"amdgpu.vm_update_mode=3"
"apparmor=1"
"cfi=kcfi"
"hardened_usercopy=1"
"hpet=disable"
"init_on_free=1"
"intel_pstate=enable"
"libahci.ignore_sss=1"
"modprobe.blacklist=iTCO_wdt"
"modprobe.blacklist=sp5100_tco"
"nosgx"
"nvidia_drm.modeset=1"
"nvme_core.multipath=Y"
"overlayroot=tmpfs:swap=1,recurse=0"
"page_alloc.shuffle=1"
"quiet"
"radeon.cik_support=0"
"radeon.si_support=0"
"randomize_kstack_offset=on"
"rcu_nocbs=all"
"rcupdate.rcu_expedited=1"
"rcutree.enable_rcu_lazy=1"
"security=apparmor"
"slab_nomerge"
"slub_debug=FZ"
"usbcore.autosuspend=-1"
"vdso32=0"
"vsyscall=none"
"zswap.compressor=zstd"
"zswap.enabled=1"
"zswap.max_pool_percent=20"
"zswap.zpool=zsmalloc"
"splash"
)

param_exists() {
local target_lower
target_lower=$(echo "$1" | tr '[:upper:]' '[:lower:]')
for existing_param in "${unique_params[@]}"; do
local existing_lower
existing_lower=$(echo "$existing_param" | tr '[:upper:]' '[:lower:]')
if [[ "$existing_lower" == "$target_lower" ]]; then
return 0
fi
done
return 1
}

handle_modprobe_blacklist() {
local required_param="$1"
local key="modprobe.blacklist="
if [[ "$required_param" == $key* ]]; then
local module
module=$(echo "$required_param" | cut -d'=' -f2)
local existing_entry=""
for i in "${!unique_params[@]}"; do
if [[ "${unique_params[i],,}" == modprobe.blacklist=* ]]; then
existing_entry="${unique_params[i]}"
break
fi
done
if [ -n "$existing_entry" ]; then
local modules
modules=$(echo "$existing_entry" | cut -d'=' -f2)
IFS=',' read -r -a existing_modules <<< "$modules"
local module_found=false
for em in "${existing_modules[@]}"; do
if [[ "${em,,}" == "${module,,}" ]]; then
module_found=true
break
fi
done
if [ "$module_found" = false ]; then
existing_modules+=("$module")
unique_params=("${unique_params[@]/$existing_entry/}")
unique_params+=("modprobe.blacklist=$(IFS=, ; echo "${existing_modules[*]}")")
fi
else
unique_params+=("$required_param")
fi
else
if ! param_exists "$required_param"; then
unique_params+=("$required_param")
fi
fi
}

if [ ! -f "$GRUB_FILE" ]; then
puts_error "$GRUB_FILE not found, quitting."
fi

cp "$GRUB_FILE" "$BACKUP_FILE"

current_line=$(grep '^GRUB_CMDLINE_LINUX_DEFAULT=' "$GRUB_FILE" || true)

if [ -n "$current_line" ]; then
current_params=$(echo "$current_line" | sed -E 's/GRUB_CMDLINE_LINUX_DEFAULT="(.*)"/\1/')
read -r -a param_array <<< "$current_params"

unique_params=()
for param in "${param_array[@]}"; do
param_lower=$(echo "$param" | tr '[:upper:]' '[:lower:]')
found=false
for up in "${unique_params[@]}"; do
up_lower=$(echo "$up" | tr '[:upper:]' '[:lower:]')
if [[ "$up_lower" == "$param_lower" ]]; then
found=true
break
fi
done
if [ "$found" = false ]; then
unique_params+=("$param")
fi
done

for req_param in "${REQUIRED_PARAMS[@]}"; do
handle_modprobe_blacklist "$req_param"
done

updated_params="${unique_params[*]}"
else
updated_params="${REQUIRED_PARAMS[*]}"
fi

new_line="GRUB_CMDLINE_LINUX_DEFAULT=\"${updated_params}\""

if grep -q '^GRUB_CMDLINE_LINUX_DEFAULT=' "$GRUB_FILE"; then
sed -i "s|^GRUB_CMDLINE_LINUX_DEFAULT=.*|$new_line|" "$GRUB_FILE"
puts_success "Updated GRUB_CMDLINE_LINUX_DEFAULT in $GRUB_FILE."
else
echo "$new_line" >> "$GRUB_FILE"
puts_success "Added GRUB_CMDLINE_LINUX_DEFAULT to $GRUB_FILE."
fi

puts_success "Kernel parameters have been successfully added to $GRUB_FILE, continuing..."

if update-grub > /dev/null 2>&1; then
if command -v update-grub >/dev/null 2>&1; then
update-grub
puts_success "Success! GRUB menu was updated, continuing..."
else
puts_error "Failed to update GRUB menu, quitting."
Expand Down

0 comments on commit 6c23bed

Please sign in to comment.