update infra script

This commit is contained in:
manuel 2024-07-15 12:22:49 +00:00
parent 92e0bdeec8
commit dc57dcd238
1 changed files with 49 additions and 56 deletions

View File

@ -620,69 +620,71 @@ def shared_server_files():
) )
logger.info(MSG_FIN + HOME_FOLDER + WPCHROOT + des) logger.info(MSG_FIN + HOME_FOLDER + WPCHROOT + des)
def server_config_files(sbase): # Configuration constants for directory paths
""" BASE_CONFIG = {
This function copies specific files used for server builds "debian": {
and configures them based on the provided base (sbase). "scripts_dir": "/server/scripts/debian/",
""" },
base_config = { "devuan": {
"debian": { "scripts_dir": "/server/scripts/devuan/",
"scripts_dir": "/server/scripts/debian/",
},
"devuan": {
"scripts_dir": "/server/scripts/devuan/",
}
} }
}
if sbase not in base_config:
def server_config_files(sbase):
"""
This function copies specific server build files adapted for the provided base (sbase).
"""
logger = logging.getLogger(__name__)
if sbase not in BASE_CONFIG:
logger.error(f"Unsupported base: {sbase}") logger.error(f"Unsupported base: {sbase}")
return return
logger.info(f"Copy Shared Files for {sbase.capitalize()}") logger.info(f"Copy Shared Files for {sbase.capitalize()}")
src_paths = [ src_paths = [
os.path.join(base_config[sbase]["scripts_dir"], 'welcome.sh'), os.path.join(BASE_CONFIG[sbase]["scripts_dir"], 'welcome.sh'),
os.path.join(base_config[sbase]["scripts_dir"], 'configure_apache2.sh'), os.path.join(BASE_CONFIG[sbase]["scripts_dir"], 'configure_apache2.sh'),
os.path.join(base_config[sbase]["scripts_dir"], 'configure_firewalld.sh'), os.path.join(BASE_CONFIG[sbase]["scripts_dir"], 'configure_firewalld.sh'),
os.path.join(base_config[sbase]["scripts_dir"], 'configure_hostname.sh'), os.path.join(BASE_CONFIG[sbase]["scripts_dir"], 'configure_hostname.sh'),
os.path.join(base_config[sbase]["scripts_dir"], 'configure_mariadb.sh'), os.path.join(BASE_CONFIG[sbase]["scripts_dir"], 'configure_mariadb.sh'),
os.path.join(base_config[sbase]["scripts_dir"], 'configure_nginx.sh'), os.path.join(BASE_CONFIG[sbase]["scripts_dir"], 'configure_nginx.sh'),
os.path.join(base_config[sbase]["scripts_dir"], 'configure_php_and_docker.sh'), os.path.join(BASE_CONFIG[sbase]["scripts_dir"], 'configure_php_and_docker.sh'),
os.path.join(base_config[sbase]["scripts_dir"], 'configure_postfix.sh'), os.path.join(BASE_CONFIG[sbase]["scripts_dir"], 'configure_postfix.sh'),
os.path.join(base_config[sbase]["scripts_dir"], 'configure_postgresql.sh'), os.path.join(BASE_CONFIG[sbase]["scripts_dir"], 'configure_postgresql.sh'),
os.path.join(base_config[sbase]["scripts_dir"], 'configure_sqlite.sh'), os.path.join(BASE_CONFIG[sbase]["scripts_dir"], 'configure_sqlite.sh'),
os.path.join(base_config[sbase]["scripts_dir"], 'configure_ssh.sh'), os.path.join(BASE_CONFIG[sbase]["scripts_dir"], 'configure_ssh.sh'),
os.path.join(base_config[sbase]["scripts_dir"], 'configure_static_ip.sh'), os.path.join(BASE_CONFIG[sbase]["scripts_dir"], 'configure_static_ip.sh'),
os.path.join(base_config[sbase]["scripts_dir"], 'create_user.sh'), os.path.join(BASE_CONFIG[sbase]["scripts_dir"], 'create_user.sh'),
os.path.join(base_config[sbase]["scripts_dir"], 'update_and_install.sh'), os.path.join(BASE_CONFIG[sbase]["scripts_dir"], 'update_and_install.sh'),
] ]
des_paths = [ des_paths = [
'/usr/local/bin/welcome.sh', '/usr/local/bin',
'/usr/local/bin/configure_apache2.sh', '/usr/local/bin',
'/usr/local/bin/configure_firewalld.sh', '/usr/local/bin',
'/usr/local/bin/configure_hostname.sh', '/usr/local/bin',
'/usr/local/bin/configure_mariadb.sh', '/usr/local/bin',
'/usr/local/bin/configure_nginx.sh', '/usr/local/bin',
'/usr/local/bin/configure_php_and_docker.sh', '/usr/local/bin',
'/usr/local/bin/configure_postfix.sh', '/usr/local/bin',
'/usr/local/bin/configure_postgresql.sh', '/usr/local/bin',
'/usr/local/bin/configure_sqlite.sh', '/usr/local/bin',
'/usr/local/bin/configure_ssh.sh', '/usr/local/bin',
'/usr/local/bin/configure_static_ip.sh', '/usr/local/bin',
'/usr/local/bin/create_user.sh', '/usr/local/bin',
'/usr/local/bin/update_and_install.sh', '/usr/local/bin',
] ]
src_q = collections.deque(src_paths) src_q = collections.deque(src_paths)
des_q = collections.deque(des_paths) des_q = collections.deque(des_paths)
while src_q and des_q: while src_q and des_q:
src = src_q.popleft() src = src_q.popleft()
des = des_q.popleft() des = des_q.popleft()
src_path = os.path.join(HOME_FOLDER, src) src_path = os.path.join(os.environ['HOME'], src)
des_path = os.path.join(HOME_FOLDER, des) des_path = os.path.join(os.environ['HOME'], WPCHROOT, des)
logger.info(f"Copying {src_path} to {des_path}") logger.info(f"Copying {src_path} to {des_path}")
try: try:
shutil.copy2(src_path, des_path) shutil.copy2(src_path, des_path)
@ -691,15 +693,6 @@ def server_config_files(sbase):
else: else:
logger.info(f"Successfully copied {src_path} to {des_path}") logger.info(f"Successfully copied {src_path} to {des_path}")
logger.info(f"Configuring server for {sbase.capitalize()}")
if sbase == "debian":
# Add Debian specific configuration logic here
pass
elif sbase == "devuan":
# Add Devuan specific configuration logic here
pass
def boostrap_shared(): def boostrap_shared():
""" """
Copy specific folders in the boostrap location Copy specific folders in the boostrap location