VTOYEFI: keep grub.cfg without paravis_return; patch only grbp.cfg

This commit is contained in:
Paravis committed 2026-11-27 18:15:08 +03:00
1 parent ada702754c
commit e0ac4aac3d
1 file changed
+32 -31
+32 -31
View File
@@ -1,30 +1,33 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
"""Add the "return to Paravis main menu" item to Ventoy's grub.cfg. """Build VTOYEFI/grub/grbp.cfg with the Paravis return entry.
The extra menu entry chainloads the Paravis boot menu: grub.cfg is the normal Ventoy config (direct boot, UEFI and legacy) and must
NOT contain the "return to Paravis" item. Only grbp.cfg - loaded by
* UEFI -> /efi/Paravis/Boot/grub2/grubx64.efi grubx64_parv.efi when Ventoy is chainloaded from the Paravis menu - gets it.
* BIOS -> MBR of the Ventoy disk: chainloader (${vtoydev})+1
Usage: Usage:
python3 patch_ventoy_paravis_return.py <path-to-grub/grub.cfg> python3 patch_ventoy_paravis_return.py <path-to-grub/grub.cfg>
The patched file is written back to grub.cfg and copied to grbp.cfg in the The script never modifies grub.cfg. If grub.cfg is already patched, it
same directory. grbp.cfg is loaded by the UEFI build (grubx64_parv.efi) that refuses to run, so a regression cannot be silently re-introduced.
the Paravis menu chainloads; the legacy core.img loads grub.cfg.
""" """
import io import io
import os import os
import sys import sys
FUNC = '''function paravis_return { FUNC = r'''function paravis_return {
if [ "$grub_platform" = "efi" ]; then if [ "$grub_platform" = "efi" ]; then
search --no-floppy --file --set=root /efi/Paravis/Boot/grub2/grub.cfg set pvroot=
search --no-floppy --file --set=pvroot /efi/Paravis/Boot/grub2/grub.cfg
if [ -z "$pvroot" ]; then
echo "Paravis Flash not found"
return
fi
if [ "$grub_cpu" = "x86_64" ]; then if [ "$grub_cpu" = "x86_64" ]; then
chainloader /efi/Paravis/Boot/grub2/grubx64.efi chainloader ($pvroot)/efi/BOOT/bootx64.efi
else else
chainloader /EFI/Boot/bootia32.efi chainloader ($pvroot)/efi/BOOT/bootia32.efi
fi fi
else else
chainloader (${vtoydev})+1 chainloader (${vtoydev})+1
@@ -33,13 +36,16 @@ FUNC = '''function paravis_return {
} }
''' '''
MENU = '''menuentry "Возврат в главное меню Paravis Flash" --id="paravis_return" --class="vtoyret" { MENU = r'''menuentry "Возврат в главное меню Paravis Flash" --id="paravis_return" --class="vtoyret" {
paravis_return paravis_return
} }
set default="paravis_return" set default="paravis_return"
''' '''
ANCHOR_FUNC = 'function ventoy_ext_menu {'
ANCHOR_MENU = '#special VTOY_DEFAULT_IMAGE process'
def main(): def main():
if len(sys.argv) != 2: if len(sys.argv) != 2:
@@ -49,29 +55,24 @@ def main():
path = sys.argv[1] path = sys.argv[1]
text = io.open(path, encoding='utf-8', newline='').read() text = io.open(path, encoding='utf-8', newline='').read()
if 'function paravis_return' in text: if 'function paravis_return' in text or '--id="paravis_return"' in text:
print('already patched: ' + path) print('grub.cfg already contains paravis_return, expected a clean source: ' + path)
else: return 1
anchor = 'function ventoy_ext_menu {' if text.count(ANCHOR_FUNC) != 1:
if text.count(anchor) != 1: print('anchor not found or not unique: ' + ANCHOR_FUNC)
print('anchor not found or not unique: ' + anchor) return 1
return 1 if text.count(ANCHOR_MENU) != 1:
text = text.replace(anchor, FUNC + '\n' + anchor, 1) print('anchor not found or not unique: ' + ANCHOR_MENU)
return 1
anchor = '#special VTOY_DEFAULT_IMAGE process' patched = text.replace(ANCHOR_FUNC, FUNC + '\n' + ANCHOR_FUNC, 1)
if text.count(anchor) != 1: patched = patched.replace(ANCHOR_MENU, MENU + '\n' + ANCHOR_MENU, 1)
print('anchor not found or not unique: ' + anchor)
return 1
text = text.replace(anchor, MENU + '\n' + anchor, 1)
io.open(path, 'w', encoding='utf-8', newline='').write(text)
print('patched: ' + path)
grbp = os.path.join(os.path.dirname(path), 'grbp.cfg') grbp = os.path.join(os.path.dirname(path), 'grbp.cfg')
io.open(grbp, 'w', encoding='utf-8', newline='').write(text) io.open(grbp, 'w', encoding='utf-8', newline='').write(patched)
print('written: ' + grbp) print('written: ' + grbp)
return 0 return 0
if __name__ == '__main__': if __name__ == '__main__':
sys.exit(main()) sys.exit(main())