121 lines
4.4 KiB
Python
121 lines
4.4 KiB
Python
import os
|
|
import subprocess
|
|
import sys
|
|
|
|
def run_command(command):
|
|
result = subprocess.run(command, shell=True, capture_output=True, text=True)
|
|
if result.returncode != 0:
|
|
print(f"Error: {result.stderr}")
|
|
sys.exit(result.returncode)
|
|
return result.stdout.strip()
|
|
|
|
def main():
|
|
# Load engine configurator from engine.cfg file.
|
|
og_engine_configurate = os.getenv('OGENGINECONFIGURATE')
|
|
if not og_engine_configurate:
|
|
run_command('source /opt/opengnsys/etc/engine.cfg')
|
|
|
|
# Clear temporary file used as log track by httpdlog
|
|
for log_file in [os.getenv('OGLOGSESSION'), os.getenv('OGLOGCOMMAND'), f"{os.getenv('OGLOGCOMMAND')}.tmp"]:
|
|
with open(log_file, 'w') as f:
|
|
f.write(" ")
|
|
|
|
# Registro de inicio de ejecución
|
|
run_command(f'ogEcho log session "$MSG_INTERFACE_START {sys.argv[0]} {" ".join(sys.argv[1:])}"')
|
|
|
|
# Captura de parámetros (se ignora el 1er parámetro y se eliminan espacios y tabuladores).
|
|
param = "".join(sys.argv[2:]).replace(" ", "").replace("\t", "")
|
|
|
|
# Activa navegador para ver progreso
|
|
coproc = subprocess.Popen(['/opt/opengnsys/bin/browser', '-qws', 'http://localhost/cgi-bin/httpd-log.sh'])
|
|
|
|
# Leer los dos bloques de parámetros, separados por '!'.
|
|
pparam, sparam = param.split('!')
|
|
|
|
# Toma valores de disco y caché, separados por "*".
|
|
disk_params = dict(item.split('=') for item in pparam.split('*'))
|
|
dis = disk_params.get('dis')
|
|
che = disk_params.get('che')
|
|
tch = disk_params.get('tch')
|
|
|
|
# Error si no se define el parámetro de disco (dis).
|
|
if not dis:
|
|
sys.exit(os.getenv('OG_ERR_FORMAT'))
|
|
|
|
# Toma valores de distribución de particiones, separados por "%".
|
|
partition_params = sparam.split('%')
|
|
|
|
maxp = 0
|
|
TBP = {}
|
|
TBF = {}
|
|
|
|
for param in partition_params:
|
|
cfg = dict(item.split('=') for item in param.split('*'))
|
|
par = int(cfg.get('par', 0))
|
|
cpt = cfg.get('cpt')
|
|
sfi = cfg.get('sfi')
|
|
tam = cfg.get('tam')
|
|
ope = cfg.get('ope')
|
|
|
|
if cpt != "CACHE":
|
|
TBP[par] = f"{cpt}:{tam}"
|
|
|
|
if ope == "1":
|
|
if run_command(f'ogCheckStringInGroup {cpt} "EMPTY EXTENDED LINUX-LVM LVM ZPOOL"') != "0":
|
|
TBF[par] = sfi
|
|
|
|
if par > maxp:
|
|
maxp = par
|
|
|
|
# Tamaño actual de la cache
|
|
CACHESIZE = run_command('ogGetCacheSize')
|
|
|
|
# Desmonta todas las particiones y la caché
|
|
run_command(f'ogEcho session log "[10] $MSG_HELP_ogUnmountAll"')
|
|
run_command(f'ogUnmountAll {dis}')
|
|
run_command('ogUnmountCache')
|
|
|
|
# Elimina la tabla de particiones
|
|
if run_command('ogGetPartitionTableType 1') != 'MSDOS':
|
|
run_command(f'ogDeletePartitionTable {dis}')
|
|
run_command(f'ogExecAndLog COMMAND ogUpdatePartitionTable {dis}')
|
|
run_command(f'ogCreatePartitionTable {dis} MSDOS')
|
|
|
|
# Inicia la cache.
|
|
if "CACHE" in sparam:
|
|
run_command(f'ogEcho session log "[30] $MSG_HELP_ogCreateCache"')
|
|
run_command(f'ogEcho session log " initCache {tch}"')
|
|
run_command(f'ogExecAndLog COMMAND initCache {tch}')
|
|
|
|
# Definir particionado.
|
|
run_command(f'ogEcho session log "[50] $MSG_HELP_ogCreatePartitions"')
|
|
run_command(f'ogEcho session log " ogCreatePartitions {dis} {" ".join(TBP.values())}"')
|
|
if run_command(f'ogExecAndLog COMMAND ogCreatePartitions {dis} {" ".join(TBP.values())}') != "0":
|
|
coproc.kill()
|
|
sys.exit(run_command(f'ogRaiseError session log $OG_ERR_GENERIC "ogCreatePartitions {dis} {" ".join(TBP.values())}"'))
|
|
|
|
run_command(f'ogExecAndLog COMMAND ogUpdatePartitionTable {dis}')
|
|
|
|
# Formatear particiones
|
|
run_command(f'ogEcho session log "[70] $MSG_HELP_ogFormat"')
|
|
|
|
for par in range(1, maxp + 1):
|
|
if TBF.get(par) == "CACHE":
|
|
if CACHESIZE == tch:
|
|
run_command(f'ogEcho session log " ogFormatCache"')
|
|
run_command(f'ogExecAndLog COMMAND ogFormatCache')
|
|
elif TBF.get(par):
|
|
run_command(f'ogEcho session log " ogFormatFs {dis} {par} {TBF[par]}"')
|
|
if run_command(f'ogExecAndLog COMMAND ogFormatFs {dis} {par} {TBF[par]}') != "0":
|
|
coproc.kill()
|
|
sys.exit(run_command(f'ogRaiseError session log $OG_ERR_GENERIC "ogFormatFs {dis} {par} {TBF[par]}"'))
|
|
|
|
# Registro de fin de ejecución
|
|
run_command(f'ogEcho log session "$MSG_INTERFACE_END {0}"')
|
|
|
|
# Retorno
|
|
coproc.kill()
|
|
sys.exit(0)
|
|
|
|
if __name__ == "__main__":
|
|
main() |