refs #441 functionality to install ogboot project was divided
parent
1590b20e1a
commit
5ff3017fc9
|
@ -9,19 +9,33 @@ import platform, os, sys, subprocess, datetime, shutil, pwd, glob, zipfile, urll
|
||||||
|
|
||||||
global PACKAGES, UBUNTU_OS_VERSION, PYTHON_VERSION, INSTALL_OGBOOT_TARGET, PROGRAM_DIR, OPENGNSYS_SERVER
|
global PACKAGES, UBUNTU_OS_VERSION, PYTHON_VERSION, INSTALL_OGBOOT_TARGET, PROGRAM_DIR, OPENGNSYS_SERVER
|
||||||
|
|
||||||
|
# Leer variables de entorno
|
||||||
|
env_ogCore_ServerIP = os.environ.get('OGCORE_SERVER_IP') #"172.17.8.82"
|
||||||
|
env_ogCore_Server = os.environ.get('OGCORE_SERVER') #"opengnsys.es"
|
||||||
|
env_ogCore_Dir = os.environ.get('OGCORE_DIR') #{INSTALL_OPENGNSYS_TARGET}
|
||||||
|
env_ogBoot_Dir = os.environ.get('OGBOOT_DIR') #{INSTALL_OGBOOT_TARGET}
|
||||||
|
env_ogBoot_GitRepo = os.environ.get('OGBOOT_GIT_REPO') #"ssh://git@ognproject.evlt.uma.es:21987/opengnsys/ogboot.git"
|
||||||
|
|
||||||
PROGRAM = os.path.splitext(os.path.basename(sys.argv[0]))[0]
|
PROGRAM = os.path.splitext(os.path.basename(sys.argv[0]))[0]
|
||||||
SERVER_OPENGNSYS = "172.17.8.82"
|
|
||||||
UBUNTU_OS_VERSION = "18"
|
|
||||||
PYTHON_VERSION = 3
|
|
||||||
INSTALL_TARGET="/opt/ogboot"
|
|
||||||
INSTALL_OPENGNSYS_TARGET = "/opt/opengnsys"
|
|
||||||
INSTALL_OGBOOT_TARGET = "/opt/ogboot"
|
|
||||||
WORKDIR="/tmp/ogboot_installer"
|
|
||||||
PACKAGES = []
|
|
||||||
PROGRAM_DIR = os.path.dirname(os.path.realpath(sys.argv[0]))
|
PROGRAM_DIR = os.path.dirname(os.path.realpath(sys.argv[0]))
|
||||||
PROGRAM_NAME = os.path.basename(sys.argv[0])
|
PROGRAM_NAME = os.path.basename(sys.argv[0])
|
||||||
OPENGNSYS_SERVER = "opengnsys.es"
|
|
||||||
|
SERVER_OPENGNSYS = env_ogCore_ServerIP
|
||||||
|
OPENGNSYS_SERVER = env_ogCore_Server
|
||||||
|
INSTALL_TARGET = env_ogBoot_Dir
|
||||||
|
INSTALL_OPENGNSYS_TARGET = env_ogCore_Dir
|
||||||
|
INSTALL_OGBOOT_TARGET = env_ogBoot_Dir
|
||||||
|
GIT_REPO = env_ogBoot_GitRepo
|
||||||
|
|
||||||
|
WORKDIR="/tmp/ogboot_installer"
|
||||||
|
TFTPSERV = "tftpd-hpa"
|
||||||
|
SAMBASERV = "smbd"
|
||||||
|
SAMBACFGDIR = "/etc/samba"
|
||||||
|
TFTPCFGDIR = "/var/lib/tftpboot"
|
||||||
|
INETDCFGDIR = "/etc/xinetd.d/"
|
||||||
|
|
||||||
DEFAULTDEV = ""
|
DEFAULTDEV = ""
|
||||||
|
PACKAGES = []
|
||||||
DEVICE = []
|
DEVICE = []
|
||||||
SERVERIP = []
|
SERVERIP = []
|
||||||
NETIP = []
|
NETIP = []
|
||||||
|
@ -29,15 +43,13 @@ NETMASK = []
|
||||||
NETBROAD = []
|
NETBROAD = []
|
||||||
ROUTERIP = []
|
ROUTERIP = []
|
||||||
BRANCH = sys.argv[1] if len(sys.argv) > 1 else "main"
|
BRANCH = sys.argv[1] if len(sys.argv) > 1 else "main"
|
||||||
TFTPSERV = "tftpd-hpa"
|
|
||||||
SAMBASERV = "smbd"
|
|
||||||
SAMBACFGDIR = "/etc/samba"
|
|
||||||
TFTPCFGDIR = "/var/lib/tftpboot"
|
|
||||||
INETDCFGDIR = "/etc/xinetd.d/"
|
|
||||||
INETDSERV = "xinetd"
|
INETDSERV = "xinetd"
|
||||||
OPENGNSYS_CLIENT_PASSWD="og"
|
OPENGNSYS_CLIENT_PASSWD="og"
|
||||||
OPENGNSYS_CLIENT_USER="opengnsys"
|
OPENGNSYS_CLIENT_USER="opengnsys"
|
||||||
GIT_REPO="ssh://git@ognproject.evlt.uma.es:21987/opengnsys/ogboot.git"
|
|
||||||
|
UBUNTU_OS_VERSION = "18"
|
||||||
|
PYTHON_VERSION = 3
|
||||||
|
|
||||||
if os.path.isdir(f"{PROGRAM_DIR}/../installer"):
|
if os.path.isdir(f"{PROGRAM_DIR}/../installer"):
|
||||||
REMOTE = 0
|
REMOTE = 0
|
||||||
else:
|
else:
|
||||||
|
@ -55,14 +67,6 @@ formatter = logging.Formatter('%(levelname)s\t%(message)s')
|
||||||
console_handler.setFormatter(formatter)
|
console_handler.setFormatter(formatter)
|
||||||
logger.addHandler(console_handler)
|
logger.addHandler(console_handler)
|
||||||
|
|
||||||
# Leer variables de entorno
|
|
||||||
ogCore_ServerIP = os.environ.get('OGCORE_SERVER_IP') #"172.17.8.82"
|
|
||||||
ogCore_Dir = os.environ.get('OGCORE_DIR') #{INSTALL_OPENGNSYS_TARGET}
|
|
||||||
ogBoot_Dir = os.environ.get('OGBOOT_DIR') #{INSTALL_OGBOOT_TARGET}
|
|
||||||
|
|
||||||
#DOWNLOAD_URL = f"https://{OPENGNSYS_SERVER}/trac/downloads"
|
|
||||||
#CODE_URL = f"https://codeload.github.com/opengnsys/OpenGnsys/zip/{BRANCH}"
|
|
||||||
#API_URL = "https://api.github.com/repos/opengnsys/OpenGnsys"
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
###::::::::::::::::::::::::::::::: UTILS :::::::::::::::::::::::::::::::::::###
|
###::::::::::::::::::::::::::::::: UTILS :::::::::::::::::::::::::::::::::::###
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
@ -234,13 +238,15 @@ def install_swagger_ui():
|
||||||
os.system(f"{os.path.join(INSTALL_TARGET, 'vendor', 'bin', 'openapi')} {INSTALL_TARGET}/src/OgBootBundle/Controller/ -o {destination_path}/swagger.json")
|
os.system(f"{os.path.join(INSTALL_TARGET, 'vendor', 'bin', 'openapi')} {INSTALL_TARGET}/src/OgBootBundle/Controller/ -o {destination_path}/swagger.json")
|
||||||
logger.info(f"Swagger UI installed on {destination_path}.")
|
logger.info(f"Swagger UI installed on {destination_path}.")
|
||||||
|
|
||||||
def create_ogboot_project(path_opengnsys_base):
|
def og_core_create_user(OPENGNSYS_CLIENT_USER):
|
||||||
try:
|
try:
|
||||||
pwd.getpwnam('ogboot')
|
pwd.getpwnam(OPENGNSYS_CLIENT_USER)
|
||||||
logger.warning("User 'ogboot' already exists")
|
logger.warning(f"User {OPENGNSYS_CLIENT_USER} already exists")
|
||||||
except KeyError:
|
except KeyError:
|
||||||
subprocess.run(["sudo", "useradd", "-m", "ogboot"])
|
subprocess.run(["sudo", "useradd", "-m", OPENGNSYS_CLIENT_USER])
|
||||||
#########################
|
logger.info(f"User {OPENGNSYS_CLIENT_USER} created successfully.")
|
||||||
|
|
||||||
|
def og_boot_create_dirs(path_opengnsys_base):
|
||||||
if os.path.exists(path_opengnsys_base):
|
if os.path.exists(path_opengnsys_base):
|
||||||
if not os.path.isdir(path_opengnsys_base):
|
if not os.path.isdir(path_opengnsys_base):
|
||||||
raise NotADirectoryError(f"{path_opengnsys_base} existe y no es un directorio.")
|
raise NotADirectoryError(f"{path_opengnsys_base} existe y no es un directorio.")
|
||||||
|
@ -249,7 +255,8 @@ def create_ogboot_project(path_opengnsys_base):
|
||||||
else:
|
else:
|
||||||
os.makedirs(path_opengnsys_base)
|
os.makedirs(path_opengnsys_base)
|
||||||
subprocess.run(["sudo", "chown", "-R", "ogboot:ogboot", path_opengnsys_base])
|
subprocess.run(["sudo", "chown", "-R", "ogboot:ogboot", path_opengnsys_base])
|
||||||
########################
|
|
||||||
|
def og_boot_symfony_install(path_opengnsys_base):
|
||||||
logger.info("Creating Symfony application skeleton...")
|
logger.info("Creating Symfony application skeleton...")
|
||||||
downloadComposer()
|
downloadComposer()
|
||||||
# Copiar los archivos .env y composer.json primero
|
# Copiar los archivos .env y composer.json primero
|
||||||
|
@ -257,7 +264,8 @@ def create_ogboot_project(path_opengnsys_base):
|
||||||
shutil.copy(f"{WORKDIR}/ogboot/.env", os.path.join(path_opengnsys_base, ".env"))
|
shutil.copy(f"{WORKDIR}/ogboot/.env", os.path.join(path_opengnsys_base, ".env"))
|
||||||
shutil.copy(f"{WORKDIR}/ogboot/composer.json", os.path.join(path_opengnsys_base, "composer.json"))
|
shutil.copy(f"{WORKDIR}/ogboot/composer.json", os.path.join(path_opengnsys_base, "composer.json"))
|
||||||
logger.info(f".env and composer.json files copied to {path_opengnsys_base}")
|
logger.info(f".env and composer.json files copied to {path_opengnsys_base}")
|
||||||
########################
|
|
||||||
|
def og_boot_copy_files(path_opengnsys_base):
|
||||||
bin_source = os.path.join(WORKDIR, "ogboot/bin")
|
bin_source = os.path.join(WORKDIR, "ogboot/bin")
|
||||||
bin_dest = os.path.join(path_opengnsys_base, "bin")
|
bin_dest = os.path.join(path_opengnsys_base, "bin")
|
||||||
src_source = os.path.join(WORKDIR, "ogboot/src")
|
src_source = os.path.join(WORKDIR, "ogboot/src")
|
||||||
|
@ -290,10 +298,9 @@ def create_ogboot_project(path_opengnsys_base):
|
||||||
|
|
||||||
subprocess.run(["sudo", "chmod", "-R", "755", path_opengnsys_base])
|
subprocess.run(["sudo", "chmod", "-R", "755", path_opengnsys_base])
|
||||||
subprocess.run(["sudo", "chown", "-R", "ogboot:ogboot", path_opengnsys_base])
|
subprocess.run(["sudo", "chown", "-R", "ogboot:ogboot", path_opengnsys_base])
|
||||||
########################
|
|
||||||
|
|
||||||
|
def og_boot_composer_install(path_opengnsys_base):
|
||||||
# Ejecutar Composer como el usuario 'ogboot' para instalar el proyecto Symfony
|
# Ejecutar Composer como el usuario 'ogboot' para instalar el proyecto Symfony
|
||||||
# result = subprocess.run(["sudo", "-u", "ogboot", "composer", "install", "--no-interaction", "--working-dir", path_opengnsys_base])
|
|
||||||
os.chdir(os.path.join(path_opengnsys_base, 'bin'))
|
os.chdir(os.path.join(path_opengnsys_base, 'bin'))
|
||||||
result = subprocess.run(["sudo", "-u", "ogboot", "php", os.path.join(path_opengnsys_base, "bin", "composer.phar"), "install", "--no-interaction", "--working-dir", path_opengnsys_base])
|
result = subprocess.run(["sudo", "-u", "ogboot", "php", os.path.join(path_opengnsys_base, "bin", "composer.phar"), "install", "--no-interaction", "--working-dir", path_opengnsys_base])
|
||||||
if result.returncode != 0:
|
if result.returncode != 0:
|
||||||
|
@ -736,7 +743,13 @@ if os.system("echo $?") != 0:
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
logger.info("Creating ogBoot project.")
|
logger.info("Creating ogBoot project.")
|
||||||
create_ogboot_project(INSTALL_TARGET)
|
og_core_create_user("ogboot")
|
||||||
|
|
||||||
|
og_boot_create_dirs(INSTALL_OGBOOT_TARGET)
|
||||||
|
|
||||||
|
og_boot_symfony_install(INSTALL_OGBOOT_TARGET)
|
||||||
|
|
||||||
|
og_boot_copy_files(INSTALL_OGBOOT_TARGET)
|
||||||
if os.system("echo $?") != 0:
|
if os.system("echo $?") != 0:
|
||||||
logger.error("Error while creating skeleton directory!")
|
logger.error("Error while creating skeleton directory!")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
@ -775,6 +788,5 @@ smbConfigure()
|
||||||
|
|
||||||
logger.info(f"ogBoot installation finished.")
|
logger.info(f"ogBoot installation finished.")
|
||||||
|
|
||||||
# Cerrar el logger
|
|
||||||
logging.shutdown()
|
logging.shutdown()
|
||||||
console_handler.close()
|
console_handler.close()
|
Loading…
Reference in New Issue