From c92a1142053eff9b52d1f40fec0a80d1186f252a Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 10 Nov 2023 20:09:15 +0100 Subject: [PATCH] grub.cfg.sh --- build.sh | 109 ++++++-------------------------------------- grub.cfg.sh | 107 +++++++++++++++++++++++++++++++++++++++++++ live/main.sh | 1 - live/menu/cmd.sh | 1 - live/menu/env.sh | 1 - live/menu/gfx.sh | 1 - live/menu/scan.sh | 1 - live/menu/set.sh | 1 - live/source/boot.sh | 40 +++++++++------- live/source/menu.sh | 1 + 10 files changed, 144 insertions(+), 119 deletions(-) create mode 100644 grub.cfg.sh diff --git a/build.sh b/build.sh index 25ecf29..ce8dc19 100644 --- a/build.sh +++ b/build.sh @@ -55,7 +55,7 @@ source "${NAME%.*}.mod" MEMDISK_ROOT='boot' MEMDISK_DIRECTORY="${MEMDISK_ROOT}/grub" MEMDISK_FILE="${MEMDISK_DIRECTORY}/grub.cfg" -MEMDISK_PUB="${MEMDISK_DIRECTORY}/grub.pub" +MEMDISK_PUB="${MEMDISK_DIRECTORY}/grub.pgp" MEMDISK_ARCHIVE="${MEMDISK_ROOT}.tar" UEFI_ROOT="${ROOT}/efi" UEFI_DIRECTORY="${UEFI_ROOT}/boot" @@ -70,7 +70,7 @@ COMPRESSION='xz' GRUB_ROOT="${ROOT}/boot/grub" GRUB_CFG="${GRUB_ROOT}/grub.cfg" GRUB_ENV="${ROOT}/grub.env" -GRUB_PUB="${GRUB_ROOT}/grub.pub" +GRUB_PUB="${GRUB_ROOT}/grub.pgp" # wipe ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ @@ -175,102 +175,20 @@ mkdir --parents "${GRUB_ROOT}" # grub / cfg ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ -echo -n "\ -function list_vars { - echo -n \"\\ - root | \${root} - prefix | \${prefix} -check_signatures | \${check_signatures} -\" - list_trusted -} - -clear -ls -echo -n \"\\ - --- - cpu-platform | \${grub_cpu}-\${grub_platform} - cmdpath | \${cmdpath} - --- -\" -if [ -f '/.disk/info' -o -f '/.disk/mini-info' ] ; then - for f in '/.disk/info' '/.disk/mini-info' ; do - echo -n ' |' - if [ -f \"\${f}\" ] ; then - echo -n '*' - else - echo -n ' ' - fi - echo \"(\${root})\${f}\" - done - unset f - echo ' *' -fi -list_vars -echo ' ---' - -unset cmdroot -regexp --set cmdroot '^\((.*)\)' \"\${cmdpath}\" -echo \" cmdroot | \${cmdroot}\" -if [ \"\${cmdroot}\" != \"\${root}\" ] ; then - if [ -d \"(\${cmdroot})/boot/grub/\${grub_cpu}-\${grub_platform}\" ] ; then - prefix=\"(\${cmdroot})/boot/grub\" - root=\"\${cmdroot}\" - fi -fi -unset cmdroot -check_signatures='enforce' -trust --skip-sig \"\${prefix}/grub.pub\" - -function set_init { - data_uuid='${DATA}' - search --no-floppy --set data \\ - --fs-uuid \"\${data_uuid}\" - # - unset esp - regexp --set esp '^\((.*)\)' \"\${prefix}\" - env=\"(\${esp})/grub.env\" - live=\"(\${esp})/${PROJECT}/live\" - # - for file in \${live}/source/*.sh ; do - source \"\${file}\" - done - unset file -} - -set_init - -source \"\${live}/main.sh\" - -echo ' *' -list_vars -echo -n \"\\ - --- - escape | \" -sleep --interruptible --verbose 1000 -" > "${GRUB_CFG}" +cp "${DIRECTORY}/grub.cfg.sh" "${GRUB_CFG}" # grub / env ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ -echo -n "\ -# GRUB Environment Block -#######################################\ -################################################################\ -################################################################\ -################################################################\ -################################################################\ -################################################################\ -################################################################\ -################################################################\ -################################################################\ -################################################################\ -################################################################\ -################################################################\ -################################################################\ -################################################################\ -################################################################\ -################################################################\ -" > "${GRUB_ENV}" +grubenv="# GRUB Environment Block +live_name=${PROJECT} +data_uuid=${DATA} +" +grublen=${#grubenv} +while [ $grublen -lt 1024 ] ; do + grubenv="${grubenv}#" + grublen=${#grubenv} +done +echo -n "${grubenv}" > "${GRUB_ENV}" # grub / fonts ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ @@ -313,7 +231,6 @@ for target in 'x86_64-efi' 'i386-pc' ; do mkdir --parents "${GRUB_ROOT}/${target}" cd "/usr/lib/grub/${target}" for module in *.lst *.mod ; do - echo "${target}/${module}" cp "${module}" "${GRUB_ROOT}/${target}" done done diff --git a/grub.cfg.sh b/grub.cfg.sh new file mode 100644 index 0000000..37ceaa5 --- /dev/null +++ b/grub.cfg.sh @@ -0,0 +1,107 @@ +function grub_fix { + unset cmdroot + regexp --set cmdroot '^\((.*)\)' "${cmdpath}" + if [ "${cmdroot}" != "${root}" ] ; then + echo -n "\ + |*${cmdpath} +" + if [ -d "(${cmdroot})/boot/grub/${grub_cpu}-${grub_platform}" ] ; then + prefix="(${cmdroot})/boot/grub" + root="${cmdroot}" + fi + fi + unset cmdroot + check_signatures='enforce' + trust --skip-sig "${prefix}/grub.pgp" +} + +function grub_list_const { + echo -n "\ + cpu-platform | ${grub_cpu}-${grub_platform} + cmdpath | ${cmdpath} +" +} + +function grub_list_info { + if [ -f '/.disk/info' -o -f '/.disk/mini-info' ] ; then + for f in '/.disk/info' '/.disk/mini-info' ; do + echo -n "\ + |" + if [ -f "${f}" ] ; then + echo -n '*' + else + echo -n ' ' + fi + echo "(${root})${f}" + done + unset f + fi +} + +function grub_list_vars { + echo -n "\ + root | ${root} + prefix | ${prefix} +check_signatures | ${check_signatures} +" + list_trusted +} + +function grub_list_xtra { + echo -n "\ + env | ${env} + live | ${live} + data | ${data} +" +} + +function grub_main { + ls + grub_list_const + grub_split + if [ ! "${data}" ] ; then + grub_list_info + grub_list_vars + grub_split + # + grub_fix + set_init + for file in ${live}/source/*.sh ; do + source "${file}" + done + unset file + source "${live}/main.sh" + fi + grub_list_vars + grub_list_xtra + grub_split + grub_pause +} + +function grub_pause { + echo -n "\ + escape | " + sleep --interruptible --verbose 1000 +} + +function grub_split { + echo -n "\ + --- +" +} + +function set_init { + regexp --set esp '^\((.*)\)' "${prefix}" + # + env="(${esp})/grub.env" + # + load_env --skip-sig --file "${env}" \ + 'live_name' 'data_uuid' + # + live="(${esp})/${live_name}/live" + # + search --no-floppy --set data \ + --fs-uuid "${data_uuid}" +} + +grub_main diff --git a/live/main.sh b/live/main.sh index b68f709..a03a63c 100644 --- a/live/main.sh +++ b/live/main.sh @@ -1,4 +1,3 @@ -env_init menu_init default='scan' diff --git a/live/menu/cmd.sh b/live/menu/cmd.sh index eece47c..b995d77 100644 --- a/live/menu/cmd.sh +++ b/live/menu/cmd.sh @@ -1,4 +1,3 @@ -env_init menu_init menuentry 'halt' { halt } diff --git a/live/menu/env.sh b/live/menu/env.sh index e97968a..b538584 100644 --- a/live/menu/env.sh +++ b/live/menu/env.sh @@ -1,4 +1,3 @@ -env_init menu_init "${env} → ${env_mod}" menuentry 'list file' { diff --git a/live/menu/gfx.sh b/live/menu/gfx.sh index 61dbd0e..ac704fe 100644 --- a/live/menu/gfx.sh +++ b/live/menu/gfx.sh @@ -1,4 +1,3 @@ -env_init menu_init menuentry 'list' { diff --git a/live/menu/scan.sh b/live/menu/scan.sh index 5096cdb..a05e604 100644 --- a/live/menu/scan.sh +++ b/live/menu/scan.sh @@ -1,4 +1,3 @@ -env_init menu_init "${scan}" scan "${scan}" diff --git a/live/menu/set.sh b/live/menu/set.sh index 77951ba..b1fcb10 100644 --- a/live/menu/set.sh +++ b/live/menu/set.sh @@ -1,4 +1,3 @@ -env_init menu_init default='split' diff --git a/live/source/boot.sh b/live/source/boot.sh index 34b713b..49ca5df 100644 --- a/live/source/boot.sh +++ b/live/source/boot.sh @@ -1,18 +1,24 @@ function debsquash { lmp="${1}" sfs="filesystem.squashfs" - if [ -f "(${data})${lmp}/vmlinuz" ]; then - linux_path="(${data})${lmp}/vmlinuz" - initrd_path="(${data})${lmp}/initrd.img" - else - linux_path="(squash)/vmlinuz" - initrd_path="(squash)/initrd.img" - loopback "squash" "${lmp}/${sfs}" - fi + chk="(${data})${lmp}/${sfs}" # - echo 'linux' - echo "${linux_path}" - linux \ + echo 'verify_detached' + echo "${chk}" + if verify_detached "${chk}" "${chk}.sig" ; then + if [ -f "(${data})${lmp}/vmlinuz" ]; then + linux_path="(${data})${lmp}/vmlinuz" + initrd_path="(${data})${lmp}/initrd.img" + else + linux_path="(squash)/vmlinuz" + initrd_path="(squash)/initrd.img" + loopback "squash" "${lmp}/${sfs}" + fi + # + echo + echo 'linux' + echo "${linux_path}" + linux \ "${linux_path}" \ boot="live" \ elevator="deadline" \ @@ -20,10 +26,10 @@ ip="frommedia" \ live-media-path="${lmp}" \ live-media-uuid="${data_uuid}" \ toram="${sfs}" - # - echo - # - echo 'initrd' - echo "${initrd_path}" - initrd "${initrd_path}" + # + echo + echo 'initrd' + echo "${initrd_path}" + initrd "${initrd_path}" + fi } diff --git a/live/source/menu.sh b/live/source/menu.sh index e4a96b4..e106b1f 100644 --- a/live/source/menu.sh +++ b/live/source/menu.sh @@ -16,6 +16,7 @@ function menu_color { } function menu_init { + env_init if [ "${menu}" ] ; then if [ "${1}" ] ; then menuentry "→ ${menu} → ${1}" { nop }