#!/bin/bash function check_root { [ $EUID -eq 0 ] && return echo "refind-menu-generator requires root privileges to work" >&2 exit 1 } check_root ESP_PATH=$(bootctl --print-esp-path) echo $ESP_PATH if [ -z "$ESP_PATH" ]; then exit 1 else if [ ! -d "${ESP_PATH}/EFI/Linux" ]; then if [ -d "${ESP_PATH}/EFI/linux" ]; then KERNEL_DIR="${ESP_PATH}/EFI/linux" fi else KERNEL_DIR="${ESP_PATH}/EFI/Linux" fi if [ -z "$KERNEL_DIR" ]; then mkdir -p "${ESP_PATH}/EFI/Linux" KERNEL_DIR="${ESP_PATH}/EFI/linux" fi fi echo $KERNEL_DIR theme=$(cat "$ESP_PATH/EFI/refind/refind.conf" | grep themes | cut -d"/" -f2) if [ -d $KERNEL_DIR ]; then if [ -f "$ESP_PATH/EFI/Linux/cmdline.txt" ]; then CMDLINE=$(sed -e 's/^[[:space:]]//g' -e 's/[[:space:]]$//g' "$ESP_PATH/EFI/Linux/cmdline.txt") elif [ -f "/etc/kernel/cmdline" ]; then CMDLINE=$(sed -e 's/^[[:space:]]//g' -e 's/[[:space:]]$//g' "/etc/kernel/cmdline") else CMDLINE=$(sed -e 's/^[[:space:]]//g' -e 's/[[:space:]]$//g' -e 's/initrd.*$//g' "/proc/cmdline") fi echo $CMDLINE manual_conf=$(mktemp) template="/etc/refind-menu-generator/menu-template.txt" for i in $(ls -1 /efi/EFI/Linux/ | grep 'linu' | grep -v 'fallback' | grep '\.efi$'); do kernel=$(echo $i | sed 's/\.efi//g') kernel_efi=$kernel kernel_vmlinuz="vmlinuz-$kernel" osname=$(cat /etc/os-release | grep "^NAME=" | cut -d'=' -f2 | sed -e 's/"//g') icon=$(cat /etc/os-release | grep "^ID=" | cut -d'=' -f2 | sed -e 's/"//g') initramfs_tpl=$(echo "initramfs-$kernel" | sed "s/vmlinuz-//g") initramfs=$(echo "$initramfs_tpl.img") initramfs_fallback=$(echo "$initramfs_tpl-fallback.img") sed -e "s/{OSNAME}/$osname/g" -e "s/{THEME}/$theme/g" -e "s/{ICON}/$icon/g" -e "s/{KERNEL}/$kernel/g" -e "s/{KERNEL_EFI}/$kernel_efi/g" -e "s/{KERNEL_VMLINUZ}/$kernel_vmlinuz/g" -e "s/{INITRAMFS}/$initramfs/g" -e "s/{INITRAMFS_FALLBACK}/$initramfs_fallback/g" -e "s/{CMDLINE}/$CMDLINE/g" $template >> $manual_conf done manual_end_conf=$(mktemp) template_end="/etc/refind-menu-generator/menu-end.txt" sed -e "s/{THEME}/$theme/g" $template_end >> $manual_end_conf cat $manual_end_conf >> $manual_conf sudo cp -vf $manual_conf "$ESP_PATH/EFI/refind/manual.conf" sudo cp -vf $manual_conf "$ESP_PATH/EFI/boot/manual.conf" rm -f $manual_conf rm -f $manual_end_conf fi