2021-09-30 17:19:55 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2021-10-01 18:25:42 +02:00
|
|
|
import click
|
|
|
|
from traceback import format_exc as get_trace
|
2021-10-04 20:16:59 +02:00
|
|
|
import subprocess
|
|
|
|
|
2021-10-01 18:25:42 +02:00
|
|
|
from logger import logging, setup_logging, verbose_option
|
|
|
|
from wrapper import nowrapper_option
|
|
|
|
from config import config, config_option, cmd_config
|
|
|
|
from forwarding import cmd_forwarding
|
2021-08-04 18:36:37 +02:00
|
|
|
from packages import cmd_packages
|
2021-10-01 18:25:42 +02:00
|
|
|
from telnet import cmd_telnet
|
|
|
|
from chroot import cmd_chroot
|
2021-08-04 18:36:37 +02:00
|
|
|
from cache import cmd_cache
|
2021-08-05 20:26:48 +02:00
|
|
|
from image import cmd_image
|
|
|
|
from boot import cmd_boot
|
|
|
|
from flash import cmd_flash
|
|
|
|
from ssh import cmd_ssh
|
2021-08-04 18:36:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
@click.group()
|
2022-01-26 17:53:53 +01:00
|
|
|
@click.option('--error-shell', '-E', 'error_shell', is_flag=True, default=False, help='Spawn shell after error occurs')
|
2021-09-09 20:23:23 +02:00
|
|
|
@verbose_option
|
|
|
|
@config_option
|
2021-09-12 06:10:15 +02:00
|
|
|
@nowrapper_option
|
2021-10-04 20:16:59 +02:00
|
|
|
def cli(verbose: bool = False, config_file: str = None, no_wrapper: bool = False, error_shell: bool = False):
|
2021-09-09 20:23:23 +02:00
|
|
|
setup_logging(verbose)
|
|
|
|
config.runtime['verbose'] = verbose
|
2021-09-29 23:18:12 +02:00
|
|
|
config.runtime['no_wrap'] = no_wrapper
|
2021-10-04 20:16:59 +02:00
|
|
|
config.runtime['error_shell'] = error_shell
|
2021-09-09 20:23:23 +02:00
|
|
|
config.try_load_file(config_file)
|
2021-09-12 06:10:15 +02:00
|
|
|
|
2021-08-04 18:36:37 +02:00
|
|
|
|
2021-09-09 20:23:23 +02:00
|
|
|
def main():
|
2021-09-29 02:00:59 +02:00
|
|
|
try:
|
|
|
|
return cli(prog_name='kupferbootstrap')
|
2021-10-05 17:34:43 +02:00
|
|
|
except Exception as ex:
|
|
|
|
if config.runtime['verbose']:
|
|
|
|
logging.fatal(get_trace())
|
|
|
|
else:
|
|
|
|
logging.fatal(ex)
|
2021-10-04 20:16:59 +02:00
|
|
|
if config.runtime['error_shell']:
|
2021-10-05 17:34:43 +02:00
|
|
|
logging.info('Starting error shell. Type exit to quit.')
|
2021-10-04 20:16:59 +02:00
|
|
|
subprocess.call('/bin/bash')
|
2021-09-29 02:00:59 +02:00
|
|
|
exit(1)
|
2021-08-04 18:36:37 +02:00
|
|
|
|
2021-09-29 23:18:12 +02:00
|
|
|
|
2021-09-29 22:57:26 +02:00
|
|
|
cli.add_command(cmd_config)
|
2021-08-04 18:36:37 +02:00
|
|
|
cli.add_command(cmd_cache)
|
|
|
|
cli.add_command(cmd_packages)
|
2021-08-05 20:26:48 +02:00
|
|
|
cli.add_command(cmd_image)
|
|
|
|
cli.add_command(cmd_boot)
|
|
|
|
cli.add_command(cmd_flash)
|
|
|
|
cli.add_command(cmd_ssh)
|
|
|
|
cli.add_command(cmd_forwarding)
|
2021-08-17 20:47:14 +02:00
|
|
|
cli.add_command(cmd_telnet)
|
2021-10-01 18:25:42 +02:00
|
|
|
cli.add_command(cmd_chroot)
|
2021-09-12 06:10:15 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|