Compare commits
No commits in common. "f5bd881b5d547cb1d2e53be079ae24405014a04e" and "6bee27bb0d7df03cee93fee2da5d00e4e6ea59b8" have entirely different histories.
f5bd881b5d
...
6bee27bb0d
2 changed files with 46 additions and 96 deletions
124
blend
124
blend
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from sys import stdout
|
import glob
|
||||||
import time
|
import time
|
||||||
import shutil
|
import shutil
|
||||||
import socket
|
import socket
|
||||||
|
@ -27,7 +27,6 @@ import getpass
|
||||||
import pexpect
|
import pexpect
|
||||||
import argparse
|
import argparse
|
||||||
import subprocess
|
import subprocess
|
||||||
import yaml
|
|
||||||
|
|
||||||
__version = '2.0.0'
|
__version = '2.0.0'
|
||||||
|
|
||||||
|
@ -84,63 +83,22 @@ def error(err):
|
||||||
print(colors.bold + colors.fg.red + '>> e: ' +
|
print(colors.bold + colors.fg.red + '>> e: ' +
|
||||||
colors.reset + colors.bold + err + colors.reset)
|
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
|
# END
|
||||||
|
|
||||||
# TODO: fix temp paths before committing
|
|
||||||
|
|
||||||
|
distro_map = {
|
||||||
def image_data_from_dict(dictionary):
|
'arch-linux': 'quay.io/toolbx/arch-toolbox:latest',
|
||||||
'''
|
'debian': 'quay.io/toolbx-images/debian-toolbox:testing',
|
||||||
Returns a distro map and aliases from a dict in this format:
|
'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',
|
||||||
{'arch-linux': {'image': 'quay.io/toolbx/arch-toolbox:latest', 'aliases': ['arch']}}
|
'ubuntu-24.04': 'quay.io/toolbx/ubuntu-toolbox:24.04',
|
||||||
```
|
}
|
||||||
|
|
||||||
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]
|
|
||||||
|
|
||||||
default_distro = 'arch-linux'
|
default_distro = 'arch-linux'
|
||||||
|
|
||||||
|
|
||||||
def get_image():
|
def get_distro():
|
||||||
try:
|
try:
|
||||||
return distro_map[args.distro]
|
return distro_map[args.distro]
|
||||||
except:
|
except:
|
||||||
|
@ -256,7 +214,7 @@ def core_create_container():
|
||||||
'--userns', 'keep-id',
|
'--userns', 'keep-id',
|
||||||
'--annotation', 'run.oci.keep_original_groups=1'])
|
'--annotation', 'run.oci.keep_original_groups=1'])
|
||||||
|
|
||||||
podman_command.extend([get_image()])
|
podman_command.extend([get_distro()])
|
||||||
|
|
||||||
# User (for init-blend)
|
# User (for init-blend)
|
||||||
podman_command.extend(['--uid', str(os.geteuid())])
|
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()
|
stdout=subprocess.PIPE, stderr=subprocess.DEVNULL).stdout.decode('UTF-8').strip()
|
||||||
|
|
||||||
|
|
||||||
def core_get_retcode(cmd):
|
def core_get_retcode(cmd): return subprocess.run(['podman', 'exec', '--user', getpass.getuser(), '-it', args.container_name, 'bash', '-c', cmd],
|
||||||
podman_command = podman_it_remover(['podman', 'exec', '--user', getpass.getuser(), '-it',
|
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode
|
||||||
args.container_name, 'bash', '-c', cmd])
|
|
||||||
return subprocess.run(podman_command, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode
|
|
||||||
|
|
||||||
|
|
||||||
def core_run_container(cmd):
|
def core_run_container(cmd):
|
||||||
if os.getcwd() == os.path.expanduser('~') or os.getcwd().startswith(os.path.expanduser('~') + '/'):
|
if os.getcwd() == os.path.expanduser('~') or os.getcwd().startswith(os.path.expanduser('~') + '/'):
|
||||||
subprocess.call(podman_it_remover(['podman', 'exec', '--user', getpass.getuser(),
|
subprocess.call(['podman', 'exec', '--user', getpass.getuser(),
|
||||||
'-w', os.getcwd(), '-it', args.container_name, 'bash', '-c', cmd]))
|
'-w', os.getcwd(), '-it', args.container_name, 'bash', '-c', cmd])
|
||||||
|
|
||||||
|
|
||||||
def core_install_pkg(pkg):
|
def core_install_pkg(pkg):
|
||||||
|
if args.distro == 'arch':
|
||||||
|
args.distro = 'arch-linux'
|
||||||
|
|
||||||
if args.distro.startswith('fedora-'):
|
if args.distro.startswith('fedora-'):
|
||||||
if args.noconfirm == True:
|
if args.noconfirm == True:
|
||||||
core_run_container(f'sudo dnf -y install {pkg}')
|
core_run_container(f'sudo dnf -y install {pkg}')
|
||||||
|
@ -319,6 +278,9 @@ def core_install_pkg(pkg):
|
||||||
|
|
||||||
|
|
||||||
def core_remove_pkg(pkg):
|
def core_remove_pkg(pkg):
|
||||||
|
if args.distro == 'arch':
|
||||||
|
args.distro = 'arch-linux'
|
||||||
|
|
||||||
if args.distro.startswith('fedora-'):
|
if args.distro.startswith('fedora-'):
|
||||||
if args.noconfirm == True:
|
if args.noconfirm == True:
|
||||||
core_run_container(f'sudo dnf -y remove {pkg}')
|
core_run_container(f'sudo dnf -y remove {pkg}')
|
||||||
|
@ -338,6 +300,9 @@ def core_remove_pkg(pkg):
|
||||||
|
|
||||||
|
|
||||||
def core_search_pkg(pkg):
|
def core_search_pkg(pkg):
|
||||||
|
if args.distro == 'arch':
|
||||||
|
args.distro = 'arch-linux'
|
||||||
|
|
||||||
if args.distro.startswith('fedora-'):
|
if args.distro.startswith('fedora-'):
|
||||||
core_run_container(f'dnf search {pkg}')
|
core_run_container(f'dnf search {pkg}')
|
||||||
elif args.distro == 'arch-linux':
|
elif args.distro == 'arch-linux':
|
||||||
|
@ -349,6 +314,9 @@ def core_search_pkg(pkg):
|
||||||
|
|
||||||
|
|
||||||
def core_show_pkg(pkg):
|
def core_show_pkg(pkg):
|
||||||
|
if args.distro == 'arch':
|
||||||
|
args.distro = 'arch-linux'
|
||||||
|
|
||||||
if args.distro.startswith('fedora-'):
|
if args.distro.startswith('fedora-'):
|
||||||
core_run_container(f'dnf info {pkg}')
|
core_run_container(f'dnf info {pkg}')
|
||||||
elif args.distro == 'arch-linux':
|
elif args.distro == 'arch-linux':
|
||||||
|
@ -403,6 +371,9 @@ def show_blend():
|
||||||
|
|
||||||
|
|
||||||
def sync_blends():
|
def sync_blends():
|
||||||
|
if args.distro == 'arch':
|
||||||
|
args.distro = 'arch-linux'
|
||||||
|
|
||||||
if args.distro.startswith('fedora-'):
|
if args.distro.startswith('fedora-'):
|
||||||
core_run_container(f'dnf makecache')
|
core_run_container(f'dnf makecache')
|
||||||
elif args.distro == 'arch-linux':
|
elif args.distro == 'arch-linux':
|
||||||
|
@ -412,6 +383,9 @@ def sync_blends():
|
||||||
|
|
||||||
|
|
||||||
def update_blends():
|
def update_blends():
|
||||||
|
if args.distro == 'arch':
|
||||||
|
args.distro = 'arch-linux'
|
||||||
|
|
||||||
if args.distro.startswith('fedora-'):
|
if args.distro.startswith('fedora-'):
|
||||||
if args.noconfirm == True:
|
if args.noconfirm == True:
|
||||||
core_run_container(f'sudo dnf -y upgrade')
|
core_run_container(f'sudo dnf -y upgrade')
|
||||||
|
@ -450,32 +424,30 @@ def enter_container():
|
||||||
if not os.environ.get('BLEND_COMMAND'):
|
if not os.environ.get('BLEND_COMMAND'):
|
||||||
if args.pkg == []:
|
if args.pkg == []:
|
||||||
if os.getcwd() == os.path.expanduser('~') or os.getcwd().startswith(os.path.expanduser('~') + '/'):
|
if os.getcwd() == os.path.expanduser('~') or os.getcwd().startswith(os.path.expanduser('~') + '/'):
|
||||||
exit(subprocess.call(podman_it_remover([*sudo, 'podman', 'exec', *podman_args,
|
exit(subprocess.call([*sudo, 'podman', 'exec', *podman_args,
|
||||||
'-w', os.getcwd(), '-it', args.container_name, 'bash'])))
|
'-w', os.getcwd(), '-it', args.container_name, 'bash']))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
exit(subprocess.call(podman_it_remover([*sudo, 'podman', 'exec', *podman_args, '-w',
|
exit(subprocess.call([*sudo, 'podman', 'exec', *podman_args, '-w',
|
||||||
'/run/host' + os.getcwd(), '-it', args.container_name, 'bash'])))
|
'/run/host' + os.getcwd(), '-it', args.container_name, 'bash']))
|
||||||
else:
|
else:
|
||||||
if os.getcwd() == os.path.expanduser('~') or os.getcwd().startswith(os.path.expanduser('~') + '/'):
|
if os.getcwd() == os.path.expanduser('~') or os.getcwd().startswith(os.path.expanduser('~') + '/'):
|
||||||
exit(subprocess.call(podman_it_remover([*sudo, 'podman', 'exec', *podman_args,
|
exit(subprocess.call([*sudo, 'podman', 'exec', *podman_args,
|
||||||
'-w', os.getcwd(), '-it', args.container_name, *args.pkg])))
|
'-w', os.getcwd(), '-it', args.container_name, *args.pkg]))
|
||||||
else:
|
else:
|
||||||
exit(subprocess.call(podman_it_remover([*sudo, 'podman', 'exec', *podman_args, '-w',
|
exit(subprocess.call([*sudo, 'podman', 'exec', *podman_args, '-w',
|
||||||
'/run/host' + os.getcwd(), '-it', args.container_name, *args.pkg])))
|
'/run/host' + os.getcwd(), '-it', args.container_name, *args.pkg]))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if os.getcwd() == os.path.expanduser('~') or os.getcwd().startswith(os.path.expanduser('~') + '/'):
|
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',
|
exit(subprocess.call([*sudo, 'podman', 'exec', *podman_args, '-w', os.getcwd(
|
||||||
args.container_name, 'bash', '-c', os.environ.get('BLEND_COMMAND')])))
|
), '-it', args.container_name, 'bash', '-c', os.environ.get('BLEND_COMMAND')]))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
exit(subprocess.call(podman_it_remover([*sudo, 'podman', 'exec', *podman_args, '-w',
|
exit(subprocess.call([*sudo, 'podman', 'exec', *podman_args, '-w',
|
||||||
'/run/host' + os.getcwd(), '-it', args.container_name, 'bash'])))
|
'/run/host' + os.getcwd(), '-it', args.container_name, 'bash']))
|
||||||
|
|
||||||
|
|
||||||
def create_container():
|
def create_container():
|
||||||
for container in args.pkg:
|
for container in args.pkg:
|
||||||
|
container = 'ubuntu-24.04' if container == 'ubuntu-24.04-lts' else container
|
||||||
args.container_name = container
|
args.container_name = container
|
||||||
if container in distro_map.keys() and distro_input == None:
|
if container in distro_map.keys() and distro_input == None:
|
||||||
args.distro = container
|
args.distro = container
|
||||||
|
@ -559,10 +531,6 @@ if len(sys.argv) == 1:
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
args = parser.parse_intermixed_args()
|
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]
|
command = command_map[args.command]
|
||||||
|
|
||||||
|
|
18
images.yaml
18
images.yaml
|
@ -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
|
|
Loading…
Add table
Add a link
Reference in a new issue