Merge pull request 'refs #2198 #2199 #2200 fix bugs' (#56) from bugs-varios into main
ogclient/pipeline/head This commit looks good Details
ogclient/pipeline/tag This commit looks good Details

Reviewed-on: #56
pull/57/head 0.15.1
Natalia Serrano 2025-06-11 10:20:40 +02:00
commit d2ef8a98f2
6 changed files with 13 additions and 171 deletions

View File

@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.15.1] - 2025-06-11
### Fixed
- Add a missing "import"
- Fix retrieving windows version from the registry
- Fix bug while building the "Part-01-01" string
## [0.15.0] - 2025-06-10
### Changed

View File

@ -441,7 +441,7 @@ def ogWindowsBootParameters (disk, par):
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_PARTITION, f'ESP: {bootdisk} {bootpar}')
return
bootdisk = str (int (bootdisk) - 1)
bootlabel = f'Part-{int(bootdisk):02d}-{int(bootpar):02d}'
bootlabel = f'Part-{int(disk):02d}-{int(par):02d}'
bcdfile = f'boot_BCD_file=/EFI/{bootlabel}/Boot/BCD'
else:
bootdisk = disk0
@ -453,9 +453,9 @@ def ogWindowsBootParameters (disk, par):
winver = InventoryLib.ogGetOsVersion (disk, par)
parts = re.split (':| ', winver)
if 'Windows' == parts[0] and 'Server' == parts[2]:
winver = parts[1] + parts[2] + parts[3]
winver = parts[1] + ' ' + parts[2] + ' ' + parts[3]
else:
winver = parts[1] + parts[2]
winver = parts[1] + ' ' + parts[2]
if not winver:
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTOS, 'Windows')
return

View File

@ -428,7 +428,7 @@ def ogGetOsVersion(disk, part):
f'load {file}',
r'cd \Microsoft\Windows NT\CurrentVersion',
'lsval ProductName',
'lsval DisplayVersion',
'lsval ReleaseId',
])
version = subprocess.run (['hivexsh'], input=i, capture_output=True, text=True).stdout
version = version.replace ('\n', ' ')

View File

@ -1,62 +0,0 @@
import sys
import os
import subprocess
import SystemLib
import FileSystemLib
import DiskLib
import Boot
#!/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:
SystemLib.ogRaiseError(1, f"Formato: {prog} ndisco nfilesys [str_kernel str_initrd str_kernelparams]")
disk = sys.argv[1]
filesystem = sys.argv[2]
try:
part = DiskLib.ogDiskToDev(disk, filesystem)
except Exception as e:
sys.exit(1)
try:
mntdir = FileSystemLib.ogMount(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:
SystemLib.ogEcho("log", "session", "MSG_WARNING: MSG_MOUNTREADONLY")
FileSystemLib.ogUnmount(disk, filesystem)
FileSystemLib.ogCheckFs(disk, filesystem)
part = DiskLib.ogDiskToDev(disk, filesystem)
os.makedirs(mntdir, exist_ok=True)
subprocess.run(["ntfs-3g", "-o", "remove_hiberfile", part, mntdir])
SystemLib.ogEcho("log", "session", "Particion desbloqueada")
FileSystemLib.ogUnmount(disk, filesystem)
FileSystemLib.ogMount(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(DiskLib.ogDiskToDev(disk, filesystem).split())):
FileSystemLib.ogUnmountAll(i)
print("[80] Desmontar cache local.")
FileSystemLib.ogUnmount_cache()
print("[90] Arrancar sistema operativo.")
BootLib.ogBoot(sys.argv[1:])
if __name__ == "__main__":
main()

View File

@ -1,105 +0,0 @@
import sys
import os
import SystemLib
import DiskLib
import FileSystemLib
import NetLib
import FileLib
#!/usr/bin/env python3
"""
bootOsCustom
@brief Plantilla para script de configuración personalizada de sistema operativo restaurado.
@param $1 de disco
@param $2 de partición
@warning Renombrar este fichero como "bootOsCustom" para personalizar el script estándar "bootOs".
@note La partición a inicializar debe estar montada
@version 1.1.1 Soporta varios discos
"""
# CONFIGURAR: Partición de datos de Windows que no queremos ocultar (valor por defecto '0' no oculta nada)
DISKDATA = 0
PARTDATA = 0
PROG = os.path.basename(__file__)
# Control de errores
if len(sys.argv) < 3:
SystemLib.ogRaiseError(OG_ERR_FORMAT, f"Formato: {PROG} ndisco nparticion")
sys.exit(1)
# Parámetros obligatorios.
DISK = sys.argv[1] # Nº de disco.
PART = sys.argv[2] # Nº de partición.
# Paso 0: Añadir código para realizar control de errores de los parámetros de entrada (recomendado).
DEVICE = DiskLib.ogDiskToDev(DISK, PART)
if not DEVICE:
sys.exit(1)
# Paso 1: Adaptar el código de ejemplo para arranque personalizado.
# Nota: el script "bootOs" llama al script "bootOsCustom" después de realizar la operaciones de inicio estándar y antes de desmontar las particiones e iniciar el sistema operativo.
MNTDIR = FileSystemLib.ogMount(DISK, PART)
if not MNTDIR:
sys.exit(1)
NAME = NetLib.ogGetHostname()
NAME = NAME if NAME else "pc"
OSTYPE = Inventory.ogGetOsType(DISK, PART)
if OSTYPE == "Windows":
# Mostrar las particiones NTFS de sistema (dos opciones)
# Opción 1: SIN ocultar las demás.
# SystemLib.ogEcho log session "[40] Mostrar y activar particion de Windows {PART}."
# if DiskLib.ogGetPartitionType(DISK, PART) in ["HNTFS", "WIN-RESERV"]:
# DiskLib.ogUnhidePartition(DISK, PART)
# Recorremos los distintos discos
# for DEVICE in DiskLib.ogDiskToDev():
# d = DiskLib.ogDevToDisk(DEVICE)
# # Mostrar las particiones NTFS de sistema (dos opciones)
# # Opción 2: Ocultamos las demás.
# SystemLib.ogEcho log session "[40] Activar particion de Windows {PART} y ocultar las demás."
# for i in range(1, DiskLib.ogGetPartitionsNumber(d) + 1):
# if (d == DISK and i == PART) or (d == DISKDATA and i == PARTDATA):
# if DiskLib.ogGetPartitionType(d, i) in ["HNTFS", "WIN-RESERV"]:
# DiskLib.ogUnhidePartition(d, i)
# else:
# if DiskLib.ogGetPartitionType(d, i) in ["NTFS", "WINDOWS"]:
# DiskLib.ogHidePartition(d, i)
# # Borrar marcas de arrranque de todos los Windows instalados en el disco.
# SystemLib.ogEcho log session "[30] Borrar marcas de arrranque de todos los Windows instalados en el disco."
# for i in range(1, DiskLib.ogGetPartitionsNumber(d) + 1):
# if Inventory.ogGetOsType(d, i) == "Windows":
# FileSystemLib.ogMount(d, i)
# os.system("rm -f /mnt/*/ogboot.*")
elif OSTYPE == "Linux":
# Modificar el nombre del equipo
# SystemLib.ogEcho log session "[30] Asignar nombre Linux \"{NAME}\"."
# ETC = FileLib.ogGetPath(DISK, PART, "/etc")
# if os.path.isdir(ETC):
# with open(os.path.join(ETC, "hostname"), "w") as f:
# f.write(NAME)
# Sustituir UUID o LABEL por su dispositivo en definición de sistema de archivo raíz.
# if os.path.isfile(os.path.join(ETC, "fstab")):
# SystemLib.ogEcho log session "[40] Actualizar fstab con particion raíz \"{PART}\"."
# with open(os.path.join(ETC, "fstab"), "r") as f:
# lines = f.readlines()
# with open("/tmp/fstab", "w") as f:
# for line in lines:
# if line.split()[1] == "/" and not line.startswith("#"):
# line = line.replace(line.split()[0], PART)
# f.write(line)
# os.replace("/tmp/fstab", os.path.join(ETC, "fstab"))
# Cambiar claves usuarios, copiando fichero /etc/passwd
# En el servidor el nuevo fichero debe situarse en el directorio del grupo:
# /opt/opengnsys/images/groups/nombre_aula
# if os.path.isfile(os.path.join(ogGetGroupDir(), "passwd")):
# SystemLib.ogEcho log session "[65] Cambiar claves de usuarios."
# os.system(f"cp {os.path.join(ogGetGroupDir(), 'passwd')} {os.path.join(MNTDIR, 'etc')}")

View File

@ -4,6 +4,7 @@
import sys
import re
import os
import subprocess
import shutil