ogclone-engine/client/shared/scripts/bootOS.py

58 lines
1.9 KiB
Python

import sys
import os
import subprocess
#!/usr/bin/env python3
# Script de ejemplo para arrancar un sistema operativo instalado.
# Nota: se usa como base para el programa de arranque de OpenGnsys Admin.
def main():
prog = os.path.basename(__file__)
if len(sys.argv) < 3 or len(sys.argv) > 6:
og_raise_error(1, f"Formato: {prog} ndisco nfilesys [str_kernel str_initrd str_kernelparams]")
disk = sys.argv[1]
filesystem = sys.argv[2]
try:
part = og_disk_to_dev(disk, filesystem)
except Exception as e:
sys.exit(1)
try:
mntdir = og_mount(disk, filesystem)
except Exception as e:
sys.exit(1)
print("[0] Inicio del proceso de arranque.")
mount_output = subprocess.getoutput(f"mount | grep -q '{mntdir}.*(rw'")
if mount_output:
og_echo("log", "session", "MSG_WARNING: MSG_MOUNTREADONLY")
og_unmount(disk, filesystem)
og_check_fs(disk, filesystem)
part = og_disk_to_dev(disk, filesystem)
os.makedirs(mntdir, exist_ok=True)
subprocess.run(["ntfs-3g", "-o", "remove_hiberfile", part, mntdir])
og_echo("log", "session", "Particion desbloqueada")
og_unmount(disk, filesystem)
og_mount(disk, filesystem)
if subprocess.call("which bootOsCustom", shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) == 0:
print("[10] Configuración personalizada del inicio.")
subprocess.run(["bootOsCustom"] + sys.argv[1:])
print("[70] Desmontar todos los sistemas de archivos.")
subprocess.run(["sync"])
for i in range(1, len(og_disk_to_dev(disk, filesystem).split())):
og_unmount_all(i)
print("[80] Desmontar cache local.")
og_unmount_cache()
print("[90] Arrancar sistema operativo.")
og_boot(sys.argv[1:])
if __name__ == "__main__":
main()