Compare commits
No commits in common. "eacb3aa470ff06dee230c2261dbb4167af6bb98c" and "4dc80a30d7e0cff86fbfa1c46072856dd3f67c08" have entirely different histories.
eacb3aa470
...
4dc80a30d7
3 changed files with 31 additions and 28 deletions
38
blend
38
blend
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import glob
|
||||||
import time
|
import time
|
||||||
import shutil
|
import shutil
|
||||||
import socket
|
import socket
|
||||||
|
@ -91,7 +92,6 @@ distro_map = {
|
||||||
'fedora-39': 'registry.fedoraproject.org/fedora-toolbox:39',
|
'fedora-39': 'registry.fedoraproject.org/fedora-toolbox:39',
|
||||||
'centos': 'quay.io/toolbx-images/centos-toolbox:latest',
|
'centos': 'quay.io/toolbx-images/centos-toolbox:latest',
|
||||||
'ubuntu-22.04': 'quay.io/toolbx/ubuntu-toolbox:22.04',
|
'ubuntu-22.04': 'quay.io/toolbx/ubuntu-toolbox:22.04',
|
||||||
'ubuntu-24.04-lts': 'quay.io/toolbx/ubuntu-toolbox:24.04',
|
|
||||||
}
|
}
|
||||||
|
|
||||||
default_distro = 'arch-linux'
|
default_distro = 'arch-linux'
|
||||||
|
@ -102,7 +102,7 @@ def get_distro():
|
||||||
return distro_map[args.distro]
|
return distro_map[args.distro]
|
||||||
except:
|
except:
|
||||||
error(f"{args.distro} isn't supported by blend.")
|
error(f"{args.distro} isn't supported by blend.")
|
||||||
exit(1)
|
exit()
|
||||||
|
|
||||||
|
|
||||||
def list_containers():
|
def list_containers():
|
||||||
|
@ -128,7 +128,7 @@ def check_container(name):
|
||||||
|
|
||||||
|
|
||||||
def check_container_status(name):
|
def check_container_status(name):
|
||||||
if os.environ.get('SUDO_USER'):
|
if os.environ.get('SUDO_USER') == None:
|
||||||
return host_get_output("podman inspect --type container " + name + " --format \"{{.State.Status}}\"")
|
return host_get_output("podman inspect --type container " + name + " --format \"{{.State.Status}}\"")
|
||||||
else:
|
else:
|
||||||
return host_get_output(f"sudo -u {os.environ.get('SUDO_USER')} podman inspect --type container " + name + " --format \"{{.State.Status}}\"")
|
return host_get_output(f"sudo -u {os.environ.get('SUDO_USER')} podman inspect --type container " + name + " --format \"{{.State.Status}}\"")
|
||||||
|
@ -136,7 +136,7 @@ def check_container_status(name):
|
||||||
|
|
||||||
def core_start_container(name, new_container=False):
|
def core_start_container(name, new_container=False):
|
||||||
sudo = []
|
sudo = []
|
||||||
if os.environ.get('SUDO_USER'):
|
if os.environ.get('SUDO_USER') != None:
|
||||||
sudo = ['sudo', '-u', os.environ.get('SUDO_USER')]
|
sudo = ['sudo', '-u', os.environ.get('SUDO_USER')]
|
||||||
subprocess.call([*sudo, 'podman', 'start', name],
|
subprocess.call([*sudo, 'podman', 'start', name],
|
||||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||||
|
@ -149,7 +149,7 @@ def core_start_container(name, new_container=False):
|
||||||
subprocess.call(['podman', 'logs', '--since', str(start_time), name])
|
subprocess.call(['podman', 'logs', '--since', str(start_time), name])
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
if not os.environ.get('SUDO_USER'):
|
if os.environ.get('SUDO_USER') == None:
|
||||||
logproc = pexpect.spawn(
|
logproc = pexpect.spawn(
|
||||||
'podman', args=['logs', '-f', '--since', str(start_time), name], timeout=3600)
|
'podman', args=['logs', '-f', '--since', str(start_time), name], timeout=3600)
|
||||||
else:
|
else:
|
||||||
|
@ -247,12 +247,12 @@ def core_run_container(cmd):
|
||||||
|
|
||||||
|
|
||||||
def core_install_pkg(pkg):
|
def core_install_pkg(pkg):
|
||||||
if args.distro.startswith('fedora-'):
|
if args.distro == 'fedora-rawhide':
|
||||||
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}')
|
||||||
else:
|
else:
|
||||||
core_run_container(f'sudo dnf install {pkg}')
|
core_run_container(f'sudo dnf install {pkg}')
|
||||||
elif args.distro == 'arch-linux':
|
elif args.distro == 'arch':
|
||||||
if core_get_retcode('[ -f /usr/bin/yay ]') != 0:
|
if core_get_retcode('[ -f /usr/bin/yay ]') != 0:
|
||||||
core_run_container('sudo pacman -Sy')
|
core_run_container('sudo pacman -Sy')
|
||||||
core_run_container(
|
core_run_container(
|
||||||
|
@ -273,12 +273,12 @@ def core_install_pkg(pkg):
|
||||||
|
|
||||||
|
|
||||||
def core_remove_pkg(pkg):
|
def core_remove_pkg(pkg):
|
||||||
if args.distro.startswith('fedora-'):
|
if args.distro == 'fedora-rawhide':
|
||||||
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}')
|
||||||
else:
|
else:
|
||||||
core_run_container(f'sudo dnf remove {pkg}')
|
core_run_container(f'sudo dnf remove {pkg}')
|
||||||
elif args.distro == 'arch-linux':
|
elif args.distro == 'arch':
|
||||||
if args.noconfirm == True:
|
if args.noconfirm == True:
|
||||||
core_run_container(f'sudo pacman --noconfirm -Rcns {pkg}')
|
core_run_container(f'sudo pacman --noconfirm -Rcns {pkg}')
|
||||||
else:
|
else:
|
||||||
|
@ -292,9 +292,9 @@ def core_remove_pkg(pkg):
|
||||||
|
|
||||||
|
|
||||||
def core_search_pkg(pkg):
|
def core_search_pkg(pkg):
|
||||||
if args.distro.startswith('fedora-'):
|
if args.distro == 'fedora-rawhide':
|
||||||
core_run_container(f'dnf search {pkg}')
|
core_run_container(f'dnf search {pkg}')
|
||||||
elif args.distro == 'arch-linux':
|
elif args.distro == 'arch':
|
||||||
core_run_container(f'yay -Sy')
|
core_run_container(f'yay -Sy')
|
||||||
core_run_container(f'yay {pkg}')
|
core_run_container(f'yay {pkg}')
|
||||||
elif args.distro.startswith('ubuntu-'):
|
elif args.distro.startswith('ubuntu-'):
|
||||||
|
@ -303,9 +303,9 @@ def core_search_pkg(pkg):
|
||||||
|
|
||||||
|
|
||||||
def core_show_pkg(pkg):
|
def core_show_pkg(pkg):
|
||||||
if args.distro.startswith('fedora-'):
|
if args.distro == 'fedora-rawhide':
|
||||||
core_run_container(f'dnf info {pkg}')
|
core_run_container(f'dnf info {pkg}')
|
||||||
elif args.distro == 'arch-linux':
|
elif args.distro == 'arch':
|
||||||
core_run_container(f'yay -Sy')
|
core_run_container(f'yay -Sy')
|
||||||
core_run_container(f'yay -Si {pkg}')
|
core_run_container(f'yay -Si {pkg}')
|
||||||
elif args.distro.startswith('ubuntu-'):
|
elif args.distro.startswith('ubuntu-'):
|
||||||
|
@ -357,21 +357,21 @@ def show_blend():
|
||||||
|
|
||||||
|
|
||||||
def sync_blends():
|
def sync_blends():
|
||||||
if args.distro.startswith('fedora-'):
|
if args.distro == 'fedora-rawhide':
|
||||||
core_run_container(f'dnf makecache')
|
core_run_container(f'dnf makecache')
|
||||||
elif args.distro == 'arch-linux':
|
elif args.distro == 'arch':
|
||||||
core_run_container(f'yay -Syy')
|
core_run_container(f'yay -Syy')
|
||||||
elif args.distro.startswith('ubuntu-'):
|
elif args.distro.startswith('ubuntu-'):
|
||||||
core_run_container(f'sudo apt-get update')
|
core_run_container(f'sudo apt-get update')
|
||||||
|
|
||||||
|
|
||||||
def update_blends():
|
def update_blends():
|
||||||
if args.distro.startswith('fedora-'):
|
if args.distro == 'fedora-rawhide':
|
||||||
if args.noconfirm == True:
|
if args.noconfirm == True:
|
||||||
core_run_container(f'sudo dnf -y upgrade')
|
core_run_container(f'sudo dnf -y upgrade')
|
||||||
else:
|
else:
|
||||||
core_run_container(f'sudo dnf upgrade')
|
core_run_container(f'sudo dnf upgrade')
|
||||||
elif args.distro == 'arch-linux':
|
elif args.distro == 'arch':
|
||||||
if args.noconfirm == True:
|
if args.noconfirm == True:
|
||||||
core_run_container(f'yay --noconfirm')
|
core_run_container(f'yay --noconfirm')
|
||||||
else:
|
else:
|
||||||
|
@ -392,7 +392,7 @@ def enter_container():
|
||||||
|
|
||||||
podman_args = ['--env', 'LC_ALL=C.UTF-8']
|
podman_args = ['--env', 'LC_ALL=C.UTF-8']
|
||||||
sudo = []
|
sudo = []
|
||||||
if not os.environ.get('SUDO_USER'):
|
if os.environ.get('SUDO_USER') == None:
|
||||||
podman_args = ['--user', getpass.getuser()]
|
podman_args = ['--user', getpass.getuser()]
|
||||||
else:
|
else:
|
||||||
sudo = ['sudo', '-u', os.environ.get(
|
sudo = ['sudo', '-u', os.environ.get(
|
||||||
|
@ -401,7 +401,7 @@ def enter_container():
|
||||||
if name not in ['LANG', 'LC_CTYPE', 'LC_ALL', 'PATH', 'HOST', 'HOSTNAME', 'SHELL'] and not name.startswith('_'):
|
if name not in ['LANG', 'LC_CTYPE', 'LC_ALL', 'PATH', 'HOST', 'HOSTNAME', 'SHELL'] and not name.startswith('_'):
|
||||||
podman_args.append('--env')
|
podman_args.append('--env')
|
||||||
podman_args.append(name + '=' + val)
|
podman_args.append(name + '=' + val)
|
||||||
if not os.environ.get('BLEND_COMMAND'):
|
if os.environ.get('BLEND_COMMAND') == None or 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([*sudo, 'podman', 'exec', *podman_args,
|
exit(subprocess.call([*sudo, 'podman', 'exec', *podman_args,
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
<option>CentOS</option>
|
<option>CentOS</option>
|
||||||
<option>Fedora 39</option>
|
<option>Fedora 39</option>
|
||||||
<option>Ubuntu 22.04</option>
|
<option>Ubuntu 22.04</option>
|
||||||
<option>Ubuntu 24.04 LTS</option>
|
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-1">
|
<div class="col-sm-1">
|
||||||
|
|
18
user
18
user
|
@ -1,9 +1,13 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import yaml
|
||||||
import click
|
import click
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
from urllib.request import urlopen
|
||||||
|
|
||||||
|
|
||||||
class colors:
|
class colors:
|
||||||
reset = '\033[0m'
|
reset = '\033[0m'
|
||||||
bold = '\033[01m'
|
bold = '\033[01m'
|
||||||
|
@ -134,7 +138,7 @@ def associate_binary(association, container):
|
||||||
|
|
||||||
@cli.command("dissociate")
|
@cli.command("dissociate")
|
||||||
@click.argument('association')
|
@click.argument('association')
|
||||||
def dissociate_binary(association):
|
def associate_binary(association):
|
||||||
'''
|
'''
|
||||||
Remove an association
|
Remove an association
|
||||||
'''
|
'''
|
||||||
|
@ -152,19 +156,19 @@ def dissociate_binary(association):
|
||||||
|
|
||||||
@cli.command("create-container")
|
@cli.command("create-container")
|
||||||
@click.argument('container_name')
|
@click.argument('container_name')
|
||||||
@click.argument('distro', required=False)
|
@click.argument('distro', default='arch')
|
||||||
def create_container(container_name, distro):
|
def create_container(container_name, distro):
|
||||||
'''
|
'''
|
||||||
Create a container
|
Create a container
|
||||||
'''
|
'''
|
||||||
|
if distro not in ('arch', 'almalinux-9', 'crystal-linux', 'debian', 'fedora-38', 'kali-linux', 'neurodebian-bookworm', 'rocky-linux', 'ubuntu-22.04', 'ubuntu-23.04'):
|
||||||
|
error(
|
||||||
|
f'distro {colors.bold}{distro}{colors.reset} not supported')
|
||||||
if subprocess.run(['podman', 'container', 'exists', container_name], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode == 0:
|
if subprocess.run(['podman', 'container', 'exists', container_name], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode == 0:
|
||||||
error(f'container {colors.bold}{container_name}{colors.reset} already exists')
|
error(f'container {colors.bold}{container_name}{colors.reset} already exists')
|
||||||
exit(1)
|
exit(1)
|
||||||
args = ['blend', 'create-container', '-cn', container_name]
|
subprocess.run(['blend', 'create-container', '-cn', container_name, '-d', distro])
|
||||||
# blend handles no distro being specified already
|
|
||||||
if distro:
|
|
||||||
args.extend(['-d', distro])
|
|
||||||
exit(subprocess.run(args).returncode)
|
|
||||||
|
|
||||||
@cli.command("delete-container")
|
@cli.command("delete-container")
|
||||||
@click.argument('container')
|
@click.argument('container')
|
||||||
|
|
Loading…
Reference in a new issue