VTOYEFI: keep grub.cfg without paravis_return; patch only grbp.cfg
This commit is contained in:
1 parent
ada702754c
commit
e0ac4aac3d
1 file changed
+32
-31
@@ -1,30 +1,33 @@
|
||||
#!/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:
|
||||
|
||||
* UEFI -> /efi/Paravis/Boot/grub2/grubx64.efi
|
||||
* BIOS -> MBR of the Ventoy disk: chainloader (${vtoydev})+1
|
||||
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
|
||||
grubx64_parv.efi when Ventoy is chainloaded from the Paravis menu - gets it.
|
||||
|
||||
Usage:
|
||||
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
|
||||
same directory. grbp.cfg is loaded by the UEFI build (grubx64_parv.efi) that
|
||||
the Paravis menu chainloads; the legacy core.img loads grub.cfg.
|
||||
The script never modifies grub.cfg. If grub.cfg is already patched, it
|
||||
refuses to run, so a regression cannot be silently re-introduced.
|
||||
"""
|
||||
|
||||
import io
|
||||
import os
|
||||
import sys
|
||||
|
||||
FUNC = '''function paravis_return {
|
||||
FUNC = r'''function paravis_return {
|
||||
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
|
||||
chainloader /efi/Paravis/Boot/grub2/grubx64.efi
|
||||
chainloader ($pvroot)/efi/BOOT/bootx64.efi
|
||||
else
|
||||
chainloader /EFI/Boot/bootia32.efi
|
||||
chainloader ($pvroot)/efi/BOOT/bootia32.efi
|
||||
fi
|
||||
else
|
||||
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
|
||||
}
|
||||
|
||||
set default="paravis_return"
|
||||
'''
|
||||
|
||||
ANCHOR_FUNC = 'function ventoy_ext_menu {'
|
||||
ANCHOR_MENU = '#special VTOY_DEFAULT_IMAGE process'
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 2:
|
||||
@@ -49,29 +55,24 @@ def main():
|
||||
path = sys.argv[1]
|
||||
text = io.open(path, encoding='utf-8', newline='').read()
|
||||
|
||||
if 'function paravis_return' in text:
|
||||
print('already patched: ' + path)
|
||||
else:
|
||||
anchor = 'function ventoy_ext_menu {'
|
||||
if text.count(anchor) != 1:
|
||||
print('anchor not found or not unique: ' + anchor)
|
||||
return 1
|
||||
text = text.replace(anchor, FUNC + '\n' + anchor, 1)
|
||||
if 'function paravis_return' in text or '--id="paravis_return"' in text:
|
||||
print('grub.cfg already contains paravis_return, expected a clean source: ' + path)
|
||||
return 1
|
||||
if text.count(ANCHOR_FUNC) != 1:
|
||||
print('anchor not found or not unique: ' + ANCHOR_FUNC)
|
||||
return 1
|
||||
if text.count(ANCHOR_MENU) != 1:
|
||||
print('anchor not found or not unique: ' + ANCHOR_MENU)
|
||||
return 1
|
||||
|
||||
anchor = '#special VTOY_DEFAULT_IMAGE process'
|
||||
if text.count(anchor) != 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)
|
||||
patched = text.replace(ANCHOR_FUNC, FUNC + '\n' + ANCHOR_FUNC, 1)
|
||||
patched = patched.replace(ANCHOR_MENU, MENU + '\n' + ANCHOR_MENU, 1)
|
||||
|
||||
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)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
sys.exit(main())
|
||||
Reference in new issue
Block a user