Esempio n. 1
0
def upgrade_keyring(system: int, args: Namespace) -> CompletedProcess:
    """Upgrades the archlinux-keyring on that system."""

    command = [
        PACMAN, '-Sy', 'archlinux-keyring', '--needed', '--noconfirm',
        '--disable-download-timeout'
    ]
    command = sudo(*command)
    command = ssh(system, *command, no_stdin=args.no_stdin)
    syslogger(system).debug('Executing command: %s', command)
    return execute(command, timeout=args.timeout)
Esempio n. 2
0
def runcmd(system: int, args: Namespace) -> dict:
    """Runs commands on a remote system."""

    command = ssh(system, args.execute, no_stdin=args.no_stdin)
    syslogger(system).debug('Running "%s" on system.', args.execute)
    completed_process = execute(command)

    if completed_process.returncode == 255:
        raise SSHConnectionError(completed_process)

    syslogger(system).debug('Returncode: %i', completed_process.returncode)

    if stdout := completed_process.stdout:
        syslogger(system).info(stdout.strip())
Esempio n. 3
0
def reboot(system: int, args: Namespace) -> dict:
    """Reboots a system."""

    command = ssh(system, *sudo(SYSTEMCTL, 'reboot'), no_stdin=args.no_stdin)
    syslogger(system).debug('Rebooting system %i.', system)
    completed_process = execute(command)

    if completed_process.returncode == 0:
        syslogger(system).info('System %i is rebooting.', system)
    elif completed_process.returncode == 1:
        syslogger(system).warning('System %i may be rebooting.', system)
    elif completed_process.returncode == 255:
        raise SSHConnectionError(completed_process)

    return completed_process_to_json(completed_process)
Esempio n. 4
0
def cleanup_system(system: int, args: Namespace) -> CompletedProcess:
    """Cleans up the system."""

    command = [PACMAN, '-Rncs', '$(pacman -Qmq; pacman -Qdtq)']

    if not args.yes:
        command.append('--noconfirm')

    command = ' '.join(sudo(*command))

    if args.yes:
        command = f'yes | {command}'

    command = ssh(system, command, no_stdin=args.no_stdin)
    syslogger(system).debug('Executing command: %s', command)
    return execute(command, timeout=args.timeout)
Esempio n. 5
0
def upgrade_system(system: int, args: Namespace) -> CompletedProcess:
    """Upgrades the system."""

    command = [PACMAN, '-Syu', '--needed', '--disable-download-timeout']

    for package in args.install:
        command.append(package)

    for glob in args.overwrite:
        command.append('--overwrite')
        command.append(glob)

    if not args.yes:
        command.append('--noconfirm')

    command = ' '.join(sudo(*command))

    if args.yes:
        command = f'yes | {command}'

    command = ssh(system, command, no_stdin=args.no_stdin)
    syslogger(system).debug('Executing command: %s', command)
    return execute(command, timeout=args.timeout)