Skip to content

Commit

Permalink
ostree-grub-generator: allow adding custom scripts to grub.cfg
Browse files Browse the repository at this point in the history
This changes allow us to customize grub.cfg without manually editing it.

Now, whatever files found under /etc/ostree.d are added (in alphabetical
order) between the cfg header and its menuentries, allowing to add
custom logic to the bootloader in a non intrusive way.

Signed-off-by: Eduardo Ferreira <[email protected]>
  • Loading branch information
EdTheBearded committed Feb 8, 2024
1 parent da89214 commit c9260ff
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/boot/grub2/ostree-grub-generator
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ script=$(basename ${0})
# Atomically safe location where to generete grub.cfg when executing system upgrade.
new_grub2_cfg=${2}
entries_path=$(dirname $new_grub2_cfg)/entries
custom_scripts="/etc/ostree.d"

read_config()
{
Expand Down Expand Up @@ -105,10 +106,22 @@ timeout=10
EOF
}

populate_custom_section()
{
if [ -d "$custom_scripts" ]; then
for script in $(ls -v $custom_scripts/*); do
echo -e "\n### BEGIN ${script} ###" >> ${new_grub2_cfg}
cat ${script} >> ${new_grub2_cfg}
echo -e "\n### END ${script} ###\n" >> ${new_grub2_cfg}
done
fi
}

generate_grub2_cfg()
{
populate_warning
populate_header
populate_custom_section
populate_menu
}

Expand Down

0 comments on commit c9260ff

Please sign in to comment.