import os import sys import subprocess #!/usr/bin/env python3 def main(mode): PROG = os.path.basename(__file__) CALLER = og_get_caller() if not og_check_string_in_group(CALLER, ["CrearImagen", "ConsolaRemota", "CrearImagenBasica", "CrearSoftIncremental"]): og_raise_error("OG_ERR_NOTEXEC", f"{CALLER} -> {PROG}") sys.exit(1) REPOIP = og_get_repo_ip() if not REPOIP: og_raise_error("OG_ERR_NOTFOUND", "repo no montado") sys.exit(1) if og_is_repo_locked(): og_raise_error("OG_ERR_LOCKED", f"repo {REPOIP}") sys.exit(1) PROTO = os.getenv("ogprotocol", "smb") if PROTO not in ["nfs", "smb"]: og_raise_error("OG_ERR_FORMAT", f"protocolo desconocido {PROTO}") sys.exit(1) if mode == "admin": MODE = "rw" elif mode == "user": MODE = "ro" else: og_raise_error("OG_ERR_FORMAT", f"modo desconocido {mode}") sys.exit(1) OGIMG = "/path/to/ogimg" # Placeholder for actual OGIMG path subprocess.run(["umount", OGIMG], check=True) ogunit = os.getenv("ogunit", "") OGUNIT = f"/{ogunit}" if ogunit else "" og_echo("info", f"{PROG}: Montar repositorio {REPOIP} por {PROTO} en modo {mode}") if PROTO == "nfs": subprocess.run(["mount", "-t", "nfs", f"{REPOIP}:{OGIMG}{OGUNIT}", OGIMG, "-o", MODE], check=True) elif PROTO == "smb": with open("/scripts/ogfunctions") as f: for line in f: if "OPTIONS=" in line: PASS = line.split("pass=")[1].split()[0] break else: PASS = "og" subprocess.run(["mount.cifs", f"//{REPOIP}/ogimages{OGUNIT}", OGIMG, "-o", f"{MODE},serverino,acl,username=opengnsys,password={PASS}"], check=True) if __name__ == "__main__": if len(sys.argv) != 2: print("Usage: CambiarAcceso.py ", file=sys.stderr) sys.exit(1) main(sys.argv[1])