Fresh eyes - my sed command will not do what I want

I have file with content - part of ISO grub configuration - the interesting part is the last 8 lines ( the whole file is provided - in case the context matters )

ISO grub configuration
for kk in /boot/vmlinu*-*64; do
if [ "$kk" != "/boot/vmlinu*-*64" ]; then
    have64="true"
    if cpuid -l; then
        have_kernel="true"
    else
        have_kernel="false"
    fi
fi
done
for kk in /boot/vmlinu*-*86; do
if [ "$kk" != "/boot/vmlinu*-*86" ]; then
    have32="true"
    have_kernel="true"
fi
done
if [ "${have_kernel}" != "true" ]; then
    menuentry --class=find.none "NO SUITABLE KERNELS AVAILABLE" {echo $@  echo "There are no kernels suitable for this machine available."
        echo ""
        if ! cpuid -l; then
            echo "This machine is NOT 64bit capable."
            echo ""
        fi
        echo "There are no suitable kernels available"
        if [ "${have64}" == "true" ]; then
            echo ""
            echo "It appears you are trying to boot a 64bit release on a 32bit machine"
            echo "This cannot work!"
        fi
        echo ""
        echo "Press Escape to return to the main menu"
        sleep --interruptible 9999
        menu_reload
    }
else
    title=""
    for kopt in x86_64 $kopts  misobasedir=manjaro misolabel=MANJARO_BOBRESCUEM_2314 quiet systemd.show_status=1 splash; do
        if [ -n "$title" ] ; then
            title="$title $kopt";
        else
            title="$kopt";
        fi;
    done
    menuentry "Boot Manjaro Live Rescue" --class=Manjaro.x86_64 "$title" {# set arguments above with the editor
        linux /boot/vmlinuz-$2 driver=free nouveau.modeset=1 i915.modeset=1 radeon.modeset=1
        initrd /boot/amd_ucode.img /boot/intel_ucode.img /boot/initramfs-x86_64.img
    }
    menuentry "Boot with proprietary drivers" --class=Manjaro.x86_64 "$title" {# set arguments above with the editor
        linux /boot/vmlinuz-$2 driver=nonfree nouveau.modeset=0 i915.modeset=1 radeon.modeset=1
        initrd /boot/amd_ucode.img /boot/intel_ucode.img /boot/initramfs-x86_64.img
    }
fi
for kk in /boot/vmlinu*-*64; do
if [ "$kk" != "/boot/vmlinu*-*64" ]; then
    have64="true"
    if cpuid -l; then
        have_kernel="true"
    else
        have_kernel="false"
    fi
fi
done
for kk in /boot/vmlinu*-*86; do
if [ "$kk" != "/boot/vmlinu*-*86" ]; then
    have32="true"
    have_kernel="true"
fi
done
if [ "${have_kernel}" != "true" ]; then
    menuentry --class=find.none "NO SUITABLE KERNELS AVAILABLE" {echo $@  echo "There are no kernels suitable for this machine available."
        echo ""
        if ! cpuid -l; then
            echo "This machine is NOT 64bit capable."
            echo ""
        fi
        echo "There are no suitable kernels available"
        if [ "${have64}" == "true" ]; then
            echo ""
            echo "It appears you are trying to boot a 64bit release on a 32bit machine"
            echo "This cannot work!"
        fi
        echo ""
        echo "Press Escape to return to the main menu"
        sleep --interruptible 9999
        menu_reload
    }
else
    title=""
    for kopt in x86_64 $kopts  misobasedir=manjaro misolabel=MANJARO_BOBRESCUEM_2314 quiet systemd.show_status=1 splash; do
        if [ -n "$title" ] ; then
            title="$title $kopt";
        else
            title="$kopt";
        fi;
    done
    menuentry "Boot with open source drivers" --class=Manjaro.x86_64 "$title" {# set arguments above with the editor
        linux /boot/vmlinuz-$2 driver=free nouveau.modeset=1 i915.modeset=1 radeon.modeset=1
        initrd /boot/amd_ucode.img /boot/intel_ucode.img /boot/initramfs-x86_64.img
    }
    menuentry "Boot with proprietary drivers" --class=Manjaro.x86_64 "$title" {# set arguments above with the editor
        linux /boot/vmlinuz-$2 driver=nonfree nouveau.modeset=0 i915.modeset=1 radeon.modeset=1
        initrd /boot/amd_ucode.img /boot/intel_ucode.img /boot/initramfs-x86_64.img
    }
fi
mod-iso-menu.sh
#!/usr/bin/env bash

usage(){
	echo "usage: sudo mod-iso-menu.sh <profile> 'Boot Live ISO'"
	exit 1
}

if [[ ${EUID} != 0 || -z "$1" || -z "$2" ]]; then
    usage
fi

LIBDIR="/usr/lib/manjaro-tools/"
USERCONFDIR="/home/fh/.config/manjaro-tools"
user_cfg="${USERCONFDIR}/manjaro-tools.conf"

# shellcheck source=/dev/null
[[ -r ${LIBDIR}/util-msg.sh ]] && source ${LIBDIR}/util-msg.sh
import ${LIBDIR}/util.sh

chroots_dir=
load_config ${user_cfg}

kernels_cfg="${chroots_dir}/buildiso/${1}/iso/boot/grub/kernels.cfg"

if ! [[ -d "${chroots_dir}/buildiso/${1}" ]]; then
    echo "'${1}' has not been build"
	exit 1
fi

msg "Modifying live '$1' bootloader menu '$2'"

# change entry for opensource gpu driver
info "Change menu name to ${2}"
sed -i "s/Boot with open source drivers/${2}/g" "${kernels_cfg}"
# remove entry for proprietary gpu drivers
info "Remove proprietary driver menu"
sed -i '/menuentry \"Boot with proprietary drivers\"/,+3d' "${kernels_cfg}"
msg "Modified '$1' with '$2'"

The purpose is to modify my ISO removing one menu and altering another.

I have this script - which takes two arguments - the iso profile to modify and the string to be used when modifying the menu.

The sed -i argument is removed for debugging purpose.

The first part work as intended - removing the menu providing proprietary drivers

# remove entry for proprietary gpu drivers
sed '/menuentry \"Boot with proprietary drivers\"/,+3d' "${kernels_cfg}"

I use double quotes because I want the second argument to be expanded - and it does expand - but sed does not edit the file and I cannot figure out why

# change entry for opensource gpu driver
echo sed "s/Boot with open source drivers/${2}/g" "${kernels_cfg}"
sed "s/Boot with open source drivers/${2}/g" "${kernels_cfg}"

if I run grep on the file - I get the line

$ grep -e 'Boot with open source drivers' <buildroot>/buildiso/<profile>/iso/boot/grub/kernels.cfg 
    menuentry "Boot with open source drivers" --class=Manjaro.x86_64 "$title" {# set arguments above with the editor

Hm, not sure. Seems to work fine if I do it in terminal.

What if you use

sed 's/Boot with open source drivers/'"${2}"'/g' "${kernels_cfg}"

:facepalm:

the script provides two variants when not using -i - I have been blindly looking at the last section - I added a couple of messages - then it dawned on me - thank you for the nudge :gear:

This topic was automatically closed 36 hours after the last reply. New replies are no longer allowed.