Add Paravis return entry for legacy Ventoy
This commit is contained in:
1 parent
def566d9ba
commit
3ce96d1366
2 files changed
+88
No files matched your search
@@ -0,0 +1,77 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Add the "return to Paravis main menu" item to Ventoy's grub.cfg.
|
||||
|
||||
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
|
||||
|
||||
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.
|
||||
"""
|
||||
|
||||
import io
|
||||
import os
|
||||
import sys
|
||||
|
||||
FUNC = '''function paravis_return {
|
||||
if [ "$grub_platform" = "efi" ]; then
|
||||
search --no-floppy --file --set=root /efi/Paravis/Boot/grub2/grub.cfg
|
||||
if [ "$grub_cpu" = "x86_64" ]; then
|
||||
chainloader /efi/Paravis/Boot/grub2/grubx64.efi
|
||||
else
|
||||
chainloader /EFI/Boot/bootia32.efi
|
||||
fi
|
||||
else
|
||||
chainloader (${vtoydev})+1
|
||||
fi
|
||||
boot
|
||||
}
|
||||
'''
|
||||
|
||||
MENU = '''menuentry "Возврат в главное меню Paravis Flash" --id="paravis_return" --class="vtoyret" {
|
||||
paravis_return
|
||||
}
|
||||
|
||||
set default="paravis_return"
|
||||
'''
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 2:
|
||||
print(__doc__)
|
||||
return 1
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
grbp = os.path.join(os.path.dirname(path), 'grbp.cfg')
|
||||
io.open(grbp, 'w', encoding='utf-8', newline='').write(text)
|
||||
print('written: ' + grbp)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
Reference in new issue
Block a user