Skip to content

Commit

Permalink
src: deploy: Add new kernels to the end of the file
Browse files Browse the repository at this point in the history
This commit ensures that we do not pollute the config.txt file by
removing kernels name duplications and adding the new kernel to the end.

Signed-off-by: Rodrigo Siqueira <siqueirajordao@riseup.net>
  • Loading branch information
rodrigosiqueira committed Mar 26, 2022
1 parent a1bcf1b commit 97b8db4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/plugins/kernel_install/rpi_bootloader.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ function run_bootloader_update()
find_target=$(basename "$find_target")

# Check if the kernel name were already added to config.txt
grep --quiet --extended-regexp "kernel=*.$find_target*." "$RPI_CONFIG_TXT_PATH"
[[ "$?" == 0 && -n "$find_target" ]] && return
grep --quiet --extended-regexp "^kernel=*.$find_target" "$RPI_CONFIG_TXT_PATH"
if [[ "$?" == 0 && -n "$find_target" ]]; then
return
fi

# If we find a kernel name in the config file, and no kernel image we
# want to remove that reference.
Expand All @@ -44,6 +46,14 @@ function run_bootloader_update()
cmd="$sudo_cmd sed -i '/^kernel=/s/^/#/' $RPI_CONFIG_TXT_PATH"
cmd_manager "$flag" "$cmd"

# If the target kernel is commented in the file, let's remove it and add it
# to the end of the file (easier to debug).
grep --quiet --extended-regexp "#kernel=*.$find_target" "$RPI_CONFIG_TXT_PATH"
if [[ "$?" == 0 ]]; then
cmd="$sudo_cmd sed -i '/#kernel=*.$find_target/d' $RPI_CONFIG_TXT_PATH"
cmd_manager "$flag" "$cmd"
fi

# Add new kernel to the config file
cmd="printf \"%s\n\" kernel=$find_target >> $RPI_CONFIG_TXT_PATH"
if [[ "$target" == 'local' ]]; then
Expand Down
22 changes: 22 additions & 0 deletions tests/plugins/kernel_install/rpi_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,28 @@ function test_remote_other_files_with_similar_name()
assertEquals "($LINENO): " "kernel-$kernel_name-42" "$output"
}

function test_remote_add_the_same_kernel_twice()
{
local output
local kernel_name='CASUAL'

touch "kernel-${kernel_name}-42"
touch "config-${kernel_name}-42"

touch "kernel-${kernel_name}-41"
touch "config-${kernel_name}-41"

run_bootloader_update 'SILENT' 'remote' "$kernel_name-42"
run_bootloader_update 'SILENT' 'remote' "$kernel_name-41"
run_bootloader_update 'SILENT' 'remote' "$kernel_name-42"

output=$(get_kernel_from_config)
assertEquals "($LINENO): " "kernel-$kernel_name-42" "$output"

output=$(grep "#kernel=kernel-$kernel_name-42" 'config.txt')
assertEquals "($LINENO): " "" "$output"
}

function test_remote_remove_kernel()
{
local output
Expand Down

0 comments on commit 97b8db4

Please sign in to comment.