update python modules for the server builds

This commit is contained in:
manuel 2024-07-17 11:21:48 +00:00
parent 617a81c439
commit 3df65a2aca
30 changed files with 82 additions and 71 deletions

View File

@ -95,7 +95,6 @@ def set_fusato_server_installer_structure():
# Define the directories to be created in includes-installer
installer_dirs = ['/preseed',
'/usr/lib/finish-install.d/',
'/usr/share/'
]
# Create the directories in includes-installer

View File

@ -24,14 +24,6 @@ WPINSTALLER = "/fusato/config/includes.installer"
BINARYPTH = "/fusato/config/includes.binary"
BOOTSTRAP = "/fusato/config/includes.bootstrap"
FUSATOCONFIG = "/fusato/config"
BASE_CONFIG = {
"debsrv": {
"scripts_dir": "/server/scripts/debian/",
},
"devsrv": {
"scripts_dir": "/server/scripts/devuan/",
}
}
# Set up the logging format
@ -314,75 +306,95 @@ def mini_shared_installer_files():
logger.info(f"Copy completed: {des_path}")
class ServerConfigFiles:
"""
Copies server initial config files CHROOT depending on the base.
"""
Class to handle copying server configuration files.
"""
def __init__(self,sbase,sarch):
logger.info("Copy server configuration files")
self.sbase = sbase
ALLOWED_BASES = {"debsrv", "devsrv"}
def __init__(self, base, sarch=None):
self.base = base
self.sarch = sarch
if self.base not in self.ALLOWED_BASES:
logger.warning(f"Base '{self.base}' is not allowed. Skipping.")
return
logger.info(f"Copy Server Files for base: {self.base}")
server_path = '/server/scripts/'
self.src_paths = (
f'{server_path}{self.base}/welcome.sh',
f'{server_path}{self.base}/configure_apache2.sh',
f'{server_path}{self.base}/configure_firewalld.sh',
f'{server_path}{self.base}/configure_hostname.sh',
f'{server_path}{self.base}/configure_mariadb.sh',
f'{server_path}{self.base}/configure_nginx.sh',
f'{server_path}{self.base}/configure_php_and_docker.sh',
f'{server_path}{self.base}/configure_postfix.sh',
f'{server_path}{self.base}/configure_postgresql.sh',
f'{server_path}{self.base}/configure_sqlite.sh',
f'{server_path}{self.base}/configure_ssh.sh',
f'{server_path}{self.base}/configure_static_ip.sh',
f'{server_path}{self.base}/create_user.sh',
f'{server_path}{self.base}/update_and_install.sh'
)
def copy_server_config_files(self):
"""
Copy server configuration files .
"""
logger.info(f"Copying server configuration files for {self.sbase.capitalize()}")
self.des_paths = (
'/usr/local/bin',
'/usr/local/bin',
'/usr/local/bin',
'/usr/local/bin',
'/usr/local/bin',
'/usr/local/bin',
'/usr/local/bin',
'/usr/local/bin',
'/usr/local/bin',
'/usr/local/bin',
'/usr/local/bin',
'/usr/local/bin',
'/usr/local/bin',
'/usr/local/bin'
)
self.copy_files()
src_paths = [
'welcome.sh',
'configure_apache2.sh',
'configure_firewalld.sh',
'configure_hostname.sh',
'configure_mariadb.sh',
'configure_nginx.sh',
'configure_php_and_docker.sh',
'configure_postfix.sh',
'configure_postgresql.sh',
'configure_sqlite.sh',
'configure_ssh.sh',
'configure_static_ip.sh',
'create_user.sh',
'update_and_install.sh',
]
des_paths = [
'/usr/local/bin',
'/usr/local/bin',
'/usr/local/bin',
'/usr/local/bin',
'/usr/local/bin',
'/usr/local/bin',
'/usr/local/bin',
'/usr/local/bin',
'/usr/local/bin',
'/usr/local/bin',
'/usr/local/bin',
'/usr/local/bin',
'/usr/local/bin',
'/usr/local/bin',
]
for src_file, des_dir in zip(src_paths, des_paths):
src_path = os.path.join(BASE_CONFIG[self.sbase]["scripts_dir"], src_file)
des_path = os.path.join(self.build_base.HOME_FOLDER, self.build_base.WPCHROOT, des_dir, src_file)
logger.info(f"Copying {src_path} to {des_path}")
def copy_files(self):
""" Ensure destination directories exist before copying"""
for des in self.des_paths:
full_des_path = os.path.join(HOME_FOLDER, WPCHROOT.strip('/'), des.strip('/'))
try:
if os.path.isdir(src_path):
shutil.copytree(src_path, des_path, ignore_dangling_symlinks=True)
else:
shutil.copy2(src_path, des_path)
os.makedirs(full_des_path, exist_ok=True)
logger.info(f"Ensured directory exists: {full_des_path}")
except Exception as e:
logger.error(f"Error copying {src_path} to {des_path}: {e}")
else:
logger.info(f"Successfully copied {src_path} to {des_path}")
# Exemplo de uso:
if __name__ == "__main__":
sbase = build_base.sbase
sarch = build_base.sarch
server_config_files = ServerConfigFiles(sbase, sarch, build_base)
logger.error(f"Error creating directory {full_des_path}: {e}")
src_q = collections.deque(self.src_paths)
des_q = collections.deque(self.des_paths)
size_q = len(src_q)
for _ in range(size_q):
source = src_q.popleft()
des = des_q.popleft()
full_src_path = os.path.join(HOME_FOLDER, source.strip('/'))
full_des_path = os.path.join(HOME_FOLDER,
WPCHROOT.strip('/'), des.strip('/')
)
logger.info(MSG_COPY + full_src_path)
try:
if os.path.exists(full_src_path):
if os.path.isdir(full_src_path):
shutil.copytree(full_src_path,
os.path.join(full_des_path,
os.path.basename(full_src_path)),
dirs_exist_ok=True
)
else:
shutil.copy(full_src_path, full_des_path)
logger.info(MSG_FIN + full_des_path)
else:
logger.error(f"Source path does not exist: {full_src_path}")
except Exception as e:
logger.error(f"Error copying {full_src_path} to {full_des_path}: {e}")
@classmethod
def run_for_all_bases(cls):
""" Define the bases to be used"""
bases = ["debsrv", "devsrv", "invalid_base"]
for base in bases:
cls(base)
class ArchitectureFiles:
"""