diff options
| author | Nicholas Rodrigues Lordello <[email protected]> | 2026-03-22 12:19:53 +0100 |
|---|---|---|
| committer | Nicholas Rodrigues Lordello <[email protected]> | 2026-03-22 12:19:53 +0100 |
| commit | 6ee7d7dff885f28589737e93143c5fc29fc965d1 (patch) | |
| tree | e4319c34669a84b218579ba1f5d7a69319ddc878 | |
| parent | 9c52e2228d5d408645b49a264e16dc5943b12c8f (diff) | |
Enter and Run in a Devbox
You can now enter and run commands in a devbox.
| -rwxr-xr-x | dbx-create | 24 | ||||
| -rwxr-xr-x | dbx-enter | 8 | ||||
| -rwxr-xr-x | dbx-init | 16 | ||||
| -rwxr-xr-x | dbx-run | 32 |
4 files changed, 64 insertions, 16 deletions
@@ -4,15 +4,21 @@ set -euo pipefail r="$HOME/.dbx" +c="dbx" d="$HOME/Developer/dbxroot" +if podman container exists dbx; then + echo "already created" + exit +fi + podman create \ - --hostname dbx \ - --label manager=dbx \ - --name dbx \ - --user root:root \ - --userns keep-id \ - --volume "$d:$d:z" \ - --volume "$r/dbx-init:/usr/local/bin/dbx-init:ro,z" \ - registry.fedoraproject.org/fedora-toolbox:43 \ - dbx-init + --hostname dbx \ + --label manager=dbx \ + --name "$c" \ + --user root:root \ + --userns keep-id \ + --volume "$d:$d:z" \ + --volume "$r/dbx-init:/usr/local/bin/dbx-init:ro,z" \ + registry.fedoraproject.org/fedora-toolbox:43 \ + dbx-init "$(id -u)" "$(id -g)" diff --git a/dbx-enter b/dbx-enter new file mode 100755 index 0000000..f4661d9 --- /dev/null +++ b/dbx-enter @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: 0BSD + +set -euo pipefail + +r="$HOME/.dbx" + +"$r/dbx-run" fish --login @@ -4,10 +4,12 @@ set -euo pipefail if [[ ! -f /run/.containerenv ]]; then - echo "ERROR: not in a container." >&2 + echo "ERROR: not in a container" >&2 fi -h=/dbx +h="/dbx" +u="${1:-1000}" +g="${2:-1000}" dnf install -y \ fish \ @@ -16,16 +18,16 @@ dnf install -y \ ripgrep \ vim-enhanced -if [[ ! -d $h ]]; then +if [[ ! -d "$h" ]]; then usermod \ - --home $h \ + --home "$h" \ --groups wheel \ --password "" \ --shell $(command -v fish) \ - $(id -nu 1000) + $(id -nu "$u") - mkdir --parents $h - chown --recursive 1000:1000 $h + mkdir --parents "$h" + chown --recursive "$u:$g" "$h" fi touch /run/.dbxenv @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: 0BSD + +set -euo pipefail + +if [[ $# -lt 1 ]]; then + echo "ERROR: missing command to run" >&2 + exit 1 +fi + +c="dbx" +d="$HOME/Developer/dbxroot" + +w="$(realpath "$PWD")" +if [[ "$w" != "$d"* ]]; then + w="$d" +fi + +tty="tty" +if [[ ! -t 0 ]]; then + tty="tty=false" +fi + +podman start "$c" >/dev/null +exec podman exec \ + --detach-keys "" \ + --interactive \ + --"$tty" \ + --user "$(id -u):$(id -g)" \ + --workdir "$w" \ + dbx \ + "$@" |
