diff --git a/blend b/blend
index 32de591..570a068 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,21 @@ 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': 'docker.io/library/archlinux',
+ 'debian': 'quay.io/toolbx-images/debian-toolbox:testing',
+ 'fedora-39': 'registry.fedoraproject.org/fedora-toolbox:39',
+ 'centos': 'quay.io/toolbx-images/centos-toolbox:latest',
+ 'ubuntu-22.04': 'quay.io/toolbx/ubuntu-toolbox:22.04',
+}
default_distro = 'arch-linux'
-def get_image():
+def get_distro():
try:
return distro_map[args.distro]
except:
@@ -171,7 +128,7 @@ def check_container(name):
def check_container_status(name):
- if not os.environ.get('SUDO_USER'):
+ if os.environ.get('SUDO_USER') == None:
return host_get_output("podman inspect --type container " + name + " --format \"{{.State.Status}}\"")
else:
return host_get_output(f"sudo -u {os.environ.get('SUDO_USER')} podman inspect --type container " + name + " --format \"{{.State.Status}}\"")
@@ -179,13 +136,12 @@ def check_container_status(name):
def core_start_container(name, new_container=False):
sudo = []
- if os.environ.get('SUDO_USER'):
+ if os.environ.get('SUDO_USER') != None:
sudo = ['sudo', '-u', os.environ.get('SUDO_USER')]
subprocess.call([*sudo, 'podman', 'start', name],
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
start_time = time.time() - 1000 # workaround
- time.sleep(1)
if check_container_status(name) != 'running':
print('')
error('the entry point failed to run; try again later')
@@ -193,7 +149,7 @@ def core_start_container(name, new_container=False):
subprocess.call(['podman', 'logs', '--since', str(start_time), name])
exit(1)
- if not os.environ.get('SUDO_USER'):
+ if os.environ.get('SUDO_USER') == None:
logproc = pexpect.spawn(
'podman', args=['logs', '-f', '--since', str(start_time), name], timeout=3600)
else:
@@ -211,8 +167,8 @@ def core_create_container():
info(f'creating container {name}, using {distro}')
if check_container(name):
- error(f'container {name} already exists')
- exit(1)
+ error(f'container {name} already exists')
+ exit(1)
podman_command = []
@@ -256,7 +212,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,25 +236,23 @@ 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.startswith('fedora-'):
+ if args.distro == 'fedora-rawhide':
if args.noconfirm == True:
core_run_container(f'sudo dnf -y install {pkg}')
else:
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:
core_run_container('sudo pacman -Sy')
core_run_container(
@@ -319,12 +273,12 @@ def core_install_pkg(pkg):
def core_remove_pkg(pkg):
- if args.distro.startswith('fedora-'):
+ if args.distro == 'fedora-rawhide':
if args.noconfirm == True:
core_run_container(f'sudo dnf -y remove {pkg}')
else:
core_run_container(f'sudo dnf remove {pkg}')
- elif args.distro == 'arch-linux':
+ elif args.distro == 'arch':
if args.noconfirm == True:
core_run_container(f'sudo pacman --noconfirm -Rcns {pkg}')
else:
@@ -338,9 +292,9 @@ def core_remove_pkg(pkg):
def core_search_pkg(pkg):
- if args.distro.startswith('fedora-'):
+ if args.distro == 'fedora-rawhide':
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 {pkg}')
elif args.distro.startswith('ubuntu-'):
@@ -349,9 +303,9 @@ def core_search_pkg(pkg):
def core_show_pkg(pkg):
- if args.distro.startswith('fedora-'):
+ if args.distro == 'fedora-rawhide':
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 -Si {pkg}')
elif args.distro.startswith('ubuntu-'):
@@ -403,21 +357,21 @@ def show_blend():
def sync_blends():
- if args.distro.startswith('fedora-'):
+ if args.distro == 'fedora-rawhide':
core_run_container(f'dnf makecache')
- elif args.distro == 'arch-linux':
+ elif args.distro == 'arch':
core_run_container(f'yay -Syy')
elif args.distro.startswith('ubuntu-'):
core_run_container(f'sudo apt-get update')
def update_blends():
- if args.distro.startswith('fedora-'):
+ if args.distro == 'fedora-rawhide':
if args.noconfirm == True:
core_run_container(f'sudo dnf -y upgrade')
else:
core_run_container(f'sudo dnf upgrade')
- elif args.distro == 'arch-linux':
+ elif args.distro == 'arch':
if args.noconfirm == True:
core_run_container(f'yay --noconfirm')
else:
@@ -438,7 +392,7 @@ def enter_container():
podman_args = ['--env', 'LC_ALL=C.UTF-8']
sudo = []
- if not os.environ.get('SUDO_USER'):
+ if os.environ.get('SUDO_USER') == None:
podman_args = ['--user', getpass.getuser()]
else:
sudo = ['sudo', '-u', os.environ.get(
@@ -447,31 +401,28 @@ def enter_container():
if name not in ['LANG', 'LC_CTYPE', 'LC_ALL', 'PATH', 'HOST', 'HOSTNAME', 'SHELL'] and not name.startswith('_'):
podman_args.append('--env')
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 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():
@@ -491,12 +442,10 @@ def remove_container():
stdout=subprocess.DEVNULL)
for bin in os.listdir(os.path.expanduser('~/.local/bin/blend_bin')):
if bin.endswith(f'.{container}'):
- os.remove(os.path.join(os.path.expanduser(
- '~/.local/bin/blend_bin'), bin))
+ os.remove(os.path.join(os.path.expanduser('~/.local/bin/blend_bin'), bin))
for app in os.listdir(os.path.expanduser('~/.local/share/applications')):
if app.startswith(f'blend;{container};'):
- os.remove(os.path.join(os.path.expanduser(
- '~/.local/share/applications'), app))
+ os.remove(os.path.join(os.path.expanduser('~/.local/share/applications'), app))
def start_containers():
@@ -559,10 +508,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/blend-settings/main.js b/blend-settings/main.js
index aeda78f..e4eac38 100644
--- a/blend-settings/main.js
+++ b/blend-settings/main.js
@@ -160,15 +160,10 @@ function loadTerminalWindow(title, cmd) {
if (!terminalWindow.isDestroyed()) {
terminalWindow.webContents.send("terminal.reset")
terminalWindow.hide()
- try {
- if (title.startsWith('Creating container: ')) {
- mainWindow.webContents.send("container-created")
- } else if (title.startsWith('Package installation')) {
- packageWindow.webContents.send("installation-complete")
- }
- } catch (err) {
- console.log(err)
- app.quit()
+ if (title.startsWith('Creating container: ')) {
+ mainWindow.webContents.send("container-created")
+ } else if (title.startsWith('Package installation')) {
+ packageWindow.webContents.send("installation-complete")
}
}
})
@@ -183,8 +178,10 @@ function loadTerminalWindow(title, cmd) {
app.whenReady().then(() => {
app.allowRendererProcessReuse = false
- if (process.argv.includes('package')) {
- createPackageWindow()
+ if (process.argv.length > 2) {
+ if (process.argv[2] == 'package') {
+ createPackageWindow()
+ }
} else {
createWindow()
}
@@ -199,4 +196,4 @@ app.whenReady().then(() => {
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit()
-})
+})
\ No newline at end of file
diff --git a/blend-settings/src/index.html b/blend-settings/src/index.html
index 1ef4cc7..d66f49c 100644
--- a/blend-settings/src/index.html
+++ b/blend-settings/src/index.html
@@ -18,7 +18,7 @@
Containers
-
+
@@ -43,14 +43,6 @@
if (fs.existsSync('/usr/bin/waydroid')) {
document.getElementById('android-button').classList.remove('d-none')
- } else {
- document.getElementById('android-button').remove()
- }
-
- if (fs.existsSync('/usr/bin/akshara')) {
- document.getElementById('system-button').classList.remove('d-none')
- } else {
- document.getElementById('system-button').remove()
}
function page(page) {
diff --git a/blend-settings/src/package-installer.html b/blend-settings/src/package-installer.html
index a2cb791..a20640b 100644
--- a/blend-settings/src/package-installer.html
+++ b/blend-settings/src/package-installer.html
@@ -88,7 +88,7 @@