#!/usr/bin/python3
# Copyright (c) 2019-2021 TurnKey GNU/Linux <admin@turnkeylinux.org>
# all rights reserved

import sys

import chroot

from common import DiliveDebconf, target_mounted

pkgs_to_clean = ['di-live', 'live-boot', 'live-tools',
                 'live-boot-initramfs-tools']


def clean_target_pkgs(*pkgs, path='/target'):
    """Clean up unrequired pkgs from installed system"""
    with chroot.mount(path, mnt_profile=chroot.MNT_FULL) as mnt:
        run = mnt.run(['apt-get', 'purge', '--autoremove', '-y', *pkgs])


def main():
    if not target_mounted('/target'):
        sys.exit(10)  # return to menu
    db = DiliveDebconf(title='Remove live packages')
    db.progress_init(2, description='Removing live packages from install')
    db.progress_step(1)
    clean_target_pkgs(*pkgs_to_clean, path='/target')
    db.progress_step(2)


if __name__ == "__main__":
    main()
