diff --git a/blend b/blend index 32de591..98335d7 100755 --- a/blend +++ b/blend @@ -19,7 +19,7 @@ import os import sys -from sys import stdout +import glob import time import shutil import socket @@ -27,7 +27,6 @@ import getpass import pexpect import argparse import subprocess -import yaml __version = '2.0.0' @@ -84,63 +83,22 @@ def error(err): print(colors.bold + colors.fg.red + '>> e: ' + colors.reset + colors.bold + err + colors.reset) - -def podman_it_remover(cmd: list): - ''' - Removes `-it` from a podman command if stdout is not a tty - ''' - return [x for x in cmd if x != '-it' or stdout.isatty()] - # END -# TODO: fix temp paths before committing - -def image_data_from_dict(dictionary): - ''' - Returns a distro map and aliases from a dict in this format: - - ``` - {'arch-linux': {'image': 'quay.io/toolbx/arch-toolbox:latest', 'aliases': ['arch']}} - ``` - - which is loaded in from yaml config files in this format: - - ```yaml - arch-linux: - image: "quay.io/toolbx/arch-toolbox:latest" - aliases: - - arch - ``` - ''' - distro_map = {} - aliases = {} - - for distro in dictionary.keys(): - distro_map[distro] = dictionary[distro]['image'] - try: - aliases[distro] = dictionary[distro]['aliases'] - except KeyError: - pass - - return (distro_map, aliases) - - -distro_map, aliases = image_data_from_dict( - yaml.safe_load(open('/usr/share/blend/images.yaml'))) -tmp = image_data_from_dict(yaml.safe_load(open('/system.yaml'))['images']) -distro_map += tmp[0] -aliases += tmp[1] -if os.path.exists(f'{os.getenv('XDG_CONFIG_HOME')}/blend/images.yaml'): - tmp = image_data_from_dict(yaml.safe_load( - open(f'{os.getenv('XDG_CONFIG_HOME')}/blend/images.yaml'))) - distro_map += tmp[0] - aliases += tmp[1] +distro_map = { + 'arch-linux': 'quay.io/toolbx/arch-toolbox:latest', + 'debian': 'quay.io/toolbx-images/debian-toolbox:testing', + 'fedora-42': 'quay.io/fedora/fedora-toolbox:42', + 'centos': 'quay.io/toolbx-images/centos-toolbox:latest', + 'ubuntu-22.04': 'quay.io/toolbx/ubuntu-toolbox:22.04', + 'ubuntu-24.04': 'quay.io/toolbx/ubuntu-toolbox:24.04', +} default_distro = 'arch-linux' -def get_image(): +def get_distro(): try: return distro_map[args.distro] except: @@ -256,7 +214,7 @@ def core_create_container(): '--userns', 'keep-id', '--annotation', 'run.oci.keep_original_groups=1']) - podman_command.extend([get_image()]) + podman_command.extend([get_distro()]) # User (for init-blend) podman_command.extend(['--uid', str(os.geteuid())]) @@ -280,19 +238,20 @@ def host_get_output(cmd): return subprocess.run(['bash', '-c', cmd], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL).stdout.decode('UTF-8').strip() -def core_get_retcode(cmd): - podman_command = podman_it_remover(['podman', 'exec', '--user', getpass.getuser(), '-it', - args.container_name, 'bash', '-c', cmd]) - return subprocess.run(podman_command, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode +def core_get_retcode(cmd): return subprocess.run(['podman', 'exec', '--user', getpass.getuser(), '-it', args.container_name, 'bash', '-c', cmd], + stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode def core_run_container(cmd): if os.getcwd() == os.path.expanduser('~') or os.getcwd().startswith(os.path.expanduser('~') + '/'): - subprocess.call(podman_it_remover(['podman', 'exec', '--user', getpass.getuser(), - '-w', os.getcwd(), '-it', args.container_name, 'bash', '-c', cmd])) + subprocess.call(['podman', 'exec', '--user', getpass.getuser(), + '-w', os.getcwd(), '-it', args.container_name, 'bash', '-c', cmd]) def core_install_pkg(pkg): + if args.distro == 'arch': + args.distro = 'arch-linux' + if args.distro.startswith('fedora-'): if args.noconfirm == True: core_run_container(f'sudo dnf -y install {pkg}') @@ -319,6 +278,9 @@ def core_install_pkg(pkg): def core_remove_pkg(pkg): + if args.distro == 'arch': + args.distro = 'arch-linux' + if args.distro.startswith('fedora-'): if args.noconfirm == True: core_run_container(f'sudo dnf -y remove {pkg}') @@ -338,6 +300,9 @@ def core_remove_pkg(pkg): def core_search_pkg(pkg): + if args.distro == 'arch': + args.distro = 'arch-linux' + if args.distro.startswith('fedora-'): core_run_container(f'dnf search {pkg}') elif args.distro == 'arch-linux': @@ -349,6 +314,9 @@ def core_search_pkg(pkg): def core_show_pkg(pkg): + if args.distro == 'arch': + args.distro = 'arch-linux' + if args.distro.startswith('fedora-'): core_run_container(f'dnf info {pkg}') elif args.distro == 'arch-linux': @@ -403,6 +371,9 @@ def show_blend(): def sync_blends(): + if args.distro == 'arch': + args.distro = 'arch-linux' + if args.distro.startswith('fedora-'): core_run_container(f'dnf makecache') elif args.distro == 'arch-linux': @@ -412,6 +383,9 @@ def sync_blends(): def update_blends(): + if args.distro == 'arch': + args.distro = 'arch-linux' + if args.distro.startswith('fedora-'): if args.noconfirm == True: core_run_container(f'sudo dnf -y upgrade') @@ -450,32 +424,30 @@ def enter_container(): if not os.environ.get('BLEND_COMMAND'): if args.pkg == []: if os.getcwd() == os.path.expanduser('~') or os.getcwd().startswith(os.path.expanduser('~') + '/'): - exit(subprocess.call(podman_it_remover([*sudo, 'podman', 'exec', *podman_args, - '-w', os.getcwd(), '-it', args.container_name, 'bash']))) - + exit(subprocess.call([*sudo, 'podman', 'exec', *podman_args, + '-w', os.getcwd(), '-it', args.container_name, 'bash'])) else: - exit(subprocess.call(podman_it_remover([*sudo, 'podman', 'exec', *podman_args, '-w', - '/run/host' + os.getcwd(), '-it', args.container_name, 'bash']))) + exit(subprocess.call([*sudo, 'podman', 'exec', *podman_args, '-w', + '/run/host' + os.getcwd(), '-it', args.container_name, 'bash'])) else: if os.getcwd() == os.path.expanduser('~') or os.getcwd().startswith(os.path.expanduser('~') + '/'): - exit(subprocess.call(podman_it_remover([*sudo, 'podman', 'exec', *podman_args, - '-w', os.getcwd(), '-it', args.container_name, *args.pkg]))) + exit(subprocess.call([*sudo, 'podman', 'exec', *podman_args, + '-w', os.getcwd(), '-it', args.container_name, *args.pkg])) else: - exit(subprocess.call(podman_it_remover([*sudo, 'podman', 'exec', *podman_args, '-w', - '/run/host' + os.getcwd(), '-it', args.container_name, *args.pkg]))) - + exit(subprocess.call([*sudo, 'podman', 'exec', *podman_args, '-w', + '/run/host' + os.getcwd(), '-it', args.container_name, *args.pkg])) else: if os.getcwd() == os.path.expanduser('~') or os.getcwd().startswith(os.path.expanduser('~') + '/'): - exit(subprocess.call(podman_it_remover([*sudo, 'podman', 'exec', *podman_args, '-w', os.getcwd(), '-it', - args.container_name, 'bash', '-c', os.environ.get('BLEND_COMMAND')]))) - + exit(subprocess.call([*sudo, 'podman', 'exec', *podman_args, '-w', os.getcwd( + ), '-it', args.container_name, 'bash', '-c', os.environ.get('BLEND_COMMAND')])) else: - exit(subprocess.call(podman_it_remover([*sudo, 'podman', 'exec', *podman_args, '-w', - '/run/host' + os.getcwd(), '-it', args.container_name, 'bash']))) + exit(subprocess.call([*sudo, 'podman', 'exec', *podman_args, '-w', + '/run/host' + os.getcwd(), '-it', args.container_name, 'bash'])) def create_container(): for container in args.pkg: + container = 'ubuntu-24.04' if container == 'ubuntu-24.04-lts' else container args.container_name = container if container in distro_map.keys() and distro_input == None: args.distro = container @@ -559,10 +531,6 @@ if len(sys.argv) == 1: exit() args = parser.parse_intermixed_args() -if args.distro not in distro_map.keys(): - for (distro, al) in aliases: - if args.distro in al: - args.distro = distro command = command_map[args.command] diff --git a/images.yaml b/images.yaml deleted file mode 100644 index 8753f84..0000000 --- a/images.yaml +++ /dev/null @@ -1,18 +0,0 @@ -arch-linux: - image: quay.io/toolbx/arch-toolbox:latest - aliases: - - arch -debian: - image: quay.io/toolbx-images/debian-toolbox:testing -fedora-42: - image: quay.io/fedora/fedora-toolbox:42 - aliases: - - fedora -centos: - image: quay.io/toolbx-images/centos-toolbox:latest -ubuntu-22.04: - image: quay.io/toolbx/ubuntu-toolbox:22.04 -ubuntu-24.04: - image: quay.io/toolbx/ubuntu-toolbox:24.04 - aliases: - - ubuntu