2022-03-08 20:47:55 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
from asyncio import run
|
2022-06-24 19:02:45 +02:00
|
|
|
from os import listdir, link, makedirs
|
|
|
|
from os.path import isdir, join
|
|
|
|
from shutil import rmtree
|
2022-03-08 20:47:55 +01:00
|
|
|
from copy import copy
|
|
|
|
|
2022-08-21 19:03:38 +02:00
|
|
|
from risotto.utils import RISOTTO_CONFIG, SERVERS
|
|
|
|
#from risotto.image import load
|
|
|
|
from risotto.machine import templates, load, ROUGAIL_NAMESPACE
|
|
|
|
from rougail.utils import normalize_family
|
2022-03-08 20:47:55 +01:00
|
|
|
|
2022-03-11 18:39:32 +01:00
|
|
|
|
2022-06-24 19:02:45 +02:00
|
|
|
INSTALL_DIR = RISOTTO_CONFIG['directories']['dest']
|
2022-03-08 20:47:55 +01:00
|
|
|
CONFIG_DEST_DIR = 'configurations'
|
2022-06-24 19:02:45 +02:00
|
|
|
CONFIG_DIFF_DIR = 'diff'
|
2022-07-01 18:57:18 +02:00
|
|
|
CONFIG_ORI_DIR = 'ori'
|
2022-03-08 20:47:55 +01:00
|
|
|
SRV_DEST_DIR = 'srv'
|
|
|
|
|
|
|
|
|
|
|
|
async def main():
|
|
|
|
if isdir(INSTALL_DIR):
|
|
|
|
rmtree(INSTALL_DIR)
|
|
|
|
makedirs(INSTALL_DIR)
|
2022-08-21 19:03:38 +02:00
|
|
|
try:
|
2022-10-01 22:33:11 +02:00
|
|
|
module_infos, rougailconfig, config = await load('a.py',
|
|
|
|
'n.py',
|
2022-08-21 19:03:38 +02:00
|
|
|
clean_directories=True,
|
|
|
|
copy_manual_dir=True,
|
|
|
|
copy_tests=True,
|
|
|
|
)
|
|
|
|
except Exception as err:
|
|
|
|
# import traceback
|
|
|
|
# traceback.print_exc()
|
|
|
|
print(err)
|
|
|
|
exit(1)
|
|
|
|
modules_done = []
|
2022-06-24 19:02:45 +02:00
|
|
|
for server_name in SERVERS:
|
2022-08-21 19:03:38 +02:00
|
|
|
module_name = SERVERS[server_name]['module']
|
|
|
|
module_info = module_infos[module_name]
|
|
|
|
subconfig = config.option(normalize_family(server_name))
|
|
|
|
try:
|
|
|
|
add_srv = await subconfig.option('machine.add_srv').value.get()
|
|
|
|
except AttributeError:
|
|
|
|
add_srv = False
|
|
|
|
rougailconfig['tmp_dir'] = 'tmp'
|
|
|
|
rougailconfig['destinations_dir'] = join(INSTALL_DIR, module_name, CONFIG_DEST_DIR, server_name)
|
|
|
|
rougailconfig['templates_dir'] = module_info['infos'].templates_dir
|
|
|
|
if module_name == 'host':
|
|
|
|
tmpfile = await subconfig.option(f'{ROUGAIL_NAMESPACE}.host_install_dir').value.get()
|
|
|
|
rougailconfig['tmpfile_dest_dir'] = f'{tmpfile}/host/configurations/{server_name}'
|
|
|
|
rougailconfig['default_systemd_directory'] = '/usr/local/lib/systemd'
|
|
|
|
else:
|
|
|
|
rougailconfig['tmpfile_dest_dir'] = '/usr/local/lib'
|
|
|
|
rougailconfig['default_systemd_directory'] = '/systemd'
|
|
|
|
# cfg['templates_dir'] = module_info['infos'].templates_dir
|
2022-06-24 19:02:45 +02:00
|
|
|
if isdir('tmp'):
|
|
|
|
rmtree('tmp')
|
2022-08-21 19:03:38 +02:00
|
|
|
makedirs(rougailconfig['tmp_dir'])
|
|
|
|
makedirs(rougailconfig['destinations_dir'])
|
2022-06-24 19:02:45 +02:00
|
|
|
if add_srv:
|
|
|
|
srv = join(INSTALL_DIR, SRV_DEST_DIR, server_name)
|
|
|
|
else:
|
|
|
|
srv = None
|
2022-08-21 19:03:38 +02:00
|
|
|
await templates(server_name,
|
|
|
|
subconfig,
|
|
|
|
rougailconfig,
|
|
|
|
srv=srv,
|
|
|
|
)
|
|
|
|
#
|
2022-06-24 19:02:45 +02:00
|
|
|
await config.property.read_write()
|
|
|
|
try:
|
2022-08-21 19:03:38 +02:00
|
|
|
await subconfig.option('general.hide_secret').value.set(True)
|
|
|
|
except AttributeError as err:
|
|
|
|
# print(err)
|
2022-06-24 19:02:45 +02:00
|
|
|
pass
|
|
|
|
await config.property.read_only()
|
2022-08-21 19:03:38 +02:00
|
|
|
rougailconfig['destinations_dir'] = join(INSTALL_DIR, module_name, CONFIG_DIFF_DIR, server_name)
|
|
|
|
rmtree('tmp')
|
|
|
|
makedirs(rougailconfig['tmp_dir'])
|
|
|
|
makedirs(rougailconfig['destinations_dir'])
|
|
|
|
await templates(server_name,
|
|
|
|
subconfig,
|
|
|
|
rougailconfig,
|
|
|
|
)
|
|
|
|
await config.property.read_write()
|
|
|
|
try:
|
|
|
|
await subconfig.option('general.hide_secret').value.set(False)
|
|
|
|
except AttributeError as err:
|
|
|
|
pass
|
|
|
|
await config.property.read_only()
|
|
|
|
#
|
|
|
|
if module_name not in modules_done:
|
|
|
|
rougailconfig['destinations_dir'] = join(INSTALL_DIR, module_name, CONFIG_ORI_DIR)
|
|
|
|
rmtree('tmp')
|
|
|
|
makedirs(rougailconfig['tmp_dir'])
|
|
|
|
makedirs(rougailconfig['destinations_dir'])
|
|
|
|
await templates(server_name,
|
|
|
|
subconfig,
|
|
|
|
rougailconfig,
|
|
|
|
just_copy=True,
|
|
|
|
)
|
|
|
|
modules_done.append(module_name)
|
2022-03-08 20:47:55 +01:00
|
|
|
with open(join(INSTALL_DIR, module_name, 'install_machines'), 'w') as fh:
|
2022-08-21 19:03:38 +02:00
|
|
|
fh.write(f'./install_machine {module_name} {server_name}\n')
|
2022-03-08 20:47:55 +01:00
|
|
|
run(main())
|